(file) Return to slp.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / slp

  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 mike  1.7   inline void insert(slp2_list & head) 
100               {  
101                 _prev = &head; 
102                 _next = head._next; 
103                 head._next->_prev = this; 
104                 head._next = this;   
105                 head._count++; 
106               }
107 mday  1.1 public:
108             slp2_list(Boolean head = true) :  _rep(NULL), _isHead(head), _count(0) { _next = this; _prev = this; _cur = this;}
109             ~slp2_list() { empty_list() ; }
110             void insert(L *);
111             void empty_list( void ) ;
112             L *remove( void ) ;
113 kumpf 1.8   L *remove(const Sint8 *key) ;
114             L *reference(const Sint8 *key);
115             L *next( const L * ); // poor man's iterators 
116             L *prev( const L * );
117             Boolean exists(const Sint8 *key);
118 mday  1.1   int count(void);
119           } ;
120           
121           struct PEGASUS_EXPORT da_list
122           {
123             ~da_list();
124 mday  1.2   da_list() : url(NULL), scope(NULL), attr(NULL), spi(NULL), auth(NULL) {}
125             Boolean operator ==(const Sint8 *key) const ; 
126             inline Boolean operator ==(const da_list & b) const { return (operator ==( b.url )); }
127 mday  1.1   Sint8 function;
128             Uint16 err;
129             Uint32 stateless_boot;
130             Sint8 *url;
131             Sint8 *scope;
132             Sint8 *attr;
133             Sint8 *spi;
134             Sint8 auth_blocks;
135             Sint8 *auth;
136             Sint8 remote[16]; 
137           } ;
138           
139           struct PEGASUS_EXPORT rply_list
140           {
141             ~rply_list();
142 mday  1.2   rply_list() : url(NULL), auth(NULL) {}
143             Boolean operator ==(const Sint8 *key ) const ;
144             inline Boolean operator ==(const rply_list & b ) const { return (operator ==(b.url)) ; }
145 mday  1.1   Sint8 function;
146             Uint16 err;
147             Uint16 lifetime;
148             Sint8 *url;
149             Sint8 auth_blocks;
150             Sint8 *auth;
151             Sint8 remote[16];
152           } ;
153           
154           
155 mday  1.2 struct PEGASUS_EXPORT reg_list
156           {
157             ~reg_list();
158             reg_list() : url(NULL), attributes(NULL), service_type(NULL), scopes(NULL) {} 
159 kumpf 1.8   reg_list(const Sint8 *url, const Sint8 *attributes, const Sint8 *service_type, const Sint8 *scopes, time_t lifetime);
160 mday  1.2   Boolean operator ==(const Sint8 *key )const;
161             inline Boolean operator ==(const reg_list & b) const { return (operator ==(b.url) ) ; }
162             Sint8 *url;
163             Sint8 *attributes;
164             Sint8 *service_type;
165             Sint8 *scopes;
166 mday  1.4   time_t lifetime;
167 mday  1.2 } ;
168           
169 mday  1.4 struct PEGASUS_EXPORT url_entry
170           {
171             url_entry( Uint16 lifetime = 0xffff, 
172           	     Sint8 *url = NULL, 
173           	     Uint8 num_auths = 0,
174           	     Uint8 *auth_blocks = NULL);
175             ~url_entry();
176             Boolean operator ==(const Sint8 *key )const;
177             inline Boolean operator ==(const url_entry & b) const { return (operator ==(b.url) ) ; }
178             Uint16 lifetime;
179             Sint16 len;
180             Sint8 *url;
181             Uint8 num_auths;
182             Uint8 *auth_blocks;
183           };
184           
185 mday  1.2 
186 mday  1.1 class PEGASUS_EXPORT slp_client 
187           {
188           
189           public: 
190             slp_client(const Sint8 *target_addr = "239.255.255.253",
191           	     const Sint8 *local_addr = "0.0.0.0", 
192           	     Uint16 target_port = 427, 
193 mday  1.4 	     const Sint8 *spi = NULL,
194           	     const Sint8 *scopes = "DEFAULT");
195 mday  1.1   ~slp_client();
196             
197             inline void set_convergence(Sint8 convergence) { _convergence = convergence ; } 
198             inline void set_port(Sint16 port) { _target_port = port ; }
199             void set_target_addr(const Sint8 *addr);
200             void set_local_interface( const Sint8 *iface); 
201             inline void set_timout_retry(Uint32 t_sec, 
202           			       Uint32 t_usec, 
203           			       Sint8 retries, 
204           			       Uint8 ttl) { _tv.tv_sec = t_sec; _tv.tv_usec = t_usec;
205           					    _retries = retries; _ttl = ttl; }
206           
207             void set_spi(const Sint8 *spi) ;
208 mday  1.4   void set_scopes(const Sint8 *scopes) ;
209 karl  1.3   rply_list *get_response( void );
210 mday  1.1   int find_das(const Sint8 *predicate, 
211           	       const Sint8 *scopes) ;
212 mday  1.4 
213             void discovery_cycle ( const Sint8 *type, 
214           			 const Sint8 *predicate, 
215           			 const Sint8 *scopes) ;
216           
217             void converge_srv_req( const Sint8 *type, 
218           			 const Sint8 *predicate, 
219           			 const Sint8 *scopes) ;
220           
221             void unicast_srv_req( const Sint8 *type, 
222 mday  1.1 			const Sint8 *predicate, 
223 mday  1.4 			const Sint8 *scopes, 
224           			struct sockaddr_in *addr) ;
225             void local_srv_req(const Sint8 *type, 
226           			 const Sint8 *predicate, 
227           			 const Sint8 *scopes) ;
228           
229 mday  1.1   void srv_req( const Sint8 *type, 
230           		const Sint8 *predicate, 
231 mday  1.4 		const Sint8 *scopes, 
232           		Boolean retry);
233 mday  1.1 
234 kumpf 1.8   Boolean srv_reg( const Sint8 *url,
235           		   const Sint8 *attributes,
236           		   const Sint8 *service_type,
237           		   const Sint8 *scopes,
238 mday  1.1 		   Sint16 lifetime);
239             
240 kumpf 1.8   int srv_reg_all( const Sint8 *url,
241           		   const Sint8 *attributes,
242           		   const Sint8 *service_type,
243           		   const Sint8 *scopes,
244 mday  1.1 		   Sint16 lifetime) ;
245 mday  1.4 
246 kumpf 1.8   void srv_reg_local ( const Sint8 *url,
247           		       const Sint8 *attributes, 
248           		       const Sint8 *service_type, 
249           		       const Sint8 *scopes, 
250 mday  1.4 		       Sint16 lifetime) ;
251           
252 mday  1.2   Sint32 service_listener( void  ) ;
253 mday  1.1   
254            private:
255             Uint16 _pr_buf_len;
256             Uint16 _buf_len;
257             Sint8 _version;
258             Uint16 _xid;
259             Uint16 _target_port;
260             Uint32 _target_addr;
261             Uint32 _local_addr;
262 mday  1.4   Uint32 *_local_addr_list;
263 mday  1.1   Sint8 *_spi;
264 mday  1.4   Sint8 *_scopes;
265 mday  1.1   Sint8 *_pr_buf;
266             Sint8 *_msg_buf;
267 mday  1.2   Sint8 *_rcv_buf;
268 mday  1.1   Sint8 _err_buf[255];
269 mday  1.2   Boolean _use_das;
270             time_t _last_da_cycle;
271 mday  1.1   struct timeval _tv;
272             int _retries;
273             int _ttl;
274             int  _convergence;
275             void *_crypto_context;
276 mday  1.2   SOCKET _rcv_sock;
277 mday  1.1 #ifdef _WIN32
278             static int _winsock_count ;
279             static WSADATA _wsa_data;
280           #endif
281             slp2_list<da_list> das;
282             slp2_list<rply_list> replies;
283 mday  1.2   slp2_list<reg_list> regs;
284 mday  1.1 
285             //  void free_list( template<class L>slp2_list &list ) ;
286             void prepare_pr_buf(const Sint8 *address);
287             Boolean prepare_query(Uint16 xid,
288           		     const Sint8 *service_type,
289           		     const Sint8 *scopes, 
290           		     const Sint8 *predicate  ) ;
291 mday  1.4   void decode_msg(struct sockaddr_in *remote ) ;
292             void decode_srvreq(struct sockaddr_in *remote );
293 mday  1.1   void decode_srvrply(struct sockaddr_in *remote) ;
294             void decode_daadvert(struct sockaddr_in *remote) ;
295             Boolean send_rcv_udp(void) ;
296 mday  1.2   Sint32 service_listener(SOCKET );
297             Sint32 service_listener_wait(time_t, SOCKET, Boolean) ;
298 mday  1.4   Boolean slp_previous_responder(Sint8 *pr_list);
299 mday  1.1 } ;
300           
301           PEGASUS_NAMESPACE_END
302           
303           #endif // slp_h_included

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2