1 mday 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2001 The Open Group, BMC Software, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 mday 1.1 // DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Mike Day (mdday@us.ibm.com)
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #ifndef SLP_H_INCLUDED
31 #define SLP_H_INCLUDED
32
33 #include <typeinfo>
34 #include <Pegasus/Common/Config.h>
|
35 mday 1.2 #include <Pegasus/Common/String.h>
|
36 mday 1.1
|
37 karl 1.3 #ifdef PEGASUS_OS_TYPE_WINDOWS
|
38 mday 1.1 #include "lslp-perl-windows.h"
39 #endif /* win 32 */
40
|
41 karl 1.3 #ifdef PEGASUS_OS_TYPE_UNIX
|
42 mday 1.1 #include "lslp-perl-linux.h"
43 #endif
44
45 #include "lslp-perl.h"
46
47 PEGASUS_NAMESPACE_BEGIN
48
49
|
50 mday 1.2 PEGASUS_EXPORT String slp_get_host_name(void) ;
|
51 mday 1.1
52 #ifdef _WIN32
53 PEGASUS_EXPORT int gethostbyname_r(const char *name,
54 struct hostent *resultbuf,
55 char *buf,
56 size_t bufsize,
57 struct hostent **result,
58 int *errno) ;
59 #endif
|
60 mike 1.6 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_TRU64)
|
61 karl 1.3 PEGASUS_EXPORT int gethostbyname_r(const char *name,
62 struct hostent *resultbuf,
63 char *buf,
64 size_t bufsize,
65 struct hostent **result,
66 int *errno) ;
67 #endif
|
68 mday 1.1
|
69 mday 1.4 PEGASUS_EXPORT void slp_get_addr_string_from_url(const Sint8 *url, String & addr) ;
|
70 mday 1.1
|
71 mday 1.4 PEGASUS_EXPORT Boolean get_addr_from_url(const Sint8 *url, struct sockaddr_in *addr , Sint8 **host) ;
72 PEGASUS_EXPORT void slp_get_host_string_from_url(const Sint8 *url, String & host) ;
|
73 mday 1.1
74 #define DA_SRVTYPE "service:directory-agent:\0"
75 #define DA_SRVTYPELEN 25
76 #define DA_SCOPE "DEFAULT\0"
77 #define DA_SCOPELEN 8
78
79
80 #define TYPE_UNKKNOWN 0
81 #define TYPE_DA_LIST 1
82 #define TYPE_RPLY_LIST 2
83
84
85
86 template<class L> class PEGASUS_EXPORT slp2_list {
87
88 private:
|
89 mday 1.2 // struct list_rep;
|
90 mday 1.1 L *_rep;
91 slp2_list *_next;
92 slp2_list *_prev;
93 slp2_list *_cur;
94 Boolean _isHead ;
95 int _count;
96 // unlink this node from whichever list it is on
97 inline void unlink( void ) { _prev->_next = _next; _next->_prev = _prev; }
98 // insert this node into list owned by head
99 inline void insert(slp2_list & head) { _prev = head;
100 _next = head._next;
101 head._next->_prev = this;
102 head._next = this;
103 head._count++; }
104 public:
105 slp2_list(Boolean head = true) : _rep(NULL), _isHead(head), _count(0) { _next = this; _prev = this; _cur = this;}
106 ~slp2_list() { empty_list() ; }
107 void insert(L *);
108 void empty_list( void ) ;
109 L *remove( void ) ;
|
110 mday 1.2 L *remove(Sint8 *key) ;
|
111 mday 1.4 L *reference(Sint8 *key);
|
112 mday 1.1 L *next( L * ); // poor man's iterators
113 L *prev( L * );
|
114 mday 1.2 Boolean exists(Sint8 *key);
|
115 mday 1.1 int count(void);
116 } ;
117
118 struct PEGASUS_EXPORT da_list
119 {
120 ~da_list();
|
121 mday 1.2 da_list() : url(NULL), scope(NULL), attr(NULL), spi(NULL), auth(NULL) {}
122 Boolean operator ==(const Sint8 *key) const ;
123 inline Boolean operator ==(const da_list & b) const { return (operator ==( b.url )); }
|
124 mday 1.1 Sint8 function;
125 Uint16 err;
126 Uint32 stateless_boot;
127 Sint8 *url;
128 Sint8 *scope;
129 Sint8 *attr;
130 Sint8 *spi;
131 Sint8 auth_blocks;
132 Sint8 *auth;
133 Sint8 remote[16];
134 } ;
135
136 struct PEGASUS_EXPORT rply_list
137 {
138 ~rply_list();
|
139 mday 1.2 rply_list() : url(NULL), auth(NULL) {}
140 Boolean operator ==(const Sint8 *key ) const ;
141 inline Boolean operator ==(const rply_list & b ) const { return (operator ==(b.url)) ; }
|
142 mday 1.1 Sint8 function;
143 Uint16 err;
144 Uint16 lifetime;
145 Sint8 *url;
146 Sint8 auth_blocks;
147 Sint8 *auth;
148 Sint8 remote[16];
149 } ;
150
151
|
152 mday 1.2 struct PEGASUS_EXPORT reg_list
153 {
154 ~reg_list();
155 reg_list() : url(NULL), attributes(NULL), service_type(NULL), scopes(NULL) {}
|
156 mday 1.4 reg_list(Sint8 *url, Sint8 *attributes, Sint8 *service_type, Sint8 *scopes, time_t lifetime);
|
157 mday 1.2 Boolean operator ==(const Sint8 *key )const;
158 inline Boolean operator ==(const reg_list & b) const { return (operator ==(b.url) ) ; }
159 Sint8 *url;
160 Sint8 *attributes;
161 Sint8 *service_type;
162 Sint8 *scopes;
|
163 mday 1.4 time_t lifetime;
|
164 mday 1.2 } ;
165
|
166 mday 1.4 struct PEGASUS_EXPORT url_entry
167 {
168 url_entry( Uint16 lifetime = 0xffff,
169 Sint8 *url = NULL,
170 Uint8 num_auths = 0,
171 Uint8 *auth_blocks = NULL);
172 ~url_entry();
173 Boolean operator ==(const Sint8 *key )const;
174 inline Boolean operator ==(const url_entry & b) const { return (operator ==(b.url) ) ; }
175 Uint16 lifetime;
176 Sint16 len;
177 Sint8 *url;
178 Uint8 num_auths;
179 Uint8 *auth_blocks;
180 };
181
|
182 mday 1.2
|
183 mday 1.1 class PEGASUS_EXPORT slp_client
184 {
185
186 public:
187 slp_client(const Sint8 *target_addr = "239.255.255.253",
188 const Sint8 *local_addr = "0.0.0.0",
189 Uint16 target_port = 427,
|
190 mday 1.4 const Sint8 *spi = NULL,
191 const Sint8 *scopes = "DEFAULT");
|
192 mday 1.1 ~slp_client();
193
194 inline void set_convergence(Sint8 convergence) { _convergence = convergence ; }
195 inline void set_port(Sint16 port) { _target_port = port ; }
196 void set_target_addr(const Sint8 *addr);
197 void set_local_interface( const Sint8 *iface);
198 inline void set_timout_retry(Uint32 t_sec,
199 Uint32 t_usec,
200 Sint8 retries,
201 Uint8 ttl) { _tv.tv_sec = t_sec; _tv.tv_usec = t_usec;
202 _retries = retries; _ttl = ttl; }
203
204 void set_spi(const Sint8 *spi) ;
|
205 mday 1.4 void set_scopes(const Sint8 *scopes) ;
|
206 karl 1.3 rply_list *get_response( void );
|
207 mday 1.1 int find_das(const Sint8 *predicate,
208 const Sint8 *scopes) ;
|
209 mday 1.4
210 void discovery_cycle ( const Sint8 *type,
211 const Sint8 *predicate,
212 const Sint8 *scopes) ;
213
214 void converge_srv_req( const Sint8 *type,
215 const Sint8 *predicate,
216 const Sint8 *scopes) ;
217
218 void unicast_srv_req( const Sint8 *type,
|
219 mday 1.1 const Sint8 *predicate,
|
220 mday 1.4 const Sint8 *scopes,
221 struct sockaddr_in *addr) ;
222 void local_srv_req(const Sint8 *type,
223 const Sint8 *predicate,
224 const Sint8 *scopes) ;
225
|
226 mday 1.1 void srv_req( const Sint8 *type,
227 const Sint8 *predicate,
|
228 mday 1.4 const Sint8 *scopes,
229 Boolean retry);
|
230 mday 1.1
231 Boolean srv_reg( Sint8 *url,
|
232 mday 1.4 Sint8 *attributes,
233 Sint8 *service_type,
234 Sint8 *scopes,
|
235 mday 1.1 Sint16 lifetime);
236
237 int srv_reg_all( Sint8 *url,
238 Sint8 *attributes,
239 Sint8 *service_type,
240 Sint8 *scopes,
241 Sint16 lifetime) ;
|
242 mday 1.4
243 void srv_reg_local ( Sint8 *url,
244 Sint8 *attributes,
245 Sint8 *service_type,
246 Sint8 *scopes,
247 Sint16 lifetime) ;
248
|
249 mday 1.2 Sint32 service_listener( void ) ;
|
250 mday 1.1
251 private:
252 Uint16 _pr_buf_len;
253 Uint16 _buf_len;
254 Sint8 _version;
255 Uint16 _xid;
256 Uint16 _target_port;
257 Uint32 _target_addr;
258 Uint32 _local_addr;
|
259 mday 1.4 Uint32 *_local_addr_list;
|
260 mday 1.1 Sint8 *_spi;
|
261 mday 1.4 Sint8 *_scopes;
|
262 mday 1.1 Sint8 *_pr_buf;
263 Sint8 *_msg_buf;
|
264 mday 1.2 Sint8 *_rcv_buf;
|
265 mday 1.1 Sint8 _err_buf[255];
|
266 mday 1.2 Boolean _use_das;
267 time_t _last_da_cycle;
|
268 mday 1.1 struct timeval _tv;
269 int _retries;
270 int _ttl;
271 int _convergence;
272 void *_crypto_context;
|
273 mday 1.2 SOCKET _rcv_sock;
|
274 mday 1.1 #ifdef _WIN32
275 static int _winsock_count ;
276 static WSADATA _wsa_data;
277 #endif
278 slp2_list<da_list> das;
279 slp2_list<rply_list> replies;
|
280 mday 1.2 slp2_list<reg_list> regs;
|
281 mday 1.1
282 // void free_list( template<class L>slp2_list &list ) ;
283 void prepare_pr_buf(const Sint8 *address);
284 Boolean prepare_query(Uint16 xid,
285 const Sint8 *service_type,
286 const Sint8 *scopes,
287 const Sint8 *predicate ) ;
|
288 mday 1.4 void decode_msg(struct sockaddr_in *remote ) ;
289 void decode_srvreq(struct sockaddr_in *remote );
|
290 mday 1.1 void decode_srvrply(struct sockaddr_in *remote) ;
291 void decode_daadvert(struct sockaddr_in *remote) ;
292 Boolean send_rcv_udp(void) ;
|
293 mday 1.2 Sint32 service_listener(SOCKET );
294 Sint32 service_listener_wait(time_t, SOCKET, Boolean) ;
|
295 mday 1.4 Boolean slp_previous_responder(Sint8 *pr_list);
|
296 mday 1.1 } ;
297
298 PEGASUS_NAMESPACE_END
299
300 #endif // slp_h_included
|