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 /** Header file that defines SLP wire protocol message structures. 34 * 35 * @file slp_message.h 36 * @author John Calcote (jcalcote@novell.com) 37 * @attention Please submit patches to http://www.openslp.org 38 * @ingroup CommonCodeMessage 39 */ 40 41 #ifndef SLP_MESSAGE_H_INCLUDED 42 #define SLP_MESSAGE_H_INCLUDED 43 44 /*!@defgroup CommonCodeMessage SLP Messages 45 * @ingroup CommonCode 46 * @{ 47 */ 48 49 #include <limits.h> 50 51 #include "slp_buffer.h" 52 #include "slp_socket.h" 53 #include "slp_types.h" 54 55 /** SLP Important constants */ 56 #define SLP_RESERVED_PORT 427 /*!< The SLP port number */ 57 #define SLP_MCAST_ADDRESS 0xeffffffd /*!< 239.255.255.253 */ 58 #define SLP_BCAST_ADDRESS 0xffffffff /*!< 255.255.255.255 */ 59 #define SLPv1_SL_MCAST_ADDRESS 0xe0000116 /*!< 224.0.1.22 */ 60 #define SLPv1_DA_MCAST_ADDRESS 0xe0000123 /*!< 224.0.1.35 */ 61 #define LOOPBACK_ADDRESS 0x7f000001 /*!< 127.0.0.1 */ 62 63 #if !defined(SLP_LIFETIME_MAXIMUM) 64 # define SLP_LIFETIME_MAXIMUM 0xffff 65 #endif 66 67 /** SLP Function ID constants */ 68 #define SLP_FUNCT_SRVRQST 1 69 #define SLP_FUNCT_SRVRPLY 2 70 #define SLP_FUNCT_SRVREG 3 71 #define SLP_FUNCT_SRVDEREG 4 72 #define SLP_FUNCT_SRVACK 5 73 #define SLP_FUNCT_ATTRRQST 6 74 #define SLP_FUNCT_ATTRRPLY 7 75 #define SLP_FUNCT_DAADVERT 8 76 #define SLP_FUNCT_SRVTYPERQST 9 77 #define SLP_FUNCT_SRVTYPERPLY 10 78 #define SLP_FUNCT_SAADVERT 11 79 80 /** SLP Protocol Error codes */ 81 #define SLP_ERROR_OK 0 82 #define SLP_ERROR_LANGUAGE_NOT_SUPPORTED 1 83 #define SLP_ERROR_PARSE_ERROR 2 84 #define SLP_ERROR_INVALID_REGISTRATION 3 85 #define SLP_ERROR_SCOPE_NOT_SUPPORTED 4 86 #define SLP_ERROR_CHARSET_NOT_UNDERSTOOD 5 /* valid only for SLPv1 */ 87 #define SLP_ERROR_AUTHENTICATION_UNKNOWN 5 88 #define SLP_ERROR_AUTHENTICATION_ABSENT 6 89 #define SLP_ERROR_AUTHENTICATION_FAILED 7 90 #define SLP_ERROR_VER_NOT_SUPPORTED 9 91 #define SLP_ERROR_INTERNAL_ERROR 10 92 #define SLP_ERROR_DA_BUSY_NOW 11 93 #define SLP_ERROR_OPTION_NOT_UNDERSTOOD 12 94 #define SLP_ERROR_INVALID_UPDATE 13 95 #define SLP_ERROR_MESSAGE_NOT_SUPPORTED 14 96 #define SLP_ERROR_REFRESH_REJECTED 15 97 98 /** Additional internal error codes */ 99 #define SLP_ERROR_RETRY_UNICAST 100 100 101 /** SLP Flags */ 102 #define SLP_FLAG_OVERFLOW 0x8000 103 #define SLP_FLAG_FRESH 0x4000 104 #define SLP_FLAG_MCAST 0x2000 105 106 #if !defined(UNICAST_NOT_SUPPORTED) 107 # define SLP_FLAG_UCAST 0x0000 108 #endif 109 110 /** SLP Constants */ 111 112 /** Max time to wait for a complete multicast query response */ 113 #define CONFIG_MC_MAX 15 114 115 /** Wait interval to give up on a unicast request retransmission */ 116 #define CONFIG_RETRY_MAX 15 117 118 /** Default wait between retransmits */ 119 #define CONFIG_RETRY_INTERVAL 3 120 121 #define SLP_DA_SERVICE_TYPE "service:directory-agent" 122 #define SLP_SA_SERVICE_TYPE "service:service-agent" 123 124 /** SLP Registration Sources */ 125 #define SLP_REG_SOURCE_UNKNOWN 0 126 #define SLP_REG_SOURCE_REMOTE 1 /* from a remote host */ 127 #define SLP_REG_SOURCE_LOCAL 2 /* from localhost or IPC */ 128 #define SLP_REG_SOURCE_STATIC 3 /* from the slp.reg file */ 129 130 /** SLP Extension IDs */ 131 132 /** @todo Deprecate the use of the experimental version of the PID watcher 133 * extension, which was originally implemented in OpenSLP 1.x. Currently the 134 * 2.x UA code base requests this extension using the EXP version in order to 135 * be compatible with 1.2.x SA's, but the 2.x SA understands both. This allows 136 * some future version of the UA to send the official version and have the 137 * (then) older version of 2.x SA's understand the official version. 138 */ 139 140 /** format: Extid(2), nxtextoffs(3), pid(4) */ 141 #define SLP_EXTENSION_ID_REG_PID 0x4001 142 #define SLP_EXTENSION_ID_REG_PID_EXP 0x9799 /* DEPRECATED */ 143 144 /** Buffer extraction and insertion macros */ 145 #define AS_UINT16(p) (uint16_t) \ 146 ( \ 147 (((const uint8_t *)(p))[0] << 8) | \ 148 (((const uint8_t *)(p))[1] ) \ 149 ) 150 151 #define AS_UINT24(p) (uint32_t) \ 152 ( \ 153 (((const uint8_t *)(p))[0] << 16) | \ 154 (((const uint8_t *)(p))[1] << 8) | \ 155 (((const uint8_t *)(p))[2] ) \ 156 ) 157 158 #define AS_UINT32(p) (uint32_t) \ 159 ( \ 160 (((const uint8_t *)(p))[0] << 24) | \ 161 (((const uint8_t *)(p))[1] << 16) | \ 162 (((const uint8_t *)(p))[2] << 8) | \ 163 (((const uint8_t *)(p))[3] ) \ 164 ) 165 166 #define TO_UINT16(p,v) \ 167 ( \ 168 (((uint8_t *)(p))[0] = (uint8_t)(((v) >> 8) & 0xff)), \ 169 (((uint8_t *)(p))[1] = (uint8_t)(((v) ) & 0xff)) \ 170 ) 171 172 #define TO_UINT24(p,v) \ 173 ( \ 174 (((uint8_t *)(p))[0] = (uint8_t)(((v) >> 16) & 0xff)), \ 175 (((uint8_t *)(p))[1] = (uint8_t)(((v) >> 8) & 0xff)), \ 176 (((uint8_t *)(p))[2] = (uint8_t)(((v) ) & 0xff)) \ 177 ) 178 179 #define TO_UINT32(p,v) \ 180 ( \ 181 (((uint8_t *)(p))[0] = (uint8_t)(((v) >> 24) & 0xff)), \ 182 (((uint8_t *)(p))[1] = (uint8_t)(((v) >> 16) & 0xff)), \ 183 (((uint8_t *)(p))[2] = (uint8_t)(((v) >> 8) & 0xff)), \ 184 (((uint8_t *)(p))[3] = (uint8_t)(((v) ) & 0xff)) \ 185 ) 186 187 /* Assuming the current byte is the packet version, returns the length */ 188 #define PEEK_LENGTH(p) ((*p == 2) ? AS_UINT24(p + 2) : (*p == 1) ? AS_UINT16(p + 2) : 1) 189 190 /* buffer-based wire routines */ 191 uint16_t GetUINT16(uint8_t ** cpp); 192 uint32_t GetUINT24(uint8_t ** cpp); 193 uint32_t GetUINT32(uint8_t ** cpp); 194 char * GetStrPtr(uint8_t ** cpp, size_t length); 195 196 void PutUINT16(uint8_t ** cpp, size_t val); 197 void PutUINT24(uint8_t ** cpp, size_t val); 198 void PutUINT32(uint8_t ** cpp, size_t val); 199 200 /** SLPHeader structure and associated functions */ 201 typedef struct _SLPHeader 202 { 203 int version; 204 int functionid; 205 size_t length; 206 int flags; 207 int encoding; /* language encoding, valid only for SLPv1 */ 208 int extoffset; 209 uint16_t xid; 210 size_t langtaglen; 211 const char * langtag; /* points into the translated message */ 212 } SLPHeader; 213 214 /** SLPAuthBlock structure and associated functions */ 215 typedef struct _SLPAuthBlock 216 { 217 uint16_t bsd; 218 size_t length; 219 uint32_t timestamp; 220 size_t spistrlen; 221 const char * spistr; 222 const char * authstruct; 223 size_t opaquelen; /* convenience */ 224 uint8_t * opaque; /* convenience */ 225 } SLPAuthBlock; 226 227 /** SLPUrlEntry structure and associated functions */ 228 typedef struct _SLPUrlEntry 229 { 230 char reserved; /*!< always 0 */ 231 int lifetime; 232 size_t urllen; 233 const char * url; 234 int authcount; 235 SLPAuthBlock * autharray; 236 size_t opaquelen; /*!< convenience */ 237 uint8_t * opaque; /*!< convenience */ 238 } SLPUrlEntry; 239 240 /** SLPSrvRqst structure and associated functions */ 241 typedef struct _SLPSrvRqst 242 { 243 size_t prlistlen; 244 const char * prlist; 245 size_t srvtypelen; 246 const char * srvtype; 247 size_t scopelistlen; 248 const char * scopelist; 249 int predicatever; 250 size_t predicatelen; 251 const char * predicate; 252 size_t spistrlen; 253 const char * spistr; 254 } SLPSrvRqst; 255 256 /** SLPSrvRply structure and associated functions */ 257 typedef struct _SLPSrvRply 258 { 259 int errorcode; 260 int urlcount; 261 SLPUrlEntry * urlarray; 262 } SLPSrvRply; 263 264 /** SLPSrvReg structure and associated functions */ 265 typedef struct _SLPSrvReg 266 { 267 SLPUrlEntry urlentry; 268 size_t srvtypelen; 269 const char * srvtype; 270 size_t scopelistlen; 271 const char * scopelist; 272 size_t attrlistlen; 273 const char * attrlist; 274 int authcount; 275 SLPAuthBlock * autharray; 276 /* The following are used for OpenSLP specific extensions */ 277 uint32_t pid; 278 int source; /*!< convenience */ 279 } SLPSrvReg; 280 281 /** SLPSrvDeReg structure and associated functions */ 282 typedef struct _SLPSrvDeReg 283 { 284 size_t scopelistlen; 285 const char * scopelist; 286 SLPUrlEntry urlentry; 287 size_t taglistlen; 288 const char * taglist; 289 } SLPSrvDeReg; 290 291 /** SLPSrvAck structure and associated functions */ 292 typedef struct _SLPSrvAck 293 { 294 int errorcode; 295 } SLPSrvAck; 296 297 /** SLPDAAdvert structure and associated functions */ 298 typedef struct _SLPDAAdvert 299 { 300 int errorcode; 301 uint32_t bootstamp; 302 size_t urllen; 303 const char * url; 304 size_t scopelistlen; 305 const char * scopelist; 306 size_t attrlistlen; 307 const char * attrlist; 308 size_t spilistlen; 309 const char * spilist; 310 int authcount; 311 SLPAuthBlock * autharray; 312 } SLPDAAdvert; 313 314 /** SLPAttrRqst structure and associated functions */ 315 typedef struct _SLPAttrRqst 316 { 317 size_t prlistlen; 318 const char * prlist; 319 size_t urllen; 320 const char * url; 321 size_t scopelistlen; 322 const char * scopelist; 323 size_t taglistlen; 324 const char * taglist; 325 size_t spistrlen; 326 const char * spistr; 327 } SLPAttrRqst; 328 329 /** SLPAttrRply structure and associated functions */ 330 typedef struct _SLPAttrRply 331 { 332 int errorcode; 333 size_t attrlistlen; 334 const char * attrlist; 335 int authcount; 336 SLPAuthBlock * autharray; 337 } SLPAttrRply; 338 339 /** SLPSrvTypeRqst structure and associated functions */ 340 typedef struct _SLPSrvTypeRqst 341 { 342 size_t prlistlen; 343 const char * prlist; 344 size_t namingauthlen; 345 const char * namingauth; 346 size_t scopelistlen; 347 const char * scopelist; 348 } SLPSrvTypeRqst; 349 350 /** SLPSrvTypeRply structure and associated functions */ 351 typedef struct _SLPSrvTypeRply 352 { 353 int errorcode; 354 size_t srvtypelistlen; 355 const char * srvtypelist; 356 } SLPSrvTypeRply; 357 358 /** SLPSAAdvert structure and associated functions */ 359 typedef struct _SLPSAAdvert 360 { 361 size_t urllen; 362 const char * url; 363 size_t scopelistlen; 364 const char * scopelist; 365 size_t attrlistlen; 366 const char * attrlist; 367 int authcount; 368 SLPAuthBlock * autharray; 369 } SLPSAAdvert; 370 371 /** SLP wire protocol message management structures and prototypes */ 372 typedef struct _SLPMessage 373 { 374 struct sockaddr_storage peer; 375 struct sockaddr_storage localaddr; 376 SLPHeader header; 377 union _body 378 { 379 SLPSrvRqst srvrqst; 380 SLPSrvRply srvrply; 381 SLPSrvReg srvreg; 382 SLPSrvDeReg srvdereg; 383 SLPSrvAck srvack; 384 SLPDAAdvert daadvert; 385 SLPAttrRqst attrrqst; 386 SLPAttrRply attrrply; 387 SLPSrvTypeRqst srvtyperqst; 388 SLPSrvTypeRply srvtyperply; 389 SLPSAAdvert saadvert; 390 } body; 391 } SLPMessage; 392 393 void SLPMessageFreeInternals(SLPMessage * mp); 394 SLPMessage * SLPMessageAlloc(void); 395 SLPMessage * SLPMessageRealloc(SLPMessage * mp); 396 void SLPMessageFree(SLPMessage * mp); 397 398 /* Message parsing routines */ 399 int SLPMessageParseHeader(SLPBuffer buffer, SLPHeader * header); 400 int SLPMessageParseBuffer(void * peeraddr, const void * localaddr, 401 SLPBuffer buffer, SLPMessage * mp); 402 403 /*! @} */ 404 405 #endif /* SLP_MESSAGE_H_INCLUDED */ 406 407 /*=========================================================================*/ 408