5
gSOAP HTTP Digest Authentication example application.
7
gSOAP XML Web services tools
8
Copyright (C) 2000-2005, Robert van Engelen, Genivia, Inc., All Rights Reserved.
10
--------------------------------------------------------------------------------
13
The contents of this file are subject to the gSOAP Public License Version 1.3
14
(the "License"); you may not use this file except in compliance with the
15
License. You may obtain a copy of the License at
16
http://www.cs.fsu.edu/~engelen/soaplicense.html
17
Software distributed under the License is distributed on an "AS IS" basis,
18
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
19
for the specific language governing rights and limitations under the License.
21
The Initial Developer of the Original Code is Robert A. van Engelen.
22
Copyright (C) 2000-2005, Robert van Engelen, Genivia, Inc., All Rights Reserved.
23
--------------------------------------------------------------------------------
26
This program is free software; you can redistribute it and/or modify it under
27
the terms of the GNU General Public License as published by the Free Software
28
Foundation; either version 2 of the License, or (at your option) any later
31
This program is distributed in the hope that it will be useful, but WITHOUT ANY
32
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
33
PARTICULAR PURPOSE. See the GNU General Public License for more details.
35
You should have received a copy of the GNU General Public License along with
36
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
37
Place, Suite 330, Boston, MA 02111-1307 USA
39
Author contact information:
40
engelen@genivia.com / engelen@acm.org
41
--------------------------------------------------------------------------------
47
soapcpp2 -c httpdatest.h
48
cc -DWITH_OPENSSL -o httpdatest httpdatest.c soapC.c soapClient.c soapServer.c httpda.c md5evp.c threads.c stdsoap2.c -lssl -lcrypto -lz
56
static char authrealm[] = "gSOAP Authentication Test";
58
int run_serve(int port);
59
int run_tests(int,char**);
61
int main(int argc, char **argv)
64
return run_serve(8080);
66
return run_serve(atoi(argv[1]));
68
return run_tests(argc, argv);
71
int run_serve(int port)
73
struct soap *soap = soap_new();
75
soap_register_plugin(soap, http_da);
76
if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
77
soap_print_fault(soap, stderr);
80
fprintf(stderr, "Bind to port %d successful\n", port);
81
soap->accept_timeout = 3600; /* let server time out after one hour */
84
int sock = soap_accept(soap);
85
if (!soap_valid_socket(sock))
88
soap_print_fault(soap, stderr);
91
fprintf(stderr, "Server timed out\n");
95
fprintf(stderr, "Accepting socket %d connection from IP %d.%d.%d.%d\n", sock, (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF);
97
soap_print_fault(soap, stderr);
98
fprintf(stderr, "Served\n\n");
110
int run_tests(int argc, char **argv)
112
struct soap *soap = soap_new();
113
struct ns__echoString r;
114
char *endpoint, *arg;
117
soap_register_plugin(soap, http_da);
122
if (soap_call_ns__echoString(soap, endpoint, NULL, arg, &r))
124
if (soap->error == 401)
126
if (!strcmp(soap->authrealm, authrealm))
128
/* save userid and passwd for basic or digest authentication */
129
struct http_da_info info;
130
http_da_save(soap, &info, authrealm, "Mufasa", "Circle Of Life");
131
if (!soap_call_ns__echoString(soap, endpoint, NULL, arg, &r))
134
/* need to restore for authentication */
135
http_da_restore(soap, &info);
136
if (!soap_call_ns__echoString(soap, endpoint, NULL, arg, &r))
138
if (!strcmp(arg, r.arg))
139
printf("EchoString test OK\n");
141
printf("Transmission error\n");
144
http_da_release(soap, &info);
145
/* regular calls may follow */
150
soap_print_fault(soap, stderr);
158
int ns__echoString(struct soap *soap, char *arg, struct ns__echoString *response)
160
if (soap->userid && soap->passwd) /* Basic authentication: we may want to reject this since the password was send in the clear */
161
{ if (!strcmp(soap->userid, "Mufasa")
162
&& !strcmp(soap->passwd, "Circle Of Life"))
168
else if (soap->authrealm && soap->userid)
170
/* simulate database lookup on userid to find passwd */
171
if (!strcmp(soap->authrealm, authrealm) && !strcmp(soap->userid, "Mufasa"))
173
char *passwd = "Circle Of Life";
175
if (!http_da_verify_post(soap, passwd))
182
soap->authrealm = authrealm;
183
return 401; /* Not authorized, challenge digest authentication with httpda plugin */