1 /*-------------------------------------------------------------------------
2  * Copyright (C) 2000 Caldera Systems, Inc
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  *    Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *    Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  *    Neither the name of Caldera Systems nor the names of its
17  *    contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALDERA
24  * SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *-------------------------------------------------------------------------*/
32 
33 /** Declarations used internally by libslp.
34  *
35  * @file       libslp.h
36  * @author     Matthew Peterson, John Calcote (jcalcote@novell.com)
37  * @attention  Please submit patches to http://www.openslp.org
38  * @ingroup    LibSLPCode
39  */
40 
41 #ifndef LIBSLP_H_INCLUDED
42 #define LIBSLP_H_INCLUDED
43 
44 /*!@defgroup LibSLPCode User Agent
45  * @{
46  */
47 
48 #include "slp_types.h"
49 #include "slp_buffer.h"
50 #include "slp_linkedlist.h"
51 #include "slp_socket.h"
52 #include "slp_atomic.h"
53 #include "slp_thread.h"
54 #include "slp_debug.h"
55 #include "slp_spi.h"
56 #include "slp_auth.h"
57 
58 #define MINIMUM_DISCOVERY_INTERVAL  300    /* 5 minutes */
59 #define MAX_RETRANSMITS             5      /* we'll only re-xmit 5 times! */
60 #define SLP_FUNCT_DASRVRQST         0x7f   /* fake id used internally */
61 
62 typedef enum
63 {
64    SLPREG = 0,
65    SLPDEREG,
66    SLPFINDSRVS,
67    SLPFINDSRVTYPES,
68    SLPFINDATTRS,
69    SLPDELATTRS
70 } SLPCallType;
71 
72 /** Used to collate Service URLS.
73  */
74 typedef struct _SLPSrvUrlCollatedItem
75 {
76    SLPListItem listitem;         /*!< Makes this a list item. */
77    char * srvurl;                /*!< The item's service URL. */
78    unsigned short lifetime;      /*!< The item's lifetime. */
79 } SLPSrvUrlCollatedItem;
80 
81 /** Used to pass all user parameters for "registration" requests.
82  */
83 typedef struct _SLPRegParams
84 {
85    uint16_t lifetime;            /*!< The desired registration lifetime. */
86    int fresh;                    /*!< New or renewed registration. */
87    size_t urllen;                /*!< The length of @e url in bytes. */
88    const char * url;             /*!< The service: URL to register. */
89    size_t srvtypelen;            /*!< The length of @e srvtype in bytes. */
90    const char * srvtype;         /*!< The service type to register. */
91    size_t scopelistlen;          /*!< The length of @e scopelist in bytes. */
92    const char * scopelist;       /*!< The scopes in which to register. */
93    size_t attrlistlen;           /*!< The length of @e attrlist in bytes. */
94    const char * attrlist;        /*!< The list of attributes to register. */
95    SLPRegReport * callback;      /*!< The users's results callback function. */
96    void * cookie;                /*!< The users's opaque pass-through data. */
97 } SLPRegParams, * PSLPRegParams;
98 
99 /** Used to pass all user parameters for "deregistration" requests.
100  */
101 typedef struct _SLPDeRegParams
102 {
103    size_t scopelistlen;          /*!< The length of @e scopelist in bytes. */
104    const char * scopelist;       /*!< The scopes to deregister from. */
105    size_t urllen;                /*!< The length of @e url in bytes. */
106    const char * url;             /*!< The service: URL to deregister. */
107    SLPRegReport * callback;      /*!< The users's results callback function. */
108    void * cookie;                /*!< The users's opaque pass-through data. */
109 } SLPDeRegParams, * PSLPDeRegParams;
110 
111 /** Used to pass all user parameters for "find service types" requests.
112  */
113 typedef struct _SLPFindSrvTypesParams
114 {
115    size_t namingauthlen;         /*!< The length of @e namingauth in bytes. */
116    const char * namingauth;      /*!< The naming authority to search type in. */
117    size_t scopelistlen;          /*!< The length of @e scopelist in bytes. */
118    const char * scopelist;       /*!< The scopes in which to search for types. */
119    SLPSrvTypeCallback * callback;/*!< The users's results callback function. */
120    void * cookie;                /*!< The users's opaque pass-through data. */
121 } SLPFindSrvTypesParams, * PSLPFindSrvTypesParams;
122 
123 /** Used to pass all user parameters for "find services" requests.
124  */
125 typedef struct _SLPFindSrvsParams
126 {
127    size_t srvtypelen;            /*!< The length of @e srvtype in bytes. */
128    const char * srvtype;         /*!< The service type to locate. */
129    size_t scopelistlen;          /*!< The length of @e scopelist in bytes. */
130    const char * scopelist;       /*!< The scopes in which to search. */
131    size_t predicatelen;          /*!< The length of @e predicate in bytes. */
132    const char * predicate;       /*!< The predicate associated with the find. */
133    SLPSrvURLCallback * callback; /*!< The user's results callback function. */
134    void * cookie;                /*!< The users's opaque pass-through data. */
135 } SLPFindSrvsParams, * PSLPFindSrvsParams;
136 
137 /** Used to pass all user parameters for "find attributes" requests.
138  */
139 typedef struct _SLPFindAttrsParams
140 {
141    size_t urllen;                /*!< The length of @e url in bytes. */
142    const char * url;             /*!< The URL for which to find attributes. */
143    size_t scopelistlen;          /*!< The length of @e scopelist in bytes. */
144    const char * scopelist;       /*!< The associated scope list. */
145    size_t taglistlen;            /*!< The length of @e taglist in bytes. */
146    const char * taglist;         /*!< The associated attribute tag list. */
147    SLPAttrCallback * callback;   /*!< The user's results callback function. */
148    void * cookie;                /*!< The users's opaque pass-through data. */
149 } SLPFindAttrsParams, * PSLPFindAttrsParams;
150 
151 /** A union of parameter structures.
152  *
153  * There is one parameter structure for each public API in the OpenSLP
154  * library. Each parameter structure is designed to hold the parameters
155  * passed in that specific handle-based API.
156  */
157 typedef union _SLPHandleCallParams
158 {
159    SLPRegParams reg;             /*!< Registration parameters. */
160    SLPDeRegParams dereg;         /*!< Deregistration parameters. */
161    SLPFindSrvTypesParams findsrvtypes; /*!< Find Service Type parameters. */
162    SLPFindSrvsParams findsrvs;   /*!< Find Service parameters. */
163    SLPFindAttrsParams findattrs; /*!< Find Attribute parameters. */
164 } SLPHandleCallParams;
165 
166 /** OpenSLP handle state information.
167  *
168  * This structure holds internal state information relative to an open
169  * OpenSLP API handle. In fact, the OpenSLP handle is really one of these
170  * structures.
171  */
172 typedef struct _SLPHandleInfo
173 {
174 #define SLP_HANDLE_SIG 0xbeeffeed
175    unsigned int sig;             /*!< A handle signature value. */
176    intptr_t inUse;               /*!< A lock used to control access. */
177 
178 #ifdef ENABLE_ASYNC_API
179    SLPBoolean isAsync;           /*!< Is operation sync or async? */
180    SLPThreadHandle th;           /*!< The async operation thread handle. */
181 #endif
182 
183    sockfd_t dasock;              /*!< A cached DA socket. */
184    struct sockaddr_storage daaddr; /*!< A cached DA address. */
185    char * dascope;               /*!< A cached DA scope. */
186    size_t dascopelen;            /*!< The length of @p dascope in bytes. */
187    sockfd_t sasock;              /*!< A cached SA socket. */
188    struct sockaddr_storage saaddr; /*!< A cached SA address. */
189    char * sascope;               /*!< A cached SA scope. */
190    size_t sascopelen;            /*!< The length of @p sascope in bytes. */
191 
192 #ifndef MI_NOT_SUPPORTED
193    const char * McastIFList;     /*!< A list of multi-cast interfaces. */
194 #endif
195 
196 #ifndef UNICAST_NOT_SUPPORTED
197    SLPBoolean dounicast;         /*!< A boolean flag - should I unicast? */
198    sockfd_t unicastsock;         /*!< A cached unicast socket. */
199    struct sockaddr_storage ucaddr; /*!< A cached unicast address. */
200    char * unicastscope;          /*!< The unicast scope list. */
201    size_t unicastscopelen;       /*!< The length in bytes of @p unicastscope. */
202 #endif
203 
204    size_t langtaglen;            /*!< The length in bytes of @p langtag. */
205    char * langtag;               /*!< The language tag assoicated. */
206    int callbackcount;            /*!< The callbacks made in this request. */
207    SLPList collatedsrvurls;      /*!< The list of collated service URLs. */
208    char * collatedsrvtypes;      /*!< The list of collated service types. */
209 
210 #ifdef ENABLE_SLPv2_SECURITY
211    SLPSpiHandle hspi;            /*!< The Security Parameter Index value. */
212 #endif
213 
214    SLPHandleCallParams params;   /*!< A union of parameter structures. */
215 } SLPHandleInfo;
216 
217 sockfd_t NetworkConnectToSlpd(void * peeraddr);
218 void NetworkDisconnectDA(SLPHandleInfo * handle);
219 void NetworkDisconnectSA(SLPHandleInfo * handle);
220 sockfd_t NetworkConnectToDA(SLPHandleInfo * handle, const char * scopelist,
221       size_t scopelistlen, void * peeraddr);
222 sockfd_t NetworkConnectToSA(SLPHandleInfo * handle, const char * scopelist,
223       size_t scopelistlen, void * saaddr);
224 
225 typedef SLPBoolean NetworkRplyCallback(SLPError errorcode,
226       void * peeraddr, SLPBuffer replybuf, void * cookie);
227 
228 SLPError NetworkRqstRply(sockfd_t sock, void * peeraddr,
229       const char * langtag, size_t extoffset, void * buf, char buftype,
230       size_t bufsize, NetworkRplyCallback callback, void * cookie,
231       int isV1);
232 
233 SLPError NetworkMcastRqstRply(SLPHandleInfo * handle,
234       void * buf, char buftype, size_t bufsize,
235       NetworkRplyCallback callback, void * cookie, int isV1);
236 
237 #ifndef UNICAST_NOT_SUPPORTED
238 SLPError NetworkUcastRqstRply(SLPHandleInfo * handle, void * buf,
239       char buftype, size_t bufsize, NetworkRplyCallback callback,
240       void * cookie, int isV1);
241 SLPError NetworkMultiUcastRqstRply(
242                          struct sockaddr_in* destaddr,		// This is an array of addresses
243                          const char* langtag,
244                          char* buf,
245                          char buftype,
246                          size_t bufsize,
247                          NetworkRplyCallback callback,
248                          void * cookie,
249                          int isV1);
250 #endif
251 
252 sockfd_t KnownDAConnect(SLPHandleInfo * handle, size_t scopelistlen,
253       const char * scopelist, void * peeraddr);
254 
255 void KnownDABadDA(void * daaddr);
256 int KnownDAGetScopes(size_t * scopelistlen, char ** scopelist,
257       SLPHandleInfo * handle);
258 void KnownDAProcessSrvRqst(SLPHandleInfo * handle);
259 SLPBoolean KnownDASpanningListFromCache(SLPHandleInfo * handle,
260                                         int scopelistlen,
261                                         const char* scopelist,
262                                         struct sockaddr_in** daaddrs);
263 
264 void KnownDAFreeAll(void);
265 
266 void PutL16String(uint8_t ** cpp, const char * str, size_t strsz);
267 size_t SizeofURLEntry(size_t urllen, size_t urlauthlen);
268 void PutURLEntry(uint8_t ** cpp, uint16_t lifetime, const char * url,
269       size_t urllen, const uint8_t * urlauth, size_t urlauthlen);
270 
271 int LIBSLPPropertyInit(char const * gconffile);
272 void LIBSLPPropertyCleanup();
273 
274 /*! @} */
275 
276 #endif /* LIBSLP_H_INCLUDED */
277 
278 /*=========================================================================*/
279