miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MiniSSDPd: register / submit service
Goto page 1, 2  Next
 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation
View previous topic :: View next topic  
Author Message
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Fri Jan 01, 2021 8:37 am    Post subject: MiniSSDPd: register / submit service Reply with quote

I want to submit a service to minissdpd so that minissdpd advertises my service on my LAN.

I'm assuming I must use "request type 4 = submit service". Correct?

testminissdpd.c uses this command: 'char command4[] = "\x04\x00test:test:test";'
Is that the command I should use to submit a service? Is the ":" the separator ... ?

If so, in what format? Looking at other existing devices/messages, my first guess would be


char command4[] = "\x04\x00http://192.168.2.222:22222/IGD.xml:urn:dslforum-org:device:WANConnectionDevice:1:uuid:11111111-405a-3721-e8b8-20e882bf0aa1::urn:dslforum-org:device:WANConnectionDevice:1" ;

... but because there are multiple :'s I can't imagine this works. And indeed it does not work: it does not show up in the list reported my testminisspd


I think the answer is in the documentation, but I don't understand it:

request type 4 = submit service
1st byte  = 4
(k,n) bytes : length and string "ST" (service type)
(k,n) bytes : length and string "USN"
(k,n) bytes : length and string "Server"
(k,n) bytes : length and string "Location"

I would appreciate to know the correct format for command4[].


Last edited by superkoning on Fri Jan 01, 2021 8:38 am; edited 1 time in total
Back to top
View user's profile Send private message
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Fri Jan 01, 2021 8:38 am    Post subject: Reply with quote

FWIW I tried this format too, but doesn't work either.

char command4[] = "\x04\x00uuid:44444444-b051-11db-88f8-0060085db3f6::upnp:rootdevice" ;

FWIW 2

I tried to understand

http://miniupnp.free.fr/minissdpd.html

UPnP Device submit (request type 4)
These "request" type is used by UPnP devices that declare themselves and their services that way. The first byte is 4 and is followed by four Strings :

Service/device type
USN
Server string (as found in SSDP packets)
Location
There is no response.



and

https://github.com/miniupnp/miniupnp/tree/master/minissdpd

request type 4 = submit service
1st byte = 4
(k,n) bytes : length and string "ST" (service type)
(k,n) bytes : length and string "USN"
(k,n) bytes : length and string "Server"
(k,n) bytes : length and string "Location"
No answer


... but no luck
Back to top
View user's profile Send private message
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Sun Jan 03, 2021 7:06 am    Post subject: Reply with quote

Further tries:

char command4[] = "\x04\x05PQRST\x05PQRST\x05PQRST\x05PQRST" ;
char command4[] = "\x04\x00\x05PQRST\x05PQRST\x05PQRST\x05PQRST" ;

... but no luck.

Help appreciated.
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Wed Jan 06, 2021 7:23 pm    Post subject: Reply with quote

have a look at SubmitServicesToMiniSSDPD() function :

https://github.com/miniupnp/miniupnp/blob/master/miniupnpd/minissdp.c#L1488
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Wed Jan 06, 2021 7:31 pm    Post subject: Reply with quote


    ST is a string such as urn:schemas-upnp-org:device:InternetGatewayDevice:1
    USN uuid:73616d61-6a6b-7a74-650a-0d24d4a5d636::urn:schemas-upnp-org:device:InternetGatewayDevice:1
    SERVER My Software/0.1
    LOCATION http://192.168.0.1:12345/rootDesc.xml

_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Wed Jan 06, 2021 7:35 pm    Post subject: Reply with quote

ReadyMedia uses almost the same code : https://sourceforge.net/p/minidlna/git/ci/master/tree/minissdp.c#l829
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Wed Jan 06, 2021 10:27 pm    Post subject: Reply with quote

miniupnp wrote:
ReadyMedia uses almost the same code : https://sourceforge.net/p/minidlna/git/ci/master/tree/minissdp.c#l829


OK, thanks ... 30 lines of C code ... with some coffee I must be able to understand that.
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Thu Jan 07, 2021 9:01 am    Post subject: Reply with quote

