forked from opentechinstitute/commotion-service-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commotion-service-manager.h
128 lines (114 loc) · 3.92 KB
/
commotion-service-manager.h
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
/**
* @file commotion-service-manager.h
* @brief main functionality of the Commotion Service Manager
*
* @author Dan Staples (dismantl), danstaples@opentechinstitute.org
*
* This file is part of Commotion, Copyright (c) 2013, Josh King
*
* Commotion 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 3 of the License,
* or (at your option) any later version.
*
* Commotion is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Commotion. If not, see <http://www.gnu.org/licenses/>.
*
* =====================================================================================
*/
#ifndef COMMOTION_SERVICE_MANAGER_H
#define COMMOTION_SERVICE_MANAGER_H
#include <stdlib.h>
#include <avahi-core/lookup.h>
#include <avahi-common/simple-watch.h>
#include <avahi-common/llist.h>
/** Length (in hex chars) of Serval IDs */
#define FINGERPRINT_LEN 64
/** Length (in hex chars) of Serval-created signatures */
#define SIG_LENGTH 128
/** Name of file to output list of services when daemon receives USR1 signal */
#define DEFAULT_FILENAME "/tmp/local-services.out"
#define PIDFILE "/var/run/commotion/commotion-service-manager.pid"
/** Directory where Avahi service files are stored */
#define avahiDir "/etc/avahi/services/"
#ifndef SERVAL_PATH
#define SERVAL_PATH "/var/serval-node/serval.keyring"
#endif
#define DEFAULT_CO_SOCK "/var/run/commotiond.sock"
struct arguments {
char *co_sock;
#ifdef USE_UCI
int uci;
#endif
int nodaemon;
char *output_file;
char *pid_file;
};
typedef struct ServiceInfo ServiceInfo;
/** Struct used to hold info about a service */
struct ServiceInfo {
AvahiIfIndex interface;
AvahiProtocol protocol;
char *name,
*type,
*domain,
*host_name,
*txt; /**< string representing all the txt fields */
char address[AVAHI_ADDRESS_STR_MAX];
uint16_t port;
AvahiStringList *txt_lst; /**< Collection of all the user-defined txt fields */
AvahiTimeout *timeout; /** Timer set for the service's expiration date */
AvahiSServiceResolver *resolver;
int resolved; /**< Flag indicating whether all the fields have been resolved */
AVAHI_LLIST_FIELDS(ServiceInfo, info);
};
/** Linked list of all the local services */
extern ServiceInfo *services;
extern AvahiSimplePoll *simple_poll;
extern AvahiServer *server;
// TODO document these
void browse_type_callback(
AvahiSServiceTypeBrowser *b,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiBrowserEvent event,
const char *type,
const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void* userdata);
void browse_service_callback(
AvahiSServiceBrowser *b,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiBrowserEvent event,
const char *name,
const char *type,
const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void* userdata);
ServiceInfo *find_service(const char *name);
ServiceInfo *add_service(AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain);
void remove_service(AvahiTimeout *t, void *userdata);
int verify_announcement(ServiceInfo *i);
void resolve_callback(
AvahiSServiceResolver *r,
AVAHI_GCC_UNUSED AvahiIfIndex interface,
AVAHI_GCC_UNUSED AvahiProtocol protocol,
AvahiResolverEvent event,
const char *name,
const char *type,
const char *domain,
const char *host_name,
const AvahiAddress *address,
long port,
AvahiStringList *txt,
AvahiLookupResultFlags flags,
void* userdata);
void print_services(int signal);
void sig_handler(int signal);
#endif