1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * Implements SLPGetRefreshInterval. This call is an AttrRqst with 31*0Sstevel@tonic-gate * the special service type service:directory-agent.sun, sent 32*0Sstevel@tonic-gate * only to slpd via loopback, so it mimics the course of a normal 33*0Sstevel@tonic-gate * SLPFindAttrs call but reroutes the message to slpd. 34*0Sstevel@tonic-gate */ 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #include <stdlib.h> 37*0Sstevel@tonic-gate #include <unistd.h> 38*0Sstevel@tonic-gate #include <syslog.h> 39*0Sstevel@tonic-gate #include <netdb.h> 40*0Sstevel@tonic-gate #include <slp-internal.h> 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate static SLPBoolean refresh_interval_cb(SLPHandle, const char *, 43*0Sstevel@tonic-gate SLPError, void *); 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate unsigned short SLPGetRefreshInterval() { 46*0Sstevel@tonic-gate slp_handle_impl_t *hp; /* SLP handle for this request */ 47*0Sstevel@tonic-gate SLPError err; /* any SLPError */ 48*0Sstevel@tonic-gate char *reply = NULL; /* reply from slpd */ 49*0Sstevel@tonic-gate void *collator = NULL; /* attr collation handle */ 50*0Sstevel@tonic-gate int mr = 0; /* max results placeholder */ 51*0Sstevel@tonic-gate unsigned short max = 0; /* max interval result cookie */ 52*0Sstevel@tonic-gate char *msg = NULL; /* attrrqst msg */ 53*0Sstevel@tonic-gate char hostname[MAXHOSTNAMELEN]; /* name of this host */ 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate if ((err = SLPOpen("en", SLP_FALSE, (void **)&hp)) != SLP_OK) { 56*0Sstevel@tonic-gate slp_err(LOG_INFO, 0, "SLPGetRefreshInterval", 57*0Sstevel@tonic-gate "Could not get SLPHandle: %s", slp_strerror(err)); 58*0Sstevel@tonic-gate return (0); 59*0Sstevel@tonic-gate } 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate /* tag this as an internal call */ 62*0Sstevel@tonic-gate hp->internal_call = SLP_TRUE; 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate /* scope is name of this host */ 65*0Sstevel@tonic-gate (void) gethostname(hostname, MAXHOSTNAMELEN); 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate if (slp_packAttrRqst_single(SLP_SUN_DA_TYPE, 68*0Sstevel@tonic-gate hostname, 69*0Sstevel@tonic-gate "min-refresh-interval", 70*0Sstevel@tonic-gate &msg, "en") != SLP_OK) { 71*0Sstevel@tonic-gate goto done; 72*0Sstevel@tonic-gate } 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate if (slp_send2slpd(msg, &reply) != SLP_OK) { 75*0Sstevel@tonic-gate goto done; 76*0Sstevel@tonic-gate } 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate (void) slp_UnpackAttrReply(hp, reply, refresh_interval_cb, 79*0Sstevel@tonic-gate &max, &collator, &mr); 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate /* clean up by invoking last call */ 82*0Sstevel@tonic-gate (void) slp_UnpackAttrReply(hp, NULL, refresh_interval_cb, 83*0Sstevel@tonic-gate &max, &collator, &mr); 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate done: 86*0Sstevel@tonic-gate if (msg) free(msg); 87*0Sstevel@tonic-gate if (reply) free(reply); 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate SLPClose(hp); 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate return (max); 92*0Sstevel@tonic-gate } 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate /*ARGSUSED*/ 95*0Sstevel@tonic-gate static SLPBoolean refresh_interval_cb(SLPHandle h, const char *attrs, 96*0Sstevel@tonic-gate SLPError err, void *cookie) { 97*0Sstevel@tonic-gate char *p, *next; 98*0Sstevel@tonic-gate unsigned short *max = (unsigned short *)cookie; 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate if (err != SLP_OK) { 101*0Sstevel@tonic-gate return (SLP_TRUE); 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate p = strchr(attrs, '='); 105*0Sstevel@tonic-gate if (!p) { 106*0Sstevel@tonic-gate *max = 0; 107*0Sstevel@tonic-gate } 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate /* walk through all intervals, looking for the greatest */ 110*0Sstevel@tonic-gate for (p++; p; p = next) { 111*0Sstevel@tonic-gate unsigned short anint; 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate next = strchr(p, ','); 114*0Sstevel@tonic-gate if (next) { 115*0Sstevel@tonic-gate *next++ = 0; 116*0Sstevel@tonic-gate } 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate anint = (unsigned short)atoi(p); 119*0Sstevel@tonic-gate if (anint > *max) { 120*0Sstevel@tonic-gate *max = anint; 121*0Sstevel@tonic-gate } 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate return (SLP_TRUE); 125*0Sstevel@tonic-gate } 126