superkoning wrote:
miniupnp wrote:
ReadyMedia uses almost the same code : https://sourceforge.net/p/minidlna/git/ci/master/tree/minissdp.c#l829


OK, thanks ... 30 lines of C code ... with some coffee I must be able to understand that.

You don't need to understand fully to just copy paste Wink

I think I will add sample.c file so people can include in their software and not worry about.
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Thu Jan 07, 2021 10:18 am    Post subject: Reply with quote

miniupnp wrote:
superkoning wrote:
miniupnp wrote:
ReadyMedia uses almost the same code : https://sourceforge.net/p/minidlna/git/ci/master/tree/minissdp.c#l829


OK, thanks ... 30 lines of C code ... with some coffee I must be able to understand that.

You don't need to understand fully to just copy paste Wink

I think I will add sample.c file so people can include in their software and not worry about.


Well, my goal is to register my service to minissdpd from ... pyhon. So I must understand the c code to write python code ... Very Happy
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Thu Jan 07, 2021 1:00 pm    Post subject: Reply with quote

ok i should try to write it in python3 Wink
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Thu Jan 07, 2021 2:08 pm    Post subject: Reply with quote

miniupnp wrote:
ok i should try to write it in python3 Wink


That would be fantastic. Indeed python3 (python2 is EoL).
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Thu Jan 07, 2021 6:44 pm    Post subject: Reply with quote

https://github.com/miniupnp/miniupnp/blob/master/minissdpd/submit_to_minissdpd.py
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Thu Jan 07, 2021 7:56 pm    Post subject: Reply with quote

miniupnp wrote:
https://github.com/miniupnp/miniupnp/blob/master/minissdpd/submit_to_minissdpd.py


Wow, that is fast!

Let's check:

Code:
$ cat submit_to_minissdpd.py  | tail -1 | tr "," "\n"

SubmitServicesToMiniSSDPD(b'urn:schemas-upnp-org:device:InternetGatewayDevice:1'
 b'uuid:73616d61-6a6b-7a74-650a-0d24d4a5d636::urn:schemas-upnp-org:device:InternetGatewayDevice:1'
 b'MyServer/0.0'
 b'http://192.168.0.1:1234/rootDesc.xml')


After

Code:
python3 submit_to_minissdpd.py



./testminissdpd reveals:

Code:
23 - http://192.168.0.1:1234/rootDesc.xml
    urn:schemas-upnp-org:device:InternetGatewayDevice:1
    uuid:73616d61-6a6b-7a74-650a-0d24d4a5d636::urn:schemas-upnp-org:device:InternetGatewayDevice:1



Looks good!

I don't see the b'MyServer/0.0 part in the output of testminisspdpd ... I guess that is by design?


Cool! Thank you.

EDIT:

One remark:


Code:
#!/usr/bin/env python


That does not work on Ubuntu 20.04: 'python' refers to python2, which is not installed on Ubuntu 20.04

For python3 scripts, it's adviced to use

Code:
#!/usr/bin/env python3


Reason: 'python' is ambigous, and often pointing to python2 (because of legacy). So therefore 'python3' in the shebang.
Back to top
View user's profile Send private message
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Thu Jan 07, 2021 8:21 pm    Post subject: Reply with quote

I'll send my suggestions via a PR
Back to top
View user's profile Send private message
superkoning



Joined: 01 Jan 2021
Posts: 14
Location: ::1

PostPosted: Fri Jan 08, 2021 12:56 pm    Post subject: Reply with quote

superkoning wrote:
I'll send my suggestions via a PR


PR sent: https://github.com/miniupnp/miniupnp/pull/520

Now usable as stand-alone program, and module.

Code:
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import submit_to_minissdpd
>>> submit_to_minissdpd.codelength(b"blalbla")
b'\x07blalbla'
>>> submit_to_minissdpd.codelength("blalbla")
b'\x07blalbla'
>>> submit_to_minissdpd.codelength("你好")
b'\x00'
>>> submit_to_minissdpd.submit_to_minissdpd("line 1", "line 2", "line 3", "line 4")
(0, 'OK')
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.