-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
168 lines (140 loc) · 7.02 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
This is a "plugin" for the Video Disk Recorder (VDR).
Written by: Lars Hanisch <dvb@flensrocker.de>
Project's homepage: https://github.com/flensrocker/vdr-plugin-avahi4vdr
Latest version available at: https://github.com/flensrocker/vdr-plugin-avahi4vdr
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
See the file COPYING for more information.
Description:
With this plugin it is possible to announce network service via avahi
to the LAN. Also plugins can browse for services on the LAN.
Call avahi4vdr's SVDRPCommand directly to publish a service or to browse
for one. You'll get an string with something like "id=<uuid>" to identify
your service or browser.
avahi4vdr will send events through the plugin's Service function if something
happens to your service or browser.
Here is some pseudo code for controlling avahi4vdr like dbus2vdr will use it.
Publish network service
-----------------------
int replyCode = 0;
cString serviceId;
cPlugin *avahi4vdr = cPluginManager::GetPlugin("avahi4vdr");
...
if (avahi4vdr != NULL)
serviceId = avahi4vdr->SVDRPCommand("CreateService", "caller=dbus2vdr,name=dbus2vdr,protocol=IPv4,port=12345,type=_dbus._tcp,subtype=_vdr_dbus2vdr._sub._dbus._tcp", replyCode);
...
if (replyCode == 900)
avahi4vdr->SVDRPCommand("DeleteService", *serviceId, replyCode);
Browse for network services
---------------------------
// for a real worl example, lookup dbus2vdr in its git
int replyCode = 0;
cString browserId;
cPlugin *avahi4vdr = cPluginManager::GetPlugin("avahi4vdr");
...
if (avahi4vdr != NULL)
browserId = avahi4vdr->SVDRPCommand("CreateBrowser", "caller=dbus2vdr,protocol=IPv4,type=_vdr_dbus2vdr._sub._dbus._tcp", replyCode);
...
if (replyCode == 900)
avahi4vdr->SVDRPCommand("DeleteBrowser", *browserId, replyCode);
...
bool cPluginDbus2vdr::Service(const char *Id, void *Data)
{
if (strcmp(Id, "avahi4vdr-event") == 0) {
cAvahiHelper options((const char*)Data);
const char *event = options.Get("event");
const char *browser_id = options.Get("id");
if (strcmp(event, "browser-service-resolved") == 0) {
const char *name = options.Get("name");
const char *host = options.Get("host");
const char *protocol = options.Get("protocol");
const char *address = options.Get("address");
const char *port = options.Get("port");
const char *local = options.Get("local");
const char *txt = NULL;
int txt_nr = 0;
while (true) {
txt = options.Get("txt", txt_nr);
if (txt == NULL)
break;
...
txt_nr++;
}
...
}
else if (strcmp(event, "browser-service-removed") == 0) {
const char *name = options.Get("name");
const char *protocol = options.Get("protocol");
const char *local = options.Get("local");
...
}
return true;
}
return false;
}
Parameters
----------
Every call to avahi4vdr expects a string with comma separated key/value-pairs like
"key1=value1,key2=value2,key3=value3,..."
If a key or value contains a comma or backslash, it has to be escaped with a backslash.
"name=dbus2vdr, host vdr" must be "name=dbus2vdr\, host vdr"
You should use vdr's function 'cString esc_name = strescape(name, "\\,");' to get a
correctly escaped string.
You can use avahi-helper.h for a class that splits up the parameter string into the
single key/value pairs.
The returned strings of SVDRPCommand may contain the following keys:
id: uuid of the service or browser you created
error: error message, e.g. if parameters are missing
message: success message
Events
------
If avahi4vdr notices that something "happens" to your services or browsers it will call
the Service function of the plugin with the name of the parameter "caller" given to
"CreateService" or "CreateBrowser".
The first parameter will be "avahi4vdr-event" and the second a key/value-list in the
format mentioned above.
Service events
--------------
* event=service-created,id=a328227c-a1e7-45f8-8062-6e9f81395f90
Your service has been created by "CreateService" but has not been published yet.
* event=service-started,id=a328227c-a1e7-45f8-8062-6e9f81395f90
Your service is published by the avahi-daemon.
* event=service-stopped,id=a328227c-a1e7-45f8-8062-6e9f81395f90
Publishing of your service has been stopped. This may occur if avahi4vdr gets some error
from the avahi-daemon or if the avahi-daemon stopps.
avahi4vdr will try to reconnect to the daemon and will publish your services again.
You don't have to do anything.
* event=service-deleted,id=a328227c-a1e7-45f8-8062-6e9f81395f90
Your service has been deleted through a call of "DeleteService" or halt of vdr.
Browser events
--------------
* event=browser-created,id=a3c43ebb-be1d-4312-908f-2a78c91a062b
You (or someone using your plugin's name) created a browser with "CreateBrowser".
* event=browser-started,id=a3c43ebb-be1d-4312-908f-2a78c91a062b
The browser is started and will get notified if it discovers something matching your browser's data.
* event=browser-service-resolved,id=a3c43ebb-be1d-4312-908f-2a78c91a062b,name=dbus2vdr on vdr,type=_dbus._tcp,protocol=IPv6,address=fe80::223:54ff:fe2f:4712,host=vdr.local,port=59419,local=true
* event=browser-service-resolved,id=a3c43ebb-be1d-4312-908f-2a78c91a062b,name=dbus2vdr on vdr,type=_dbus._tcp,protocol=IPv4,address=192.168.23.13,host=vdr.local,port=59419,local=true
Congratulations, you discovered a network service!
* event=browser-allfornow,id=a3c43ebb-be1d-4312-908f-2a78c91a062b
Avahi doesn't expect any new services in the near future.
* event=browser-service-removed,id=a3c43ebb-be1d-4312-908f-2a78c91a062b,name=dbus2vdr on vdr,type=_dbus._tcp,protocol=IPv4,local=true
* event=browser-service-removed,id=a3c43ebb-be1d-4312-908f-2a78c91a062b,name=dbus2vdr on vdr,type=_dbus._tcp,protocol=IPv6,local=true
The service is not longer available.
* event=browser-stopped,id=a3c43ebb-be1d-4312-908f-2a78c91a062b
Like "serivce-stopped", see above.
* event=browser-deleted,id=a3c43ebb-be1d-4312-908f-2a78c91a062b
Like "browser-stopped", see above.
services.conf
-------------
You can place a file called services.conf in the plugin's configuration directory.
For each valid line with a service configuration, this service will be published
via the avahi-daemon. Each occurrence of "%h" will be replaced with the hostname.
You should use the following scheme for the subtypes:
_vdr_<pluginname>._sub._<protocol>._<transport>
Examples:
name=SVDRP on %h,type=_svdrp._tcp,port=6419
name=vdr-live on %h,type=_https._tcp,port=8443,subtype=_vdr_live._sub._https._tcp
name=streamdev-server on %h,type=_http._tcp,port=3000,subtype=_vdr_streamdevserver._sub._http._tcp
To reload the services.conf there's the SVDRP command "ReloadServices".