1 /*-------------------------------------------------------------------------
2 * Copyright (C) 2000 Caldera Systems, Inc
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Caldera Systems nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALDERA
24 * SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *-------------------------------------------------------------------------*/
32
33 /** Test for SLPDereg.
34 *
35 * @file SLPDereg.c
36 * @date Wed May 24 14:26:50 EDT 2000
37 * @author Matthew Peterson, John Calcote (jcalcote@novell.com)
38 * @attention Please submit patches to http://www.openslp.org
39 * @ingroup TestCode
40 */
41
42 #include <slp.h>
43 #include <slp_debug.h>
44 #include <string.h>
45
MySLPRegReport(SLPHandle hslp,SLPError errcode,void * cookie)46 void MySLPRegReport(SLPHandle hslp, SLPError errcode, void * cookie)
47 {
48 (void)hslp;
49 *(SLPError *)cookie = errcode; /* return the error code in the cookie */
50 }
51
MySLPSrvURLCallback(SLPHandle hslp,const char * srvurl,unsigned short lifetime,SLPError errcode,void * cookie)52 SLPBoolean MySLPSrvURLCallback(SLPHandle hslp, const char * srvurl,
53 unsigned short lifetime, SLPError errcode, void * cookie)
54 {
55 (void)hslp;
56 (void)lifetime;
57
58 switch (errcode)
59 {
60 case SLP_OK:
61 printf("Service Found = %s\n", srvurl);
62 *(SLPError *)cookie = SLP_OK;
63 break;
64
65 case SLP_LAST_CALL:
66 break;
67
68 default:
69 *(SLPError *)cookie = errcode;
70 break;
71 }
72
73 /* return SLP_TRUE because we want to be called again
74 * if more services were found
75 */
76 return SLP_TRUE;
77 }
78
main(int argc,char * argv[])79 int main(int argc, char * argv[])
80 {
81 /* This test works by:
82 * 1. Register a service.
83 * 2. Query the service to make sure it is there.
84 * 3. Remove the service.
85 * 4. Query the service to ensure it is not there.
86 */
87 SLPError err;
88 SLPError callbackerr;
89 SLPHandle hslp;
90 char reg_string[4096];
91 char dereg_string[4096];
92
93 if ((argc != 3) && (argc != 5))
94 {
95 printf("SLPDereg\n This test the SLP de-registration.\n"
96 " Usage:\n SLPDereg\n <service name to register>\n"
97 " <service address>\n <service to deregister>\n"
98 " <service deregistration address>\n SLPDereg\n"
99 " <service to deregister>\n");
100 return 0;
101 }
102
103 err = SLPOpen("en", SLP_FALSE, &hslp);
104 check_error_state(err, "Error opening slp handle.");
105
106 /* Register a service with SLP */
107 if (argc == 5)
108 {
109 sprintf(reg_string, "%s://%s", argv[1], argv[2]);
110 printf("Registering = %s\n", reg_string);
111 err = SLPReg(hslp, reg_string, SLP_LIFETIME_MAXIMUM, "", "", SLP_TRUE,
112 MySLPRegReport, &callbackerr);
113 check_error_state(err, "Error registering service with slp");
114 printf("Srv. Registered = %s\n", reg_string);
115 }
116
117 /* Now make sure that the service is there. */
118 printf("Querying = %s\n", (argc == 5) ? argv[3] : argv[1]);
119 err = SLPFindSrvs(hslp, (argc == 5) ? argv[3] : argv[1], "",
120 /* use configured scopes */
121 "", /* no attr filter */
122 MySLPSrvURLCallback, &callbackerr);
123 check_error_state(err, "Error registering service with slp.");
124
125 /* Deregister the service. */
126 if (argc == 5)
127 sprintf(dereg_string, "%s://%s", argv[3], argv[4]);
128 else
129 sprintf(dereg_string, "%s://%s", argv[1], argv[2]);
130
131 printf("Deregistering = %s\n", dereg_string);
132 err = SLPDereg(hslp, dereg_string, MySLPRegReport, &callbackerr);
133 check_error_state(err, "Error deregistering service with slp.");
134 printf("Deregistered = %s\n", dereg_string);
135
136 /* Now that we're done using slp, close the slp handle */
137 SLPClose(hslp);
138
139 return 0;
140 }
141
142 /*=========================================================================*/
143