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