2N/A/*
2N/A * CDDL HEADER START
2N/A *
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 * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
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 *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1999 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * Implements SLPGetRefreshInterval. This call is an AttrRqst with
2N/A * the special service type service:directory-agent.sun, sent
2N/A * only to slpd via loopback, so it mimics the course of a normal
2N/A * SLPFindAttrs call but reroutes the message to slpd.
2N/A */
2N/A
2N/A#include <stdlib.h>
2N/A#include <unistd.h>
2N/A#include <syslog.h>
2N/A#include <netdb.h>
2N/A#include <slp-internal.h>
2N/A
2N/Astatic SLPBoolean refresh_interval_cb(SLPHandle, const char *,
2N/A SLPError, void *);
2N/A
2N/Aunsigned short SLPGetRefreshInterval() {
2N/A slp_handle_impl_t *hp; /* SLP handle for this request */
2N/A SLPError err; /* any SLPError */
2N/A char *reply = NULL; /* reply from slpd */
2N/A void *collator = NULL; /* attr collation handle */
2N/A int mr = 0; /* max results placeholder */
2N/A unsigned short max = 0; /* max interval result cookie */
2N/A char *msg = NULL; /* attrrqst msg */
2N/A char hostname[MAXHOSTNAMELEN]; /* name of this host */
2N/A
2N/A if ((err = SLPOpen("en", SLP_FALSE, (void **)&hp)) != SLP_OK) {
2N/A slp_err(LOG_INFO, 0, "SLPGetRefreshInterval",
2N/A "Could not get SLPHandle: %s", slp_strerror(err));
2N/A return (0);
2N/A }
2N/A
2N/A /* tag this as an internal call */
2N/A hp->internal_call = SLP_TRUE;
2N/A
2N/A /* scope is name of this host */
2N/A (void) gethostname(hostname, MAXHOSTNAMELEN);
2N/A
2N/A if (slp_packAttrRqst_single(SLP_SUN_DA_TYPE,
2N/A hostname,
2N/A "min-refresh-interval",
2N/A &msg, "en") != SLP_OK) {
2N/A goto done;
2N/A }
2N/A
2N/A if (slp_send2slpd(msg, &reply) != SLP_OK) {
2N/A goto done;
2N/A }
2N/A
2N/A (void) slp_UnpackAttrReply(hp, reply, refresh_interval_cb,
2N/A &max, &collator, &mr);
2N/A
2N/A /* clean up by invoking last call */
2N/A (void) slp_UnpackAttrReply(hp, NULL, refresh_interval_cb,
2N/A &max, &collator, &mr);
2N/A
2N/Adone:
2N/A if (msg) free(msg);
2N/A if (reply) free(reply);
2N/A
2N/A SLPClose(hp);
2N/A
2N/A return (max);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Astatic SLPBoolean refresh_interval_cb(SLPHandle h, const char *attrs,
2N/A SLPError err, void *cookie) {
2N/A char *p, *next;
2N/A unsigned short *max = (unsigned short *)cookie;
2N/A
2N/A if (err != SLP_OK) {
2N/A return (SLP_TRUE);
2N/A }
2N/A
2N/A p = strchr(attrs, '=');
2N/A if (!p) {
2N/A *max = 0;
2N/A }
2N/A
2N/A /* walk through all intervals, looking for the greatest */
2N/A for (p++; p; p = next) {
2N/A unsigned short anint;
2N/A
2N/A next = strchr(p, ',');
2N/A if (next) {
2N/A *next++ = 0;
2N/A }
2N/A
2N/A anint = (unsigned short)atoi(p);
2N/A if (anint > *max) {
2N/A *max = anint;
2N/A }
2N/A }
2N/A
2N/A return (SLP_TRUE);
2N/A}