Annotation of embedaddon/rsync/srvloc.c, revision 1.1.1.1
1.1 misho 1: /* -*- c-file-style: "linux"; -*-
2:
3: Copyright (C) 2002 by Brad Hards <bradh@frogmouth.net>
4:
5: This program is free software; you can redistribute it and/or modify
6: it under the terms of the GNU General Public License as published by
7: the Free Software Foundation; either version 2 of the License, or
8: (at your option) any later version.
9:
10: This program is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: GNU General Public License for more details.
14:
15: You should have received a copy of the GNU General Public License
16: along with this program; if not, write to the Free Software
17: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18: */
19:
20: /* This file implements the service location functionality */
21: /* Basically, it uses normal Service Location Protocol API */
22:
23: /* It is really a cheap hack - just to show how it might work
24: in a real application.
25: */
26:
27: #include "rsync.h"
28:
29: #include <slp.h>
30: #include <stdio.h>
31: #include <string.h>
32:
33: /* This one just prints out the attributes */
34: static SLPBoolean getAttrCallback(UNUSED(SLPHandle hslp), const char *attrlist,
35: SLPError errcode, UNUSED(void *cookie))
36: {
37: char *cleanstr;
38:
39: if (errcode == SLP_OK) {
40: if (!strcmp(attrlist, "(comment=)"))
41: rprintf(FINFO, "\t(No description)\n");
42: else {
43: cleanstr = strrchr(attrlist, ')') ;
44: *cleanstr = ' '; /* remove last ')' */
45: rprintf(FINFO, "\t%s\n", strchr(attrlist, '=') + 1);
46: }
47: }
48: return SLP_FALSE;
49: }
50:
51: static SLPBoolean getSLPSrvURLCallback(UNUSED(SLPHandle hslp),
52: const char *srvurl, UNUSED(unsigned short lifetime),
53: SLPError errcode, void *cookie)
54: {
55: SLPError result;
56: SLPHandle attrhslp;
57:
58: if (errcode == SLP_OK) {
59: /* chop service: off the front */
60: rprintf(FINFO, " %s ", (strchr(srvurl, ':') + 1));
61: /* check for any attributes */
62: if (SLPOpen("en", SLP_FALSE,&attrhslp) == SLP_OK) {
63: result = SLPFindAttrs(attrhslp, srvurl,
64: "", /* return all attributes */
65: "", /* use configured scopes */
66: getAttrCallback, NULL);
67: if (result != SLP_OK) {
68: rprintf(FERROR, "errorcode: %i\n",result);
69: }
70: SLPClose(attrhslp);
71: }
72: *(SLPError*)cookie = SLP_OK;
73: } else
74: *(SLPError*)cookie = errcode;
75:
76: /* Return SLP_TRUE because we want to be called again
77: * if more services were found. */
78:
79: return SLP_TRUE;
80: }
81:
82: int print_service_list(void)
83: {
84: SLPError err;
85: SLPError callbackerr;
86: SLPHandle hslp;
87:
88: err = SLPOpen("en",SLP_FALSE,&hslp);
89: if (err != SLP_OK) {
90: rprintf(FERROR, "Error opening slp handle %i\n", err);
91: return err;
92: }
93:
94: SLPFindSrvs(hslp, "rsync",
95: 0, /* use configured scopes */
96: 0, /* no attr filter */
97: getSLPSrvURLCallback, &callbackerr);
98:
99: /* Now that we're done using slp, close the slp handle */
100: SLPClose(hslp);
101:
102: return 0;
103: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>