2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License, Version 1.0 only 2N/A * (the "License"). You may not use this file except in compliance 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * This file contains all functions pertaining to registrations: 2N/A * Each function talks only to the local slpd, and receives a SrvAck 2N/A * These calls can operate in sync or async mode. Sync mode operates 2N/A * format params into a char *msg 2N/A * send this msg to slpd 2N/A * invoke the SLPRegReport callback with the error code found in the 2N/A * Async mode operates as follows: 2N/A * format the params into a char *msg 2N/A * there is one thread per process which handles async regs 2N/A * make sure this thread is running 2N/A * the reg_thread monitors the global static reg_q for messages 2N/A * a queue message is represented as a struct reg_q_msg 2N/A * caller thread places the reg msg on the reg_q, and returns 2N/A * the reg_thread reads the message from the reg_q, and sends the 2N/A * the reg_thread then invokes the SLPRegReport callback with the error 2N/A * code found in the reply from slpd 2N/A * once started, the reg_thread manages registration refreshing. 2N/A * If there are no registrations to refresh, the thread exits. 2N/A/* Indices into a reg_msg iovec for auth blocks */ 2N/A/* A registration / de-registration message */ 2N/A int urlauth;
/* index into authiov for URL auth blocks */ 2N/A int attrauth;
/* index into authiov for attr auth blocks */ 2N/A * This is the message bundle passed to the reg thread via a queue. 2N/A * These structures and vars are used for automatic re-registering. 2N/A/* Private Utility Routines */ 2N/A unsigned short,
const char *,
const char *,
2N/A/* Public API SA functionality */ 2N/A /* format params into msg */ 2N/A /* create a rereg message, with no attrs */ 2N/A /* calculate the timestamp */ 2N/A /* create the reg_msg */ 2N/A /* compute the total messge length */ 2N/A * Allocate memory for all the message except the auth blocks. 2N/A * The iovec msgiov actually contains only pointers into this 2N/A * Create iovec for the msg. The iovec components are layed out thus: 2N/A * 1: URL auth block count, URL auth block 2N/A * 3: attrs auth block count, attr auth block 2N/A /* set fresh flag */ 2N/A len++;
/* skip reserved byte in URL entry */ 2N/A /* save pointer to URL for signing */ 2N/A /* add auth blocks for URL */ 2N/A /* type, scopes, and attrs */ 2N/A /* save pointer to attr for signing */ 2N/A /* length of 2nd portion is len - length of 1st portion */ 2N/A /* add auth blocks for attrs */ 2N/A /* adjust msgLen with authblocks, and set header length */ 2N/A /* make sure msgLen is valid */ 2N/A /* format params into msg */ 2N/A /* format params into msg */ 2N/A /* create the reg_msg */ 2N/A /* compute the total message length */ 2N/A * Create iovec for the msg. The iovec components are layed out thus: 2N/A * 1: URL auth block count, URL auth block 2N/A len++;
/* skip reserved byte in URL entry */ 2N/A /* save pointer to URL for signing */ 2N/A /* add auth blocks for URL */ 2N/A /* length of 2nd portion is len - length of 1st portion */ 2N/A /* adjust msgLen with authblocks, and set header length */ 2N/A /* make sure msgLen is valid */ 2N/A * Passes the packed message to the routines which talk to slpd. 2N/A /* If an error occurred, end_call() will not have happened */ 2N/A * Put a reg message on the queue. Assumes reg_thread is running. 2N/A * Create a new reg_q and start the reg thread. 2N/A /* make sure someone else hasn't already intialized the thread */ 2N/A /* create the reg queue */ 2N/A /* start the reg thread */ 2N/A "could not start thread: %s",
2N/A * This is what the permanent reg thread runs; it just sits in a loop 2N/A * monitoring the reg_q for new reg messages. 2N/A * To conserve resources, 2N/A * if there are no more registrations to refresh, it will exit. 2N/A /* get the next message from the queue */ 2N/A /* no more reregs; shut down this thread */ 2N/A /* got a new message */ 2N/A * 'reply' should point to the beginning of the header. 2N/A * The dispatcher for SA messages. Sends a message to slpd, unpacks and 2N/A * dispatches the reply to the user callback. 2N/A /* through with msg, so free it now */ 2N/A /* the reg thread doubles as the consumer thread for SA calls */ 2N/A * Re-registration routines 2N/A * Adds the registration contained in 'msg' to the refresh registration 2N/A * list managed by reg_thread. 2N/A * Only registrations which are meant to be permanent are refreshed, 2N/A * so we only allow reg's with lifetime == SLP_LIFETIME_PERMANENT into 2N/A /* alloc a new rereg entry */ 2N/A /* adjust the next wake time if necessary */ 2N/A /* add the rereg to the list */ 2N/A /* else add it to the beginning of the list */ 2N/A * Walks through the rereg list and re-registers any which will expire 2N/A * before the reg thread wakes up and checks again. 2N/A * Returns true if there are more reregs on the list, false if none. 2N/A /* rereg it, first recalculating signature */ 2N/A * Removes the refresh registration for 'url'. 2N/A /* found it; remove it from the list */ 2N/A /* first one on list */ 2N/A /* free the entry */ 2N/A /* free the message memory */ 2N/A /* free the URL auth block */ 2N/A /* free the attr auth block */ 2N/A /* free the message iovec */ 2N/A /* finally, free the message structure */ 2N/A * Returns configured scopes in scopes. Caller should free *scopes 2N/A * when done. If the scope string is too long for an SLP string, the 2N/A * string is truncated. 2N/A /* Ensure string is not too long */ 2N/A /* truncate the string */ 2N/A /* scopes can't end with ',' */ 2N/A * Does all the dirty work of freeing a msgiov. 2N/A /* free the message memory */ 2N/A /* free the URL auth block */ 2N/A /* free the attr auth block */ 2N/A /* free the message iovec */