// Server.cpp : Defines the entry point for the console application. // #include "soapH.h" #include "ns.nsmap" int main(int argc, char **argv) { int m, s; // master and slave sockets struct soap soap; soap_init(&soap); bool CGIapp = false; if(CGIapp) { // serve as CGI application soap_serve(&soap); } else { // bind (TCP Port: 44444) m = soap_bind(&soap, NULL, atoi("44444"), 100); if (m < 0) { soap_print_fault(&soap, stderr); exit(-1); } printf("Socket connection successful: master socket = %d\n", m); for ( ; ; ) { s = soap_accept(&soap); printf("Socket connection successful: slave socket = %d\n", s); if (s < 0) { soap_print_fault(&soap, stderr); exit(-1); } soap_serve(&soap); soap_end(&soap); } } return 0; } // these following methods are declared on "soapStub.h" int ns__add(struct soap *soap, double a, double b, double &result) { result = a + b; printf("a = %lf, b = %lf, result = %lf\n", a, b, result); return SOAP_OK; } int ns__sub(struct soap *soap, double a, double b, double &result) { result = a - b; printf("a = %lf, b = %lf, result = %lf\n", a, b, result); return SOAP_OK; } int ns__square(struct soap *soap, double a, double &result) { result = a * a; printf("a = %lf, result = %lf\n", a, result); return SOAP_OK; } bool certifyUser(char* ID, char* Password) { if(!strcmp(ID, "root")) { if(!strcmp(Password, "pass")) return true; else return false; } else return false; } int ns__certifyUser(struct soap *soap, char *ID, char *Password, char *&result) { printf("Received: ID = %s, Password = %s\n", ID, Password); if(certifyUser(ID, Password)) { result = "OK"; return SOAP_OK; } else { soap->error = soap_receiver_fault(soap, "[faultstring] : error", "[faultdetail] your ID or Password is wrong."); soap_send_fault(soap); return SOAP_FAULT; } }