File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / rsync / srvloc.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:32:36 2021 UTC (3 years, 7 months ago) by misho
Branches: rsync, MAIN
CVS tags: v3_2_3, HEAD
rsync 3.2.3

/* -*- c-file-style: "linux"; -*-

   Copyright (C) 2002 by Brad Hards <bradh@frogmouth.net>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/* This file implements the service location functionality */
/* Basically, it uses normal Service Location Protocol API */

/* It is really a cheap hack - just to show how it might work
   in a real application.
*/

#include "rsync.h"

#include <slp.h>
#include <stdio.h>
#include <string.h>

/* This one just prints out the attributes */
static SLPBoolean getAttrCallback(UNUSED(SLPHandle hslp), const char *attrlist,
				  SLPError errcode, UNUSED(void *cookie))
{
	char *cleanstr;

	if (errcode == SLP_OK) {
		if (!strcmp(attrlist, "(comment=)"))
			rprintf(FINFO, "\t(No description)\n");
		else {
			cleanstr = strrchr(attrlist, ')') ;
			*cleanstr = ' '; /* remove last ')' */
			rprintf(FINFO, "\t%s\n", strchr(attrlist, '=') + 1);
		}
	}
	return SLP_FALSE;
}

static SLPBoolean getSLPSrvURLCallback(UNUSED(SLPHandle hslp),
			const char *srvurl, UNUSED(unsigned short lifetime),
			SLPError errcode, void *cookie)
{
	SLPError    result;
	SLPHandle   attrhslp;

	if (errcode == SLP_OK) {
		/* chop service: off the front */
		rprintf(FINFO, "  %s  ", (strchr(srvurl, ':') + 1));
		/* check for any attributes */
		if (SLPOpen("en", SLP_FALSE,&attrhslp) == SLP_OK) {
			result = SLPFindAttrs(attrhslp, srvurl,
					      "", /* return all attributes */
					      "", /* use configured scopes */
					      getAttrCallback, NULL);
			if (result != SLP_OK) {
				rprintf(FERROR, "errorcode: %i\n",result);
			}
			SLPClose(attrhslp);
		}
		*(SLPError*)cookie = SLP_OK;
	} else
		*(SLPError*)cookie = errcode;

	/* Return SLP_TRUE because we want to be called again
	 * if more services were found. */

	return SLP_TRUE;
}

int print_service_list(void)
{
	SLPError err;
	SLPError callbackerr;
	SLPHandle hslp;

	err = SLPOpen("en",SLP_FALSE,&hslp);
	if (err != SLP_OK) {
		rprintf(FERROR, "Error opening slp handle %i\n", err);
		return err;
	}

	SLPFindSrvs(hslp, "rsync",
		    0, /* use configured scopes */
		    0, /* no attr filter        */
		    getSLPSrvURLCallback, &callbackerr);

	/* Now that we're done using slp, close the slp handle */
	SLPClose(hslp);

	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>