1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _SLP_INTERNAL_H 28*7c478bd9Sstevel@tonic-gate #define _SLP_INTERNAL_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 31*7c478bd9Sstevel@tonic-gate extern "C" { 32*7c478bd9Sstevel@tonic-gate #endif 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include <thread.h> 35*7c478bd9Sstevel@tonic-gate #include <synch.h> 36*7c478bd9Sstevel@tonic-gate #include <errno.h> 37*7c478bd9Sstevel@tonic-gate #include <string.h> 38*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 39*7c478bd9Sstevel@tonic-gate #include <limits.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/uio.h> 42*7c478bd9Sstevel@tonic-gate #include <slp.h> 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate /* SLPv2 function numbers */ 45*7c478bd9Sstevel@tonic-gate #define SRVRQST 1 46*7c478bd9Sstevel@tonic-gate #define SRVRPLY 2 47*7c478bd9Sstevel@tonic-gate #define SRVREG 3 48*7c478bd9Sstevel@tonic-gate #define SRVDEREG 4 49*7c478bd9Sstevel@tonic-gate #define SRVACK 5 50*7c478bd9Sstevel@tonic-gate #define ATTRRQST 6 51*7c478bd9Sstevel@tonic-gate #define ATTRRPLY 7 52*7c478bd9Sstevel@tonic-gate #define DAADVERT 8 53*7c478bd9Sstevel@tonic-gate #define SRVTYPERQST 9 54*7c478bd9Sstevel@tonic-gate #define SRVTYPERPLY 10 55*7c478bd9Sstevel@tonic-gate #define SAADVERT 11 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* SLPv2 protocol error functions, hidden under the API */ 58*7c478bd9Sstevel@tonic-gate typedef enum { 59*7c478bd9Sstevel@tonic-gate SLP_MSG_PARSE_ERROR = 256, /* used internally */ 60*7c478bd9Sstevel@tonic-gate SLP_VER_NOT_SUPPORTED = 9, 61*7c478bd9Sstevel@tonic-gate SLP_SICK_DA = 10, 62*7c478bd9Sstevel@tonic-gate SLP_DA_BUSY_NOW = 11, 63*7c478bd9Sstevel@tonic-gate SLP_OPTION_NOT_UNDERSTOOD = 12, 64*7c478bd9Sstevel@tonic-gate SLP_RQST_NOT_SUPPORTED = 13 65*7c478bd9Sstevel@tonic-gate } slp_proto_err; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /* Defaults and properties */ 68*7c478bd9Sstevel@tonic-gate #define SLP_VERSION 2 69*7c478bd9Sstevel@tonic-gate #define SLP_DEFAULT_SENDMTU 1400 70*7c478bd9Sstevel@tonic-gate #define SLP_PORT 427 71*7c478bd9Sstevel@tonic-gate #define SLP_DEFAULT_MAXWAIT 15000 72*7c478bd9Sstevel@tonic-gate #define SLP_DEFAULT_MAXRESULTS -1 73*7c478bd9Sstevel@tonic-gate #define SLP_MULTICAST_ADDRESS inet_addr("239.255.255.253") 74*7c478bd9Sstevel@tonic-gate #define SLP_MAX_STRINGLEN USHRT_MAX 75*7c478bd9Sstevel@tonic-gate #define SLP_MAX_MSGLEN 16777216 /* max message length 2^24 */ 76*7c478bd9Sstevel@tonic-gate #define SLP_SUN_SCOPES_TAG "424242SUN-TABLE-SCOPES424242" 77*7c478bd9Sstevel@tonic-gate #define SLP_SUN_VERSION_TAG "424242SUN-TABLE-VERSION424242" 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* Property names */ 80*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_USESCOPES "net.slp.useScopes" 81*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_ISBROADCASTONLY "net.slp.isBroadcastOnly" 82*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_MULTICASTTTL "net.slp.multicastTTL" 83*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_MULTICASTMAXWAIT "net.slp.multicastMaximumWait" 84*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_DATAGRAMTIMEOUTS "net.slp.datagramTimeouts" 85*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_MULTICASTTIMEOUTS "net.slp.multicastTimeouts" 86*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_MTU "net.slp.mtu" 87*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_INTERFACES "net.slp.interfaces" 88*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_LOCALE "net.slp.locale" 89*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_MAXRESULTS "net.slp.maxResults" 90*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_USEGETXXXBYYYY "sun.net.slp.usegetxxxbyyyy" 91*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_TYPEHINT "net.slp.typeHint" 92*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_SECURITY_ON "net.slp.securityEnabled" 93*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_SPI "sun.net.slp.SPIs" 94*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_SIGN_AS "sun.net.slp.signAs" 95*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_BYPASS_AUTH "sun.net.slp.bypassAuth" 96*7c478bd9Sstevel@tonic-gate #define SLP_CONFIG_AUTH_BACKEND "sun.net.slp.authBackend" 97*7c478bd9Sstevel@tonic-gate #define SLP_SUN_DA_TYPE "service:directory-agent.sun" 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate #define SLP_DEFAULT_CONFIG_FILE "/etc/inet/slp.conf" 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate extern void slp_readConfig(void); 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate /* Synchronized queue structures and functions */ 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate typedef void slp_queue_t; 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate extern slp_queue_t *slp_new_queue(SLPError *); 108*7c478bd9Sstevel@tonic-gate extern SLPError slp_enqueue(slp_queue_t *, void *); 109*7c478bd9Sstevel@tonic-gate extern SLPError slp_enqueue_at_head(slp_queue_t *, void *); 110*7c478bd9Sstevel@tonic-gate extern void *slp_dequeue_timed(slp_queue_t *, timestruc_t *, SLPBoolean *); 111*7c478bd9Sstevel@tonic-gate extern void *slp_dequeue(slp_queue_t *); 112*7c478bd9Sstevel@tonic-gate extern void slp_flush_queue(slp_queue_t *, void (*)(void *)); 113*7c478bd9Sstevel@tonic-gate extern void slp_destroy_queue(slp_queue_t *); 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate typedef struct { 116*7c478bd9Sstevel@tonic-gate struct iovec *iov; 117*7c478bd9Sstevel@tonic-gate int iovlen; 118*7c478bd9Sstevel@tonic-gate char *msg; 119*7c478bd9Sstevel@tonic-gate struct iovec prlistlen; 120*7c478bd9Sstevel@tonic-gate struct iovec *prlist; 121*7c478bd9Sstevel@tonic-gate struct iovec scopeslen; 122*7c478bd9Sstevel@tonic-gate struct iovec *scopes; 123*7c478bd9Sstevel@tonic-gate } slp_msg_t; 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate /* Implementation of SLPHandle */ 126*7c478bd9Sstevel@tonic-gate typedef struct handle_impl { 127*7c478bd9Sstevel@tonic-gate const char *locale; /* language tag */ 128*7c478bd9Sstevel@tonic-gate int fid; /* SLP function ID */ 129*7c478bd9Sstevel@tonic-gate slp_msg_t msg; /* The SLP message */ 130*7c478bd9Sstevel@tonic-gate mutex_t *tcp_lock; /* TCP thread wait lock */ 131*7c478bd9Sstevel@tonic-gate int tcp_ref_cnt; /* TCP thread reference count */ 132*7c478bd9Sstevel@tonic-gate cond_t *tcp_wait; /* TCP thread wait condition var */ 133*7c478bd9Sstevel@tonic-gate SLPBoolean async; /* asynchronous flag */ 134*7c478bd9Sstevel@tonic-gate slp_queue_t *q; /* message queue for this handle */ 135*7c478bd9Sstevel@tonic-gate thread_t producer_tid; /* thr ID of message producer */ 136*7c478bd9Sstevel@tonic-gate thread_t consumer_tid; /* thr ID of message consumer */ 137*7c478bd9Sstevel@tonic-gate int cancel; /* cancellation flag */ 138*7c478bd9Sstevel@tonic-gate void *ifinfo; /* interface info */ 139*7c478bd9Sstevel@tonic-gate SLPBoolean force_multicast; /* for SAAdvert solicitations */ 140*7c478bd9Sstevel@tonic-gate SLPBoolean internal_call; /* current call is an internal op */ 141*7c478bd9Sstevel@tonic-gate SLPBoolean pending_outcall; /* is handle in use? */ 142*7c478bd9Sstevel@tonic-gate mutex_t outcall_lock; /* protects pending_outcall */ 143*7c478bd9Sstevel@tonic-gate cond_t outcall_cv; /* outcall cond var */ 144*7c478bd9Sstevel@tonic-gate SLPBoolean close_on_end; /* cleanup on slp_end_call */ 145*7c478bd9Sstevel@tonic-gate } slp_handle_impl_t; 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate extern SLPError slp_start_call(slp_handle_impl_t *); 148*7c478bd9Sstevel@tonic-gate extern void slp_end_call(slp_handle_impl_t *); 149*7c478bd9Sstevel@tonic-gate extern void slp_cleanup_handle(slp_handle_impl_t *); 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate /* UA common functionality */ 152*7c478bd9Sstevel@tonic-gate typedef void SLPGenericAppCB(); 153*7c478bd9Sstevel@tonic-gate typedef SLPBoolean SLPMsgReplyCB(slp_handle_impl_t *, char *, void (*)(), 154*7c478bd9Sstevel@tonic-gate void *, void **, int *); 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate extern SLPError slp_ua_common(SLPHandle, const char *, SLPGenericAppCB, void *, 157*7c478bd9Sstevel@tonic-gate SLPMsgReplyCB); 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate extern SLPError slp_packSrvRqst(const char *, const char *, 160*7c478bd9Sstevel@tonic-gate slp_handle_impl_t *); 161*7c478bd9Sstevel@tonic-gate extern SLPError slp_packSrvRqst_single(const char *, const char *, 162*7c478bd9Sstevel@tonic-gate const char *, char **, 163*7c478bd9Sstevel@tonic-gate const char *); 164*7c478bd9Sstevel@tonic-gate extern SLPBoolean slp_unpackSrvReply(slp_handle_impl_t *, char *, 165*7c478bd9Sstevel@tonic-gate SLPSrvURLCallback, void *, 166*7c478bd9Sstevel@tonic-gate void **, int *); 167*7c478bd9Sstevel@tonic-gate extern SLPError slp_packAttrRqst_single(const char *, 168*7c478bd9Sstevel@tonic-gate const char *, 169*7c478bd9Sstevel@tonic-gate const char *, 170*7c478bd9Sstevel@tonic-gate char **, 171*7c478bd9Sstevel@tonic-gate const char *); 172*7c478bd9Sstevel@tonic-gate extern SLPBoolean slp_UnpackAttrReply(slp_handle_impl_t *, char *, 173*7c478bd9Sstevel@tonic-gate SLPAttrCallback, void *, 174*7c478bd9Sstevel@tonic-gate void **, int *); 175*7c478bd9Sstevel@tonic-gate extern SLPError slp_getDAbyScope(const char *, slp_queue_t *); 176*7c478bd9Sstevel@tonic-gate extern SLPError slp_SAAdvert(slp_handle_impl_t *, void *); 177*7c478bd9Sstevel@tonic-gate extern SLPError slp_unpackDAAdvert(char *, char **, char **, char **, 178*7c478bd9Sstevel@tonic-gate char **, SLPError *); 179*7c478bd9Sstevel@tonic-gate extern SLPError slp_unpackSAAdvert(char *, char **, char **, char **); 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate /* target selection routines */ 182*7c478bd9Sstevel@tonic-gate typedef void slp_target_list_t; 183*7c478bd9Sstevel@tonic-gate typedef void slp_target_t; 184*7c478bd9Sstevel@tonic-gate extern SLPError slp_new_target_list(slp_handle_impl_t *hp, const char *, 185*7c478bd9Sstevel@tonic-gate slp_target_list_t **); 186*7c478bd9Sstevel@tonic-gate extern const char *slp_get_uc_scopes(slp_target_list_t *); 187*7c478bd9Sstevel@tonic-gate extern const char *slp_get_mc_scopes(slp_target_list_t *); 188*7c478bd9Sstevel@tonic-gate extern slp_target_t *slp_next_uc_target(slp_target_list_t *); 189*7c478bd9Sstevel@tonic-gate extern slp_target_t *slp_next_failover(slp_target_t *); 190*7c478bd9Sstevel@tonic-gate extern void *slp_get_target_sin(slp_target_t *); 191*7c478bd9Sstevel@tonic-gate extern void slp_mark_target_used(slp_target_t *); 192*7c478bd9Sstevel@tonic-gate extern void slp_mark_target_failed(slp_target_t *); 193*7c478bd9Sstevel@tonic-gate extern slp_target_t *slp_fabricate_target(void *); 194*7c478bd9Sstevel@tonic-gate extern void slp_free_target(slp_target_t *); 195*7c478bd9Sstevel@tonic-gate extern void slp_destroy_target_list(slp_target_list_t *); 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate /* short-lived DA cache */ 198*7c478bd9Sstevel@tonic-gate extern char *slp_find_das_cached(const char *); 199*7c478bd9Sstevel@tonic-gate extern void slp_put_das_cached(const char *, const char *, unsigned int); 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate /* networking */ 202*7c478bd9Sstevel@tonic-gate extern void slp_uc_tcp_send(slp_handle_impl_t *, slp_target_t *, 203*7c478bd9Sstevel@tonic-gate const char *, SLPBoolean, unsigned short); 204*7c478bd9Sstevel@tonic-gate extern void slp_uc_udp_send(slp_handle_impl_t *, slp_target_t *, 205*7c478bd9Sstevel@tonic-gate const char *); 206*7c478bd9Sstevel@tonic-gate extern void slp_mc_send(slp_handle_impl_t *, const char *); 207*7c478bd9Sstevel@tonic-gate extern void slp_tcp_wait(slp_handle_impl_t *); 208*7c478bd9Sstevel@tonic-gate extern SLPError slp_tcp_read(int, char **); 209*7c478bd9Sstevel@tonic-gate extern char *slp_ntop(char *, int, const void *); 210*7c478bd9Sstevel@tonic-gate extern int slp_pton(const char *, void *); 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate /* IPC */ 213*7c478bd9Sstevel@tonic-gate extern SLPError slp_send2slpd(const char *, char **); 214*7c478bd9Sstevel@tonic-gate extern SLPError slp_send2slpd_iov(struct iovec *, int, char **); 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate /* SLP-style list management */ 217*7c478bd9Sstevel@tonic-gate extern int slp_onlist(const char *, const char *); 218*7c478bd9Sstevel@tonic-gate extern void slp_add2list(const char *, char **, SLPBoolean); 219*7c478bd9Sstevel@tonic-gate extern void slp_list_subtract(const char *, char **); 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate /* searching and storing */ 222*7c478bd9Sstevel@tonic-gate typedef enum { preorder, postorder, endorder, leaf } VISIT; 223*7c478bd9Sstevel@tonic-gate extern void slp_twalk(void *, void (*)(void *, VISIT, int, void *), 224*7c478bd9Sstevel@tonic-gate int, void *); 225*7c478bd9Sstevel@tonic-gate extern void *slp_tsearch(const void *, void **, int (*)()); 226*7c478bd9Sstevel@tonic-gate extern void *slp_tfind(const void *, void *const *, 227*7c478bd9Sstevel@tonic-gate int (*)(const void *, const void *)); 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate /* DA and scope discovery routines */ 230*7c478bd9Sstevel@tonic-gate extern SLPError slp_find_das(const char *, char **); 231*7c478bd9Sstevel@tonic-gate extern SLPError slp_administrative_scopes(char **, SLPBoolean); 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate /* UTF8 routines */ 234*7c478bd9Sstevel@tonic-gate extern char *slp_utf_strchr(const char *, char); 235*7c478bd9Sstevel@tonic-gate extern int slp_strcasecmp(const char *, const char *); 236*7c478bd9Sstevel@tonic-gate 237*7c478bd9Sstevel@tonic-gate /* Error reporting */ 238*7c478bd9Sstevel@tonic-gate extern void slp_err(int, int, char *, char *, ...); 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate /* Mapping from protocol to API error codes */ 241*7c478bd9Sstevel@tonic-gate extern SLPError slp_map_err(unsigned short); 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate /* Security: signing and verifying */ 244*7c478bd9Sstevel@tonic-gate extern SLPError slp_sign(struct iovec *, int, time_t, struct iovec *, int); 245*7c478bd9Sstevel@tonic-gate extern SLPError slp_verify(struct iovec *, int, const char *, 246*7c478bd9Sstevel@tonic-gate size_t, int, size_t *); 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate /* Config convenience wrappers */ 249*7c478bd9Sstevel@tonic-gate extern size_t slp_get_mtu(); 250*7c478bd9Sstevel@tonic-gate extern int slp_get_next_onlist(char **); 251*7c478bd9Sstevel@tonic-gate extern int slp_get_maxResults(); 252*7c478bd9Sstevel@tonic-gate #define slp_get_mcmaxwait() atoi(SLPGetProperty(SLP_CONFIG_MULTICASTMAXWAIT)) 253*7c478bd9Sstevel@tonic-gate #define slp_get_maxresults() atoi(SLPGetProperty(SLP_CONFIG_MAXRESULTS)) 254*7c478bd9Sstevel@tonic-gate #define slp_get_multicastTTL() atoi(SLPGetProperty(SLP_CONFIG_MULTICASTTTL)) 255*7c478bd9Sstevel@tonic-gate #define slp_get_usebroadcast() \ 256*7c478bd9Sstevel@tonic-gate (!strcasecmp(SLPGetProperty(SLP_CONFIG_ISBROADCASTONLY), "true")) 257*7c478bd9Sstevel@tonic-gate #define slp_get_security_on() \ 258*7c478bd9Sstevel@tonic-gate (!strcasecmp(SLPGetProperty(SLP_CONFIG_SECURITY_ON), "true")) 259*7c478bd9Sstevel@tonic-gate #define slp_get_bypass_auth() \ 260*7c478bd9Sstevel@tonic-gate (!strcasecmp(SLPGetProperty(SLP_CONFIG_BYPASS_AUTH), "true")) 261*7c478bd9Sstevel@tonic-gate 262*7c478bd9Sstevel@tonic-gate /* Primitive encoding routines */ 263*7c478bd9Sstevel@tonic-gate extern SLPError slp_add_byte(char *, size_t, int, size_t *); 264*7c478bd9Sstevel@tonic-gate extern SLPError slp_add_sht(char *, size_t, unsigned short, size_t *); 265*7c478bd9Sstevel@tonic-gate extern SLPError slp_add_int32(char *, size_t, unsigned int, size_t *); 266*7c478bd9Sstevel@tonic-gate extern SLPError slp_add_string(char *, size_t, const char *, size_t *); 267*7c478bd9Sstevel@tonic-gate extern SLPError slp_get_byte(const char *, size_t, size_t *, int *); 268*7c478bd9Sstevel@tonic-gate extern SLPError slp_get_sht(const char *, size_t, size_t *, unsigned short *); 269*7c478bd9Sstevel@tonic-gate extern SLPError slp_get_int32(const char *, size_t, size_t *, unsigned int *); 270*7c478bd9Sstevel@tonic-gate extern SLPError slp_get_string(const char *, size_t, size_t *, char **); 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate /* Header generation and handling */ 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate /* OFFSETS to fields in the header */ 275*7c478bd9Sstevel@tonic-gate #define SLP_VER 0 276*7c478bd9Sstevel@tonic-gate #define SLP_FUN 1 277*7c478bd9Sstevel@tonic-gate #define SLP_LEN 2 278*7c478bd9Sstevel@tonic-gate #define SLP_FLAGS 5 279*7c478bd9Sstevel@tonic-gate #define SLP_NEXTOP 7 280*7c478bd9Sstevel@tonic-gate #define SLP_XID 10 281*7c478bd9Sstevel@tonic-gate #define SLP_LANGLEN 12 282*7c478bd9Sstevel@tonic-gate #define SLP_HDRLEN 14 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate /* Flags */ 285*7c478bd9Sstevel@tonic-gate #define SLP_OVERFLOW (char)0x80 286*7c478bd9Sstevel@tonic-gate #define SLP_FRESH (char)0x40 287*7c478bd9Sstevel@tonic-gate #define SLP_MCAST (char)0x20 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate /* One byte macros (not needing byte order conversion) */ 290*7c478bd9Sstevel@tonic-gate #define slp_get_version(h) (h)[SLP_VER] 291*7c478bd9Sstevel@tonic-gate #define slp_set_version(h, v) (h)[SLP_VER] = (v); 292*7c478bd9Sstevel@tonic-gate #define slp_get_function(h) (h)[SLP_FUN] 293*7c478bd9Sstevel@tonic-gate #define slp_set_function(h, f) (h)[SLP_FUN] = (f) 294*7c478bd9Sstevel@tonic-gate #define slp_get_overflow(h) ((h)[SLP_FLAGS] & SLP_OVERFLOW) 295*7c478bd9Sstevel@tonic-gate #define slp_set_overflow(h) (h)[SLP_FLAGS] |= SLP_OVERFLOW 296*7c478bd9Sstevel@tonic-gate #define slp_set_fresh(h) (h)[SLP_FLAGS] |= SLP_FRESH 297*7c478bd9Sstevel@tonic-gate #define slp_set_mcast(h) (h)[SLP_FLAGS] |= SLP_MCAST 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate /* Routines requiring byte order conversions */ 300*7c478bd9Sstevel@tonic-gate extern unsigned short slp_header_get_sht(const char *, size_t); 301*7c478bd9Sstevel@tonic-gate extern void slp_header_set_sht(char *, unsigned short, size_t); 302*7c478bd9Sstevel@tonic-gate extern unsigned int slp_header_get_int24(const char *, size_t); 303*7c478bd9Sstevel@tonic-gate extern void slp_header_set_int24(char *, unsigned int, size_t); 304*7c478bd9Sstevel@tonic-gate extern slp_proto_err slp_get_errcode(char *); 305*7c478bd9Sstevel@tonic-gate #define slp_get_length(h) slp_header_get_int24((h), SLP_LEN) 306*7c478bd9Sstevel@tonic-gate #define slp_set_length(h, x) slp_header_set_int24((h), (int)(x), SLP_LEN) 307*7c478bd9Sstevel@tonic-gate #define slp_get_langlen(h) slp_header_get_sht((h), SLP_LANGLEN) 308*7c478bd9Sstevel@tonic-gate #define slp_set_langlen(h, x) slp_header_set_sht((h), (x), SLP_LANGLEN) 309*7c478bd9Sstevel@tonic-gate #define slp_get_option(h) slp_header_get_int24((h), SLP_NEXTOP) 310*7c478bd9Sstevel@tonic-gate #define slp_set_option(h, x) slp_header_set_int24((h), (x), SLP_NEXTOP) 311*7c478bd9Sstevel@tonic-gate #define slp_get_xid(h) slp_header_get_sht((h), SLP_XID) 312*7c478bd9Sstevel@tonic-gate #define slp_set_xid(h, x) slp_header_set_sht((h), (x), SLP_XID) 313*7c478bd9Sstevel@tonic-gate 314*7c478bd9Sstevel@tonic-gate extern SLPError slp_add_header(const char *, char *, size_t, int, 315*7c478bd9Sstevel@tonic-gate size_t, size_t *); 316*7c478bd9Sstevel@tonic-gate #define slp_hdrlang_length(h) \ 317*7c478bd9Sstevel@tonic-gate (SLP_HDRLEN + strlen(((slp_handle_impl_t *)(h))->locale)) 318*7c478bd9Sstevel@tonic-gate 319*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 320*7c478bd9Sstevel@tonic-gate } 321*7c478bd9Sstevel@tonic-gate #endif 322*7c478bd9Sstevel@tonic-gate 323*7c478bd9Sstevel@tonic-gate #endif /* _SLP_INTERNAL_H */ 324