/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Miscellaneous Utilities
*
* slp_err: Error and information message dispatch, i18n'd
* slp_start_call: Marks a SLP handle as in-use
* slp_end_call: Marks a SLP handle as available
* slp_map_err: protocol to API error mapping
* slp_onlist: determines if a token is on a list
* slp_add2list: adds a token to a list
* slp_list_subtract: removes a token from a list
* slp_add_header: creates a SLP message header
* slp_get_length: gets the length field from a SLP header
* slp_set_length: sets the length field in a SLP header
* slp_header_get_sht: gets a 16 bit integer from a SLP header
* slp_header_set_sht: sets a 16 bit interger in a SLP header
* slp_header_length: calculates the length of a header, including the
* language tag
* slp_get_errcode: returns the error code from a SLP message
* slp_add_byte: encodes a byte into the given buffer
* slp_add_sht: encodes a 16-bit integer into the given buffer
* slp_add_string: encodes the given string into the given buffer
* slp_get_byte: decodes a byte from the given buffer
* slp_get_sht: decodes a 16-bit integer from the given buffer
* slp_get_string: decodes a string from the given buffer
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <syslog.h>
#include <string.h>
#include <thread.h>
#include <synch.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <libintl.h>
#include <slp-internal.h>
/*
* Outputs an error message. priority is a syslog(3) priority.
*/
/*ARGSUSED1*/
/* PRINTFLIKE4 */
char *p, *msg;
(void) mutex_lock(&loglock);
/* i18n mapping */
(void) mutex_unlock(&loglock);
}
/*
* Start and end slp calls
* slp_start_call returns SLP_HANDLE_IN_USE if the handle is already
* being used, otherwise SLP_OK.
*/
if (hp->pending_outcall) {
return (SLP_HANDLE_IN_USE);
}
return (SLP_OK);
}
if (hp->close_on_end) {
/* SLPClose() called from callback */
return;
}
}
/*
* Map a protocol error code to an API error code.
*/
switch (proto_err) {
case 0: return (SLP_OK);
case 1: return (SLP_LANGUAGE_NOT_SUPPORTED);
case 2: return (SLP_PARSE_ERROR);
case 3: return (SLP_INVALID_REGISTRATION);
case 4: return (SLP_SCOPE_NOT_SUPPORTED);
case 6: return (SLP_AUTHENTICATION_ABSENT);
case 7: return (SLP_AUTHENTICATION_FAILED);
case 13: return (SLP_INVALID_UPDATE);
/*
* 9 (VER_NOT_SUPPORTED), 10 (INTERNAL_ERROR),
* 11 (DA_BUSY_NOW), 12 (OPTION_NOT_UNDERSTOOD),
* and 14 (RQST_NOT_SUPPORTED)
* should be handled internally by the API.
*/
default: return (SLP_INTERNAL_SYSTEM_ERROR);
}
}
/*
* SLP List Management:
* SLP lists are comma separated lists of tokens. The following routines
* manage SLP lists, ensuring proper UTF-8 parsing.
*/
/*
* If 'item' is on 'list', returns 1, otherwise 0.
*/
char *p;
for (p = (char *)list; p; p++) {
char *s;
s = p;
p = slp_utf_strchr(p, ',');
if (!p)
break;
else
continue;
}
return (1);
if (!p)
break;
}
return (0);
}
/*
* Adds item to *list if it is not already on it. If *list == NULL,
* creates a new list. When it grows the list, it will free *list,
* so *list must not be on the caller's stack. 'check_onlist' specifies
* whether to look to item on the current list. This is a small
* optimization for callers which are that item is not on *list, or
* which don't care about duplicates.
*/
if (!(*list)) {
return;
}
if (check_onlist)
/* no duplicates */
return;
return;
}
}
/*
* Removes the first instance of item from *list.
* When it shrinks the list, it may free *list, so *list must not be on
* the caller's stack.
*/
char *p, *s;
return;
/* find item's location on the list */
for (p = *list; p; p++) {
s = p;
p = slp_utf_strchr(p, ',');
continue;
break;
if (!p)
break;
}
if (!p && s == *list) {
/* item is only one on list */
return;
}
if (!p) {
/* last one on list; just chop it off */
s--;
*s = 0;
return;
}
/* either first on list, or somewhere in the middle */
(void) strcpy(s, p + 1);
}
/* SLPv2 header management */
/*
* Lays a SLP header into pcSendBuf, performing byte-ordering and bounds
* checking where necessary.
* pcLangTag: Language tag
* pcSendBuf: a buffer into which to write the composed header
* iSendBufSz: the size of pcSendBuf in bytes
* iFun: SLP V2 function number
* iLen: The length of the whole SLP message, in bytes
* piLen: a pointer to an int into which will be written the size of the
* header + the language tag (i.e. the offset at which the rest of
* the message should be written into pcSendBuf).
*/
static unsigned short xid_seeded = 0;
if (!xid_seeded) {
(void) mutex_lock(&lock);
if (!xid_seeded) {
/* generate a seed based on our PID */
xid_seeded = 1;
}
(void) mutex_unlock(&lock);
}
/* squish the random value into an unsigned short */
return (SLP_PARAMETER_BAD);
return (SLP_OK);
}
/*
* Retrieves the 24 bit int stored at 'off' offset into 'header'.
* Assumes 'header' is a valid SLP message header.
*/
unsigned int len;
return (len);
}
/*
* Sets a 24 bit int at the location in 'header' 'off' bytes
* offset into the header.
* Assumes 'header' is a valid SLP message header.
*/
}
/*
* Retrieves the 16 bit integer stored at 'off' offset into 'header'.
* Assumes 'header' is a valid SLP message header.
*/
unsigned short answer = 0;
return (answer);
}
/*
* Sets a 16 bit interger at the location in 'header' 'off' bytes
* offset into the header.
* Assumes 'header' is a valid SLP message header.
*/
}
/*
* Returns the total length of a SLP header associated with the SLP
* handle 'hp', including the language tag.
*/
}
/*
* Retrieves the error code for UA replies -- the errcode is always
* the first short after the header for these functions. 'msg' points to
* the beginning of a SLP header.
*/
/* make sure the reply is long enough */
return (SLP_MSG_PARSE_ERROR);
return (SLP_MSG_PARSE_ERROR);
return (errcode);
}
/*
* Primitive Encoding and Decoding Routines.
* All perform byte-ordering coversions and bounds checking.
*/
return (SLP_PARAMETER_BAD);
return (SLP_OK);
}
return (SLP_PARAMETER_BAD);
return (SLP_OK);
}
return (SLP_PARAMETER_BAD);
return (SLP_OK);
}
/* SLP strings are limited to 16-bit len */
return (SLP_PARAMETER_BAD);
return (SLP_PARAMETER_BAD);
!= SLP_OK)
return (err);
return (SLP_OK);
}
return (SLP_PARSE_ERROR);
*piOffset += 1;
}
return (SLP_OK);
}
return (SLP_PARSE_ERROR);
*piOffset += 2;
}
*piSht = (unsigned short)
*piSht <<= 8;
*piSht += (unsigned short)
return (SLP_OK);
}
return (SLP_PARSE_ERROR);
*piOffset += 4;
}
return (SLP_OK);
}
unsigned short iLen;
if (err)
return (err);
return (SLP_PARSE_ERROR);
return (SLP_MEMORY_ALLOC_FAILED);
}
return (SLP_OK);
}