SOAP_SOCKET BankService::accept() { return soap_accept(this); }
SOAP_SOCKET wsrmService::accept() { return soap_accept(this->soap); }
int main(int argc, char *argv[]) { SOAP_SOCKET m; #if defined(_POSIX_THREADS) || defined(_SC_THREADS) pthread_t tid; pthread_mutex_init(&global_flag, NULL); pthread_mutex_init(&libssh2_flag, NULL); pthread_cond_init(&termination_flag, NULL); #endif struct soap soap, *tsoap = NULL; psoap = &soap; int ch, msglevel = LOG_INFO; static char *USAGE = "\nUSAGE:\noph_server [-d] [-l <log_file>] [-p <port>] [-v] [-w]\n"; fprintf(stdout, "%s", OPH_VERSION); fprintf(stdout, "%s", OPH_DISCLAIMER); set_debug_level(msglevel + 10); while ((ch = getopt(argc, argv, "dhl:p:vwxz")) != -1) { switch (ch) { case 'd': msglevel = LOG_DEBUG; break; case 'h': fprintf(stdout, "%s", USAGE); return 0; case 'l': oph_log_file_name = optarg; break; case 'p': oph_server_port = optarg; break; case 'v': return 0; break; case 'w': if (msglevel < LOG_WARNING) msglevel = LOG_WARNING; break; case 'x': fprintf(stdout, "%s", OPH_WARRANTY); return 0; case 'z': fprintf(stdout, "%s", OPH_CONDITIONS); return 0; default: fprintf(stdout, "%s", USAGE); return 0; } } set_debug_level(msglevel + 10); pmesg(LOG_INFO, __FILE__, __LINE__, "Selected log level %d\n", msglevel); #ifdef OPH_SERVER_LOCATION oph_server_location = strdup(OPH_SERVER_LOCATION); #else oph_server_location = getenv(OPH_SERVER_LOCATION_STR); if (!oph_server_location) { fprintf(stderr, "OPH_SERVER_LOCATION has to be set\n"); return 1; } #endif pmesg(LOG_DEBUG, __FILE__, __LINE__, "Server location '%s'\n", oph_server_location); char configuration_file[OPH_MAX_STRING_SIZE]; snprintf(configuration_file, OPH_MAX_STRING_SIZE, OPH_CONFIGURATION_FILE, oph_server_location); set_global_values(configuration_file); if (oph_log_file_name) { if (logfile) fclose(logfile); if (!(logfile = fopen(oph_log_file_name, "a"))) { fprintf(stderr, "Wrong log file name '%s'\n", oph_log_file_name); return 1; } pmesg(LOG_INFO, __FILE__, __LINE__, "Selected log file '%s'\n", oph_log_file_name); if (logfile) set_log_file(logfile); } else oph_log_file_name = hashtbl_get(oph_server_params, OPH_SERVER_CONF_LOGFILE); int int_port = strtol(oph_server_port, NULL, 10); if (oph_handle_signals()) { pmesg(LOG_ERROR, __FILE__, __LINE__, "A problem occurred while setting up signal dispositions\n"); exit(1); } if (mysql_library_init(0, 0, 0)) { pmesg(LOG_ERROR, __FILE__, __LINE__, "Cannot setup MySQL\n"); exit(1); } oph_tp_start_xml_parser(); if (CRYPTO_thread_setup()) { pmesg(LOG_ERROR, __FILE__, __LINE__, "Cannot setup thread mutex for OpenSSL\n"); exit(1); } soap_init(&soap); soap.fget = oph_http_get; if (soap_register_plugin(&soap, oph_plugin)) { pmesg(LOG_ERROR, __FILE__, __LINE__, "Cannot register %s plugin\n", OPH_PLUGIN_ID); soap_print_fault(&soap, stderr); cleanup(); exit(-1); } // Register serverid struct oph_plugin_data *state = NULL; if (!(state = (struct oph_plugin_data *) soap_lookup_plugin(&soap, OPH_PLUGIN_ID))) { pmesg(LOG_ERROR, __FILE__, __LINE__, "Error on lookup plugin struct\n"); soap_print_fault(&soap, stderr); cleanup(); exit(-1); } state->serverid = strdup(oph_web_server); #ifdef WITH_OPENSSL /* init gsoap context and SSL */ if (soap_ssl_server_context(&soap, SOAP_TLSv1_2, oph_server_cert, oph_server_password, oph_server_ca, NULL, NULL, NULL, NULL)) { pmesg(LOG_ERROR, __FILE__, __LINE__, "SSL Server Context Error\n"); soap_print_fault(&soap, stderr); cleanup(); exit(1); } #endif soap.accept_timeout = oph_server_inactivity_timeout; soap.send_timeout = soap.recv_timeout = oph_server_timeout; soap.bind_flags |= SO_REUSEADDR; m = soap_bind(&soap, NULL, int_port, 100); if (!soap_valid_socket(m)) { pmesg(LOG_ERROR, __FILE__, __LINE__, "Soap invalid socket\n"); soap_print_fault(&soap, stderr); cleanup(); exit(1); } pmesg(LOG_DEBUG, __FILE__, __LINE__, "Bind successful: socket = %d\n", m); for (;;) { SOAP_SOCKET s = soap_accept(&soap); if (!soap_valid_socket(s)) { if (soap.errnum) { pmesg(LOG_ERROR, __FILE__, __LINE__, "Soap invalid socket\n"); soap_print_fault(&soap, stderr); } else pmesg(LOG_ERROR, __FILE__, __LINE__, "Server timed out (timeout set to %d seconds)\n", soap.accept_timeout); break; } tsoap = soap_copy(&soap); if (!tsoap) { soap_closesock(&soap); continue; } #if defined(_POSIX_THREADS) || defined(_SC_THREADS) pthread_create(&tid, NULL, (void *(*)(void *)) &process_request, tsoap); #else process_request(tsoap); #endif } cleanup(); return 0; }
SOAP_SOCKET quoteService::accept() { return soap_accept(this); }
SOAP_SOCKET calcService::accept() { return soap_accept(this); }
SOAP_SOCKET AdvancedSecurityServiceBindingService::accept() { return soap_accept(this->soap); }
SOAP_SOCKET AccountService::accept() { return soap_accept(this); }
SOAP_SOCKET ServiceSoapBindingService::accept() { return soap_accept(this); }
SOAP_SOCKET ImagingBindingService::accept() { return soap_accept(this->soap); }
SOAP_SOCKET BasicHttpBinding_USCOREICalculatorService::accept() { return soap_accept(this->soap); }
int main(int argc, char **argv){ // Asigno el handler para el Ctrl + C signal(SIGINT,salir); // Declaro estructura soap struct soap soap; // Inicializo la estructura soap soap_init(&soap); // Compruebo que me han pasado bien los argumentos al ejecutar el servidor if (argc < 2) { printf("Usage: ./server xxxx (port)\n"); soap_serve(&soap); soap_destroy(&soap); soap_end(&soap); } else{ soap.send_timeout = 60; soap.recv_timeout = 60; soap.accept_timeout = 3600; // server stops after 1 hour of inactivity soap.max_keep_alive = 100; // max keep-alive sequence void *process_request(void*); struct soap *tsoap; pthread_t tid; int port = atoi(argv[1]); // first command-line arg is port SOAP_SOCKET m, s; m = soap_bind(&soap, NULL, port, BACKLOG); if (!soap_valid_socket(m)){ soap_print_fault(&soap, stderr); exit(1); } fprintf(stderr, "Socket connection successful %d\n", m); // Cargamos lus usuarios guardados en disco cargarListaUsuarios(); for (;;) { s = soap_accept(&soap); if (!soap_valid_socket(s)) { if (soap.errnum) { soap_print_fault(&soap, stderr); exit(1); } fprintf(stderr, "server timed out\n"); break; } // gestiono la funcion que me pide el Cliente soap_serve(&soap); soap_end(&soap); tsoap = soap_copy(&soap); if (!tsoap) break; pthread_create(&tid, NULL, (void*(*)(void*))process_request, (void*)tsoap); } } soap_done(&soap); return 0; }
SOAP_SOCKET projectstatsService::accept() { return soap_accept(this); }
SOAP_SOCKET serverService::accept() { return soap_accept(this); }
SOAP_SOCKET WSHttpBinding_USCOREINWNMasterServerAPIService::accept() { return soap_accept(this); }
SOAP_SOCKET DisplayBindingService::accept() { return soap_accept(this); }
/* * This loop listens to incoming Soap reuests and forwards them to HtiDispatcher */ void DataGatewaySOAPServerThread::Run() { struct soap soap; //Initializes a static/stack-allocated runtime environment soap_init(&soap); //soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE); //_CrtDbgReport(_CRT_ERROR, _CRTDBG_MODE_WNDW); /* #ifdef _DEBUG HANDLE hLogFile; hLogFile = CreateFile("c:\\log.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, hLogFile); #endif */ while (m_Running) { int m, s; // master and slave sockets Util::Debug("soap_init"); //Returns master socket (backlog = max. queue size for requests). When host==NULL: host is the machine on which the service runs m = soap_bind(&soap, NULL, m_TcpPort, 100); if (m < 0) { //Util::Error("Failed to open socket", m_TcpPort); //soap_print_fault(&soap, stderr); char temp[512]; soap_sprint_fault(&soap, temp); Util::Error(temp); break; } else { Util::Debug("Socket connection successful"); /* #ifdef _DEBUG _CrtMemState startMem, endMem, diffMem; //Sleep(5000); #endif */ for (int i = 1; ; i++) { //_RPT1(_CRT_WARN, "---++++=======Iter %d=======++++---\n", i); //_RPT0(_CRT_WARN, "---Start dump---\n"); //_CrtMemCheckpoint(&startMem); //_CrtMemDumpStatistics(&startMem); //Returns slave socket s = soap_accept(&soap); if (s < 0) { //soap_print_fault(&soap, stderr); char temp[512]; soap_sprint_fault(&soap, temp); Util::Error(temp); break; } Util::Debug(" accepted connection"); //start of my dispatching code if ( !m_HtiDispatcher->DispatchSoapServe( &soap ) ) // process RPC request { //soap_print_fault(&soap, stderr); // print error // clean up class instances soap_destroy(&soap); // clean up everything and close socket soap_end(&soap); } else { // clean up allcated data soap_dealloc(&soap, NULL); // clean up class instances soap_destroy(&soap); //cleanup temp data soap_free(&soap); //soap_end(&soap); // clean up everything and close socket } /* #ifdef _DEBUG //Sleep(2000); //wait when hadler thread is over //copy memcpy( &startMem, &endMem, sizeof(_CrtMemState) ); _CrtMemCheckpoint(&endMem); _CrtMemDumpStatistics(&endMem); _RPT0(_CRT_WARN, "==========End diff==========\n"); if (_CrtMemDifference( &diffMem, &startMem, &endMem ) ) { _CrtMemDumpStatistics(&diffMem); _RPT0(_CRT_WARN, "########## Objects #############\n"); //_CrtMemDumpAllObjectsSince( &diffMem ); _RPT0(_CRT_WARN, "++++++End dump++++++\n"); } #endif */ Util::Debug("request dispatched"); } } } // Clean up deserialized data (except class instances) and temporary data soap_end(&soap); // close master socket and detach environment soap_done(&soap); Stop(); //#ifdef _DEBUG // CloseHandle(hLogFile); //#endif }
int main(int argc, char **argv) { struct soap *soap; int server = 0; int text = 0; int port = 0; FILE *fd; double result; char *user; int runs = 1; /* create context */ soap = soap_new(); /* register wsse plugin */ soap_register_plugin_arg(soap, soap_wsse, (void*)token_handler); /* options */ if (argc >= 2) { if (strchr(argv[1], 'c')) soap_set_omode(soap, SOAP_IO_CHUNK); else if (strchr(argv[1], 'y')) soap_set_omode(soap, SOAP_IO_STORE); if (strchr(argv[1], 'i')) soap_set_omode(soap, SOAP_XML_INDENT); if (strchr(argv[1], 'n')) soap_set_omode(soap, SOAP_XML_CANONICAL); if (strchr(argv[1], 'a')) aes = 1; if (strchr(argv[1], 'o')) oaep = 1; if (strchr(argv[1], 'd')) sym = 1; if (strchr(argv[1], 'e')) enc = 1; if (strchr(argv[1], 'f')) addenc = 1; /* if (strchr(argv[1], 'F')) addenca = 1; */ if (strchr(argv[1], 'h')) hmac = 1; if (strchr(argv[1], 'k')) nokey = 1; if (strchr(argv[1], 's')) server = 1; if (strchr(argv[1], 't')) text = 1; if (strchr(argv[1], 'g')) addsig = 1; if (strchr(argv[1], 'b')) nobody = 1; if (strchr(argv[1], 'x')) nohttp = 1; if (strchr(argv[1], 'z')) soap_set_mode(soap, SOAP_ENC_ZLIB); if (isdigit(argv[1][strlen(argv[1])-1])) { runs = argv[1][strlen(argv[1])-1] - '0'; soap_set_mode(soap, SOAP_IO_KEEPALIVE); } } /* soap->actor = "..."; */ /* set only when required */ user = getenv("USER"); if (!user) user = "******"; /* read RSA private key for signing */ if ((fd = fopen("server.pem", "r"))) { rsa_privk = PEM_read_PrivateKey(fd, NULL, NULL, (void*)"password"); fclose(fd); if (!rsa_privk) { fprintf(stderr, "Could not read private RSA key from server.pem\n"); exit(1); } } else fprintf(stderr, "Could not read server.pem\n"); /* read certificate (more efficient is to keep certificate in memory) to obtain public key for encryption and signature verification */ if ((fd = fopen("servercert.pem", "r"))) { cert = PEM_read_X509(fd, NULL, NULL, NULL); fclose(fd); if (!cert) { fprintf(stderr, "Could not read certificate from servercert.pem\n"); exit(1); } } else fprintf(stderr, "Could not read server.pem\n"); rsa_pubk = X509_get_pubkey(cert); if (!rsa_pubk) { fprintf(stderr, "Could not get public key from certificate\n"); exit(1); } /* port argument */ if (argc >= 3) port = atoi(argv[2]); /* need cacert to verify certificates with CA (cacert.pem for testing and cacerts.pem for production, which contains the trusted CA certificates) */ soap->cafile = "cacert.pem"; /* server or client/ */ if (server) { if (port) { /* stand-alone server serving messages over port */ if (!soap_valid_socket(soap_bind(soap, NULL, port, 100))) { soap_print_fault(soap, stderr); exit(1); } printf("Server started at port %d\n", port); while (soap_valid_socket(soap_accept(soap))) { if (hmac) soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); else if (nokey) soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0); else soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0); if (sym) { if (aes) soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key)); else soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key)); } else if (enc) soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0); if (soap_serve(soap)) { soap_wsse_delete_Security(soap); soap_print_fault(soap, stderr); soap_print_fault_location(soap, stderr); } soap_destroy(soap); soap_end(soap); } soap_print_fault(soap, stderr); exit(1); } else { /* CGI-style server serving messages over stdin/out */ if (hmac) soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); else if (nokey) soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0); else soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0); if (sym) { if (aes) soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key)); else soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key)); } else if (enc) soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0); if (soap_serve(soap)) { soap_wsse_delete_Security(soap); soap_print_fault(soap, stderr); soap_print_fault_location(soap, stderr); } soap_destroy(soap); soap_end(soap); } } else /* client */ { int run; char endpoint[80]; /* ns1:test data */ struct ns1__add a; struct ns1__sub b; a.a = 123; a.b = 456; b.a = 789; b.b = -99999; /* client sending messages to stdout or over port */ if (port) sprintf(endpoint, "http://localhost:%d", port); else if (nohttp) strcpy(endpoint, ""); else strcpy(endpoint, "http://"); for (run = 0; run < runs; run++) { /* message lifetime of 60 seconds */ soap_wsse_add_Timestamp(soap, "Time", 60); /* add user name with text or digest password */ if (text) soap_wsse_add_UsernameTokenText(soap, "User", user, "userPass"); else soap_wsse_add_UsernameTokenDigest(soap, "User", user, "userPass"); if (sym) { if (aes) { /* symmetric encryption with AES */ soap_wsse_add_EncryptedData_KeyInfo_KeyName(soap, "My AES Key"); if (soap_wsse_encrypt_body(soap, SOAP_MEC_ENC_AES256_CBC, aes_key, sizeof(aes_key))) soap_print_fault(soap, stderr); soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key)); } else { /* symmetric encryption with DES */ soap_wsse_add_EncryptedData_KeyInfo_KeyName(soap, "My DES Key"); if (soap_wsse_encrypt_body(soap, SOAP_MEC_ENC_DES_CBC, des_key, sizeof(des_key))) soap_print_fault(soap, stderr); soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key)); } } else if (addenc || addenca) { /* RSA encryption of the <ns1:add> element */ const char *SubjectKeyId = NULL; /* set to non-NULL to use SubjectKeyIdentifier in Header rather than a full cert key */ /* MUST set wsu:Id of the elements to encrypt */ if (addenc) /* encrypt element <ns1:add> */ { soap_wsse_set_wsu_id(soap, "ns1:add"); if (soap_wsse_add_EncryptedKey_encrypt_only(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL, "ns1:add")) soap_print_fault(soap, stderr); } else /* encrypt element <a> */ { soap_wsse_set_wsu_id(soap, "a"); if (soap_wsse_add_EncryptedKey_encrypt_only(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL, "a")) soap_print_fault(soap, stderr); } soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0); } else if (enc) { /* RSA encryption of the SOAP Body */ const char *SubjectKeyId = NULL; /* set to non-NULL to use SubjectKeyIdentifier in Header rather than a full cert key */ if (oaep) { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_AES256_CBC | SOAP_MEC_OAEP, "Cert", cert, SubjectKeyId, NULL, NULL)) soap_print_fault(soap, stderr); } else if (aes) { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_AES256_CBC, "Cert", cert, SubjectKeyId, NULL, NULL)) soap_print_fault(soap, stderr); } else { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL)) soap_print_fault(soap, stderr); } soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0); } if (hmac) { /* symmetric signature */ if (nobody) soap_wsse_sign(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); else soap_wsse_sign_body(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); /* WS-SecureConversation contect token */ soap_wsse_add_SecurityContextToken(soap, "SCT", contextId); } else { if (nokey) soap_wsse_add_KeyInfo_KeyName(soap, "MyKey"); else { soap_wsse_add_BinarySecurityTokenX509(soap, "X509Token", cert); soap_wsse_add_KeyInfo_SecurityTokenReferenceX509(soap, "#X509Token"); } if (nobody || addsig) /* do not sign body */ soap_wsse_sign(soap, SOAP_SMD_SIGN_RSA_SHA1, rsa_privk, 0); else soap_wsse_sign_body(soap, SOAP_SMD_SIGN_RSA_SHA256, rsa_privk, 0); } /* enable automatic signature verification of server responses */ if (hmac) soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); else if (nokey) soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0); else soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0); /* sign the response message in unsigned body? If so, set wsu:Id */ if (addsig) { soap_wsse_set_wsu_id(soap, "ns1:add"); soap_wsse_sign_only(soap, "User ns1:add"); } /* invoke the server. You can choose add, sub, mul, or div operations * that show different security aspects (intentional message rejections) * for demonstration purposes (see server operations below) */ if (!soap_call_ns1__add(soap, endpoint, NULL, 1.0, 2.0, &result)) { if (!soap_wsse_verify_Timestamp(soap)) { const char *servername = soap_wsse_get_Username(soap); if (servername && !strcmp(servername, "server") && !soap_wsse_verify_Password(soap, "serverPass")) printf("Result = %g\n", result); else { fprintf(stderr, "Server authentication failed\n"); soap_print_fault(soap, stderr); } } else { fprintf(stderr, "Server response expired\n"); soap_print_fault(soap, stderr); } } else { soap_print_fault(soap, stderr); soap_print_fault_location(soap, stderr); } /* clean up security header */ soap_wsse_delete_Security(soap); /* disable soap_wsse_verify_auto */ soap_wsse_verify_done(soap); } /* run */ } /* clean up keys */ if (rsa_privk) EVP_PKEY_free(rsa_privk); if (rsa_pubk) EVP_PKEY_free(rsa_pubk); if (cert) X509_free(cert); /* clean up gSOAP engine */ soap_destroy(soap); soap_end(soap); soap_done(soap); free(soap); /* done */ return 0; }
SOAP_SOCKET RuleEngineBindingService::accept() { return soap_accept(this->soap); }
int main(int argc, char **argv) { // program initialize // log4cplus configuration PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("./conf/Log4Cplus.inp")); // program configuration if(configure.LoadFile("conf/config.xml")) { fprintf(stderr,"fail to read configure file\n"); return(-1); } // get ladp current max uid LdapModule* ld = new LdapModule; ld->conn(); ld->initMaxUid(MAXUID); ld->disconn(); delete ld; // Web Service struct soap soap; soap_init(&soap); soap.fget = http_get; if (argc < 2) // no args: assume this is a CGI application { soap_serve(&soap); // serve request, one thread, CGI style soap_destroy(&soap); // dealloc C++ data soap_end(&soap); // dealloc data and clean up } else { struct soap *soap_thr[MAX_THR]; // each thread needs a runtime context pthread_t tid[MAX_THR]; int port = atoi(argv[1]); // first command-line arg is port SOAP_SOCKET m, s; int i; m = soap_bind(&soap, NULL, port, BACKLOG); if (!soap_valid_socket(m)) exit(1); fprintf(stderr, "Socket connection successful %d\n", m); pthread_mutex_init(&queue_cs, NULL); pthread_cond_init(&queue_cv, NULL); for (i = 0; i < MAX_THR; i++) { soap_thr[i] = soap_copy(&soap); fprintf(stderr, "Starting thread %d\n", i); pthread_create(&tid[i], NULL, (void*(*)(void*))process_queue, (void*)soap_thr[i]); } for (;;) { s = soap_accept(&soap); if (!soap_valid_socket(s)) { if (soap.errnum) { soap_print_fault(&soap, stderr); continue; // retry } else { fprintf(stderr, "Server timed out\n"); break; } } fprintf(stderr, "Thread %d accepts socket %d connection from IP %d.%d.%d.%d\n", i, s, (soap.ip >> 24)&0xFF, (soap.ip >> 16)&0xFF, (soap.ip >> 8)&0xFF, soap.ip&0xFF); while (enqueue(s) == SOAP_EOM) sleep(1); } for (i = 0; i < MAX_THR; i++) { while (enqueue(SOAP_INVALID_SOCKET) == SOAP_EOM) sleep(1); } for (i = 0; i < MAX_THR; i++) { fprintf(stderr, "Waiting for thread %d to terminate... ", i); pthread_join(tid[i], NULL); fprintf(stderr, "terminated\n"); soap_done(soap_thr[i]); free(soap_thr[i]); } pthread_mutex_destroy(&queue_cs); pthread_cond_destroy(&queue_cv); } soap_done(&soap); return 0; }
int main(int argc, char **argv) { struct soap *soap = soap_new1(SOAP_XML_INDENT); soap_register_plugin(soap, soap_wsa); if (argc < 2) { /* no args: act as CGI service over stdin/out */ if (soap_serve(soap)) { soap_print_fault(soap, stderr); soap_print_fault_location(soap, stderr); } } else { int port = atoi(argv[1]); if (port) { /* stand-alone server serving messages over port */ soap->bind_flags = SO_REUSEADDR; if (!soap_valid_socket(soap_bind(soap, NULL, port, 100))) { soap_print_fault(soap, stderr); exit(1); } printf("Server is running\n"); while (soap_valid_socket(soap_accept(soap))) { if (soap_serve(soap)) { soap_print_fault(soap, stderr); soap_print_fault_location(soap, stderr); } printf("Request served\n"); soap_destroy(soap); soap_end(soap); } } else { /* client */ struct ns__wsademoResult res; soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction); if (argc >= 3) { if (strchr(argv[2], 'f')) soap_wsa_add_From(soap, FromAddress); if (strchr(argv[2], 'r')) soap_wsa_add_ReplyTo(soap, ReplyToAddress); if (strchr(argv[2], 'n')) { #ifdef SOAP_WSA_2005 soap_wsa_add_NoReply(soap); #else printf("'NoReply' feature not available with WS-Addressing 2003/2004\n"); #endif } if (strchr(argv[2], 'e')) soap_wsa_add_FaultTo(soap, FaultToAddress); } if (soap_call_ns__wsademo(soap, ToAddress, NULL, argv[1], &res)) { #ifdef SOAP_WSA_2005 wsa5__FaultCodesType fault; const char *info; if (soap->error == 202) /* HTTP ACCEPTED */ printf("Request was accepted\n"); else if (soap_wsa_check_fault(soap, &fault, &info)) { switch (fault) { case wsa5__EndpointUnavailable: fprintf(stderr, "Server %s is currently not available.\n", info?info:""); break; default: fprintf(stderr, "A wsa fault %d occurred:\n", (int)fault); soap_print_fault(soap, stderr); break; } } else soap_print_fault(soap, stderr); #else if (soap->error == 202) /* HTTP ACCEPTED */ printf("Request was accepted\n"); else soap_print_fault(soap, stderr); #endif } else if (res.out) printf("Result = %s\n", res.out); } } soap_destroy(soap); soap_end(soap); soap_done(soap); free(soap); return 0; }
int main (int argc, char *argv[]) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, ""); if (parse_args (argc, argv) != 0) { return -1; } CORBA::Object_var obj = orb->string_to_object (bdc_ior); CUTS::Benchmark_Data_Collector_var comp = CUTS::Benchmark_Data_Collector::_narrow (obj.in()); if (CORBA::is_nil (comp.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Unable to acquire Benchmark_Data_Collector objref\n"), -1); } CUTS::BDC_Control_Handle_var controls = comp->provide_controls(); if (CORBA::is_nil (controls.in())) { ACE_ERROR_RETURN ((LM_ERROR, "Unable to acquire controls objref\n"), -1); } CUTS::Path_Measurement_var online_measurements = comp->provide_online_measurements(); if (CORBA::is_nil (online_measurements.in())) { ACE_ERROR_RETURN ((LM_ERROR, "Unable to acquire online_measurements objref\n"), -1); } CUTS_x002eBenchmark_USCOREData_USCORECollector service (controls.in(), online_measurements.in()); int m, s; // master and slave sockets m = soap_bind(&service, "localhost", port, 100); if (m < 0) soap_print_fault(&service, stderr); else { fprintf(stderr, "Listening for SOAP requests on port = %d\n", port); for (int i = 1; ; i++) { s = soap_accept(&service); if (s < 0) { soap_print_fault(&service, stderr); break; } fprintf(stderr, "%d: Accepted connection from IP=%d.%d.%d.%d socket=%d\n", i, (service.ip >> 24)&0xFF, (service.ip >> 16)&0xFF, (service.ip >> 8)&0xFF, service.ip&0xFF, s); if (service.serve() != SOAP_OK) // process RPC request soap_print_fault(&service, stderr); // print error fprintf(stderr, "SOAP Request served\n"); soap_destroy(&service); // clean up class instances soap_end(&service); // clean up everything and close socket } } } catch (CORBA::Exception& ex) { ACE_PRINT_EXCEPTION (ex, "CORBA::Exception\n"); ACE_ERROR_RETURN ((LM_ERROR, "Uncaught CORBA exception\n"), 1); } return 0; }
int main(int argc, const char * argv[]) { struct soap soap; // sqlite3 设置为工作在 Serialized 模式下,因为“心跳线程”会周期操作 token table // 启动 webservice soap_init(&soap); soap_set_mode(&soap, SOAP_C_UTFSTRING); // 如果没有这个,无法正确显示 utf-8 编码的汉字 if (!soap_valid_socket(soap_bind(&soap, 0, 8899, 100))) { fprintf(stderr, "ERR: soap_bind 8899 err\n"); exit(-1); } fprintf(stdout, "start %d\n", 8899); // 启动心跳线程 // FIXME: 在每次 webservice 的请求时,检查 token table 是不是更好些呢?. // 已经修改为,在每次查询时,首先删除超时对象,这样不需要启动独立的工作线程;. #if 0 #ifdef WIN32 CloseHandle(CreateThread(0, 0, heartBeatCheck_run, 0, 0, 0)); #else pthread_t th; pthread_create(&th, 0, heartBeatCheck_run, 0); #endif // os #endif // 0; // 开始处理所有 webservice 请求... while (1) { int n = soap_accept(&soap); if (n < 0) { fprintf(stderr, "ERR: soap_accept err\n"); soap_print_fault(&soap, stderr); if (soap.errnum) { soap_print_fault(&soap, stderr); exit(1); } exit(-1); } #ifdef MULTITHREAD_SERVER { struct soap *ts = soap_copy(&soap); if (ts) { #ifdef WIN32 HANDLE th; CloseHandle(CreateThread(0, 0, _working_proc, ts, 0, 0)); #else pthread_t th; pthread_create(&th, 0, _working_proc, ts); #endif // } } #else soap_serve(&soap); soap_destroy(&soap); soap_end(&soap); #endif // multi thread server } soap_done(&soap); return 0; }
SOAP_SOCKET TransService::accept() { return soap_accept(this); }
//Main Funtion int main(int argc,char *argv[]) { int status=0; status=nInit(); sprintf(sLogfile,"%s",argv[0]); SOAP_SOCKET m,s; int i=0; struct soap Onlsoap; soap_init(&Onlsoap); Onlsoap.fget = http_get; Onlsoap.fpost = http_post; struct soap * soap_thr[MAX_THR]; pthread_t tid[MAX_THR]; sigset(SIGUSR1, signalHandle); sigset(SIGTERM, signalHandle); sigset(SIGSEGV, signalHandle); // 设置UTF-8编码方式 //soap_set_mode(&Onlsoap, SOAP_C_UTFSTRING); soap_set_mode(&Onlsoap, SOAP_C_MBSTRING); soap_set_namespaces(&Onlsoap, namespaces); // ---------- m = soap_bind(&Onlsoap,NULL,lPort,BACKLOG); //循环直至服务套接字合法 while (!soap_valid_socket(m)) { dzlog_error("Bind port error!"); m = soap_bind(&Onlsoap,NULL,lPort,BACKLOG); sleep(2); } //锁和条件变量初始化 pthread_mutex_init(&queue_cs,NULL); pthread_cond_init(&queue_cv,NULL); //生成服务线程 for(i = 0; i <MAX_THR; i++) { soap_thr[i] = soap_copy(&Onlsoap); dzlog_info("Starting thread %d ",i); pthread_create(&tid[i],NULL,(void*(*)(void*))process_queue,(void*)soap_thr[i]); } for(;;) { s=soap_accept(&Onlsoap); if(!soap_valid_socket(s)) { if (Onlsoap.errnum) { soap_print_fault(&Onlsoap,stderr); continue; } else { dzlog_error("Server timed out."); break; } } dzlog_info("Main Process[%d] accepted connection from IP=%d.%d.%d.%d", getpid(), (Onlsoap.ip >> 24)&0xFF, (Onlsoap.ip >> 16)&0xFF, (Onlsoap.ip >> 8)&0xFF, Onlsoap.ip&0xFF); while(enqueue(s) == SOAP_EOM) sleep(1); } //服务结束后的清理工作 for(i = 0; i < MAX_THR; i++) { while (enqueue(SOAP_INVALID_SOCKET) == SOAP_EOM) { sleep(1); } } for(i=0; i< MAX_THR; i++) { pthread_join(tid[i],NULL); dzlog_debug("terminated[%d] ",i); soap_done(soap_thr[i]); free(soap_thr[i]); } pthread_mutex_destroy(&queue_cs); pthread_cond_destroy(&queue_cv); soap_done(&Onlsoap); DbPoolFree(&conn_pool); zlog_fini(); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { int ret; /* 192.168.1.1 is the NVT, 192.168.1.234 is the NVC */ string url = "http://192.168.1.1/onvif/device_service"; /* Below is where to receive the event */ string eventNotify = "http://192.168.1.234:9090/subscription-2"; string user = "******"; string pass = "******"; OnvifClientDevice onvifDevice(url, user, pass); _tds__GetCapabilitiesResponse capabilitiesResponse; onvifDevice.GetCapabilities(); OnvifClientMedia media(onvifDevice); _trt__GetProfilesResponse profiles; media.GetProfiles(profiles); /* Recording */ OnvifClientRecording onvifRecording(onvifDevice); _trc__GetRecordingsResponse recordings; onvifRecording.GetRecordings(recordings); /* Onvif Receiver */ OnvifClientReceiver onvifReceiver(onvifDevice); _trv__GetReceiversResponse receivers; onvifReceiver.GetReceivers(receivers); string replayUrl; OnvifClientReplay onvifRelay(onvifDevice); onvifRelay.GetReplayUri("RecordingToken001", replayUrl); printf("Relay Url %s\n", replayUrl.c_str()); OnvifClientEvent onvifEvent(onvifDevice); onvifEvent.Subscribe(eventNotify); OnvifClientEventNotify notify(soap_new()); if ((ret = soap_bind(¬ify, NULL, 9090, 100) == SOAP_INVALID_SOCKET ) ) { printf("OnvifClientEventNotify::soap_bind Binding on %d port failed", 9090); return 0; } int timeStart = time(NULL); int currentTime = 0; //Loop to recevie the event while(1) { currentTime = time(NULL); if (currentTime - timeStart > 58) { onvifEvent.Renew(); } printf("soap_accept accepting\n"); if( (ret = soap_accept(¬ify)) == SOAP_INVALID_SOCKET) { printf("soap_accept accepting timeout\n"); continue; } if ( (soap_begin_serve(¬ify)) != SOAP_OK) { printf("soap_begin_serve serve %d failed", ret); continue; } ret = notify.dispatch(); continue; } return 0; }
SOAP_SOCKET ReceiverBindingService::accept() { return soap_accept(this); }
SOAP_SOCKET PullPointSubscriptionBindingService::accept() { return soap_accept(this->soap); }
SOAP_SOCKET WSDualHttpBinding_USCOREICalculatorDuplexService::accept() { return soap_accept(this->soap); }