int AmazonS3SoapBindingService::serve() { #ifndef WITH_FASTCGI unsigned int k = this->soap->max_keep_alive; #endif do { #ifndef WITH_FASTCGI if (this->soap->max_keep_alive > 0 && !--k) this->soap->keep_alive = 0; #endif if (soap_begin_serve(this->soap)) { if (this->soap->error >= SOAP_STOP) continue; return this->soap->error; } if (dispatch() || (this->soap->fserveloop && this->soap->fserveloop(this->soap))) { #ifdef WITH_FASTCGI soap_send_fault(this->soap); #else return soap_send_fault(this->soap); #endif } #ifdef WITH_FASTCGI soap_destroy(this->soap); soap_end(this->soap); } while (1); #else } while (this->soap->keep_alive);
/** * Actual SOAP request processing in the thread * if it was accepted in ServeSoap() * The request is processed using HtiPluginDll */ void SoapHandler::DoServeSoap() { Util::Debug("SoapHandler::DoServeSoap"); soap_set_namespaces( m_SoapEnv, m_HtiPlugin->serviceNamespaces()); //soap_set_namespaces( m_SoapEnv, namespaces_l); if (soap_envelope_begin_in(m_SoapEnv) || soap_recv_header(m_SoapEnv) || soap_body_begin_in(m_SoapEnv) ) { //soap_set_namespaces( m_SoapEnv, namespaces_l); soap_send_fault(m_SoapEnv); Util::Debug("SoapHandler::DoServeSoap NOK"); return; } //call soap_serve(soap_server_request) from the dll plug-in //m_HtiPlugin->soap_serve( m_SoapEnv ); if (m_HtiPlugin->soap_serve_request(m_SoapEnv) || (m_SoapEnv->fserveloop && m_SoapEnv->fserveloop(m_SoapEnv))) { //soap_set_namespaces( m_SoapEnv, namespaces_l); soap_send_fault(m_SoapEnv); Util::Debug("SoapHandler::DoServeSoap NOK"); return; } CleanSoapEnv(); Util::Debug("SoapHandler::DoServeSoap OK"); }
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap) { #ifndef WITH_FASTCGI unsigned int k = soap->max_keep_alive; #endif do { #ifndef WITH_FASTCGI if (soap->max_keep_alive > 0 && !--k) soap->keep_alive = 0; #endif if (soap_begin_serve(soap)) { if (soap->error >= SOAP_STOP) continue; return soap->error; } if (soap_serve_request(soap) || (soap->fserveloop && soap->fserveloop(soap))) { #ifdef WITH_FASTCGI soap_send_fault(soap); #else return soap_send_fault(soap); #endif } #ifdef WITH_FASTCGI soap_destroy(soap); soap_end(soap); } while (1); #else } while (soap->keep_alive);
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap* soap) { #ifndef WITH_FASTCGI unsigned int k = soap->max_keep_alive; #endif do { #ifdef WITH_FASTCGI if (FCGI_Accept() < 0) { soap->error = SOAP_EOF; return soap_send_fault(soap); } #endif soap_begin(soap); #ifndef WITH_FASTCGI if (soap->max_keep_alive > 0 && !--k) soap->keep_alive = 0; #endif if (soap_begin_recv(soap)) { if (soap->error < SOAP_STOP) { #ifdef WITH_FASTCGI soap_send_fault(soap); #else return soap_send_fault(soap); #endif } soap_closesock(soap); continue; } if (soap_envelope_begin_in(soap) || soap_recv_header(soap) || soap_body_begin_in(soap) || soap_serve_request(soap) || (soap->fserveloop && soap->fserveloop(soap))) { #ifdef WITH_FASTCGI soap_send_fault(soap); #else return soap_send_fault(soap); #endif } #ifdef WITH_FASTCGI soap_destroy(soap); soap_end(soap); } while (1); #else } while (soap->keep_alive);
int dpws_discoveryService::serve() { #ifndef WITH_FASTCGI unsigned int k = this->max_keep_alive; #endif do { soap_begin(this); #ifdef WITH_FASTCGI if (FCGI_Accept() < 0) { this->error = SOAP_EOF; return soap_send_fault(this); } #endif soap_begin(this); #ifndef WITH_FASTCGI if (this->max_keep_alive > 0 && !--k) this->keep_alive = 0; #endif if (soap_begin_recv(this)) { if (this->error < SOAP_STOP) { #ifdef WITH_FASTCGI soap_send_fault(this); #else return soap_send_fault(this); #endif } soap_closesock(this); continue; } if (soap_envelope_begin_in(this) || soap_recv_header(this) || soap_body_begin_in(this) || dispatch() || (this->fserveloop && this->fserveloop(this))) { #ifdef WITH_FASTCGI soap_send_fault(this); #else return soap_send_fault(this); #endif } #ifdef WITH_FASTCGI soap_destroy(this); soap_end(this); } while (1); #else } while (this->keep_alive);
/* * This method is used to forward soap request to correct SOAPHandler * Correct SOAPHandler is found by soap action */ bool HtiDispatcher::DispatchSoapServe(struct soap* soapEnv) { Util::Debug("HtiDispatcher::DispatchSoapServe()"); /* _CrtMemState localMem; _CrtMemCheckpoint( &localMem ); */ soap_begin( soapEnv ); if (soap_begin_recv(soapEnv)) { soap_set_namespaces( soapEnv, namespaces); soap_send_fault(soapEnv); return false; } if ( !(soapEnv->action) ) { //Util::Error("soapAction is missing"); soap_set_namespaces( soapEnv, namespaces); soapEnv->error = soap_sender_fault(soapEnv, "soapAction is missing", NULL); soap_send_fault(soapEnv); return false; } /* //_RPT0(_CRT_WARN, "!!!!!!!!!!!!!!!! Local Objects !!!!!!!!!!!!!!!!\n"); _CrtMemDumpAllObjectsSince( &localMem ); //_RPT1(_CRT_WARN, "action address %x\n", soapEnv->action); */ htiSoapActionHashMap::const_iterator it; it = m_SoapHandlers.find( soapEnv->action ); if ( it != m_SoapHandlers.end() ) { return (it->second)->ServeSoap( soapEnv ); } else { //Util::Error("soapAction is unknown:"); //Util::Error(soapEnv->action); //soapEnv->error = SOAP_NO_METHOD; soap_set_namespaces( soapEnv, namespaces); soapEnv->error = soap_sender_fault(soapEnv, "No plugin found", "no plugin found for requested service in actionSOAP header field"); soap_send_fault(soapEnv); return false; } Util::Debug("HtiDispatcher::DispatchSoapServe() OK"); }
void cms_clientFree( cms_client client) { struct soap* soap; cms_soapThread soapThread; cms_thread(client)->terminate = TRUE; os_mutexLock(&client->conditionMutex); os_condSignal(&client->condition); os_mutexUnlock(&client->conditionMutex); cms_threadDeinit(cms_thread(client)); if(client->soapEnvs){ os_mutexLock(&client->soapMutex); soap = (struct soap*)(c_iterTakeFirst(client->soapEnvs)); while(soap){ soap->error = soap_receiver_fault(soap, "Service is terminating.", NULL); soap_send_fault(soap); soap_destroy(soap); soap_end(soap); soap_done(soap); os_free(soap); soap = (struct soap*)(c_iterTakeFirst(client->soapEnvs)); } c_iterFree(client->soapEnvs); client->soapEnvs = NULL; os_mutexUnlock(&client->soapMutex); } if(client->threads){ soapThread = cms_soapThread(c_iterTakeFirst(client->threads)); while(soapThread){ cms_soapThreadFree(soapThread); (void)u_observableAction(u_observable(client->service->uservice), cms_clientStatisticsThreadRemove, client->service); soapThread = cms_soapThread(c_iterTakeFirst(client->threads)); } c_iterFree(client->threads); client->threads = NULL; } os_mutexDestroy(&client->soapMutex); os_mutexDestroy(&client->threadMutex); os_mutexDestroy(&client->conditionMutex); os_condDestroy(&client->condition); client->initCount = 0; if(client->service->configuration->verbosity >= 5){ OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "Client thread stopped for IP: %d.%d.%d.%d", (int)(client->ip>>24)&0xFF, (int)(client->ip>>16)&0xFF, (int)(client->ip>>8)&0xFF, (int)(client->ip&0xFF)); }
int Service::start(int port) { if (!soap_valid_socket(bind(NULL, port, 100))) { soap_stream_fault(std::cerr); exit(1); } std::cerr << "Server Running" << std::endl; /* optional: set accept timeout to pulse acks every 500 ms, see below */ soap->accept_timeout = -500000; for (;;) { if (soap_valid_socket(accept())) { /* with iterative servers asynchronous messaging deadlock scenarios exist! */ /* chain the WSRM service operations after the main service operations */ if (soap_begin_serve(soap) == SOAP_OK) if (dispatch() == SOAP_NO_METHOD) soap_serve_request(soap); if (soap->error) soap_send_fault(soap); if (soap->error && soap->error != SOAP_STOP) soap_stream_fault(std::cerr); destroy(); callback.destroy(); soap_wsrm_dump(soap, stdout); } else { /* error or timeout? */ if (soap->errnum) { soap_stream_fault(std::cerr); exit(1); } /* timeout occurs after 1 sec */ /* send acks to peers (optional), 10 ms per message timeout */ soap_wsrm_pulse(soap, -10000); /* 10 ms */ } } return SOAP_OK; }
void *callback_thread(void *ctx) { WSDualHttpBinding_USCOREICalculatorDuplexService *callback = (WSDualHttpBinding_USCOREICalculatorDuplexService*)ctx; THREAD_DETACH(THREAD_ID); /* chain the WSRM operations after callback operations */ if (soap_begin_serve(callback->soap) == SOAP_OK) if (callback->dispatch() == SOAP_NO_METHOD) soap_serve_request(callback->soap); if (callback->soap->error) soap_send_fault(callback->soap); if (callback->soap->error != SOAP_STOP && callback->soap->error != SOAP_EOF) callback->soap_stream_fault(std::cerr); else if (callback->soap->error != SOAP_EOF || callback->soap->errnum) soap_wsrm_dump(callback->soap, stdout); callback->destroy(); delete callback; return NULL; }
int Client::poll(int timeout) { #ifdef CB_THREAD // We leave the acceptance of messages to the callback server thread if (timeout < 0) timeout = 1; sleep(timeout); // but we want to wait some until these messages arrive #else callback.soap->accept_timeout = timeout; printf("\n**** Callback Polling\n"); while (soap_valid_socket(callback.accept())) { /* chain the WSRM operations after callback operations */ if (soap_begin_serve(callback.soap) == SOAP_OK) if (callback.dispatch() == SOAP_NO_METHOD) soap_serve_request(callback.soap); if (callback.soap->error) soap_send_fault(callback.soap); soap->error = callback.soap->error; callback.destroy(); if (soap->error && soap->error != SOAP_STOP) { soap_stream_fault(std::cerr); return soap->error; } soap_wsrm_dump(callback.soap, stdout); } #endif return SOAP_OK; }
OPENSPLICE_SERVICE_ENTRYPOINT (ospl_cmsoap, cmsoap) { cms_service cms; cms_client client; c_bool success; char* name = NULL; char* config; c_long slave; struct soap* soap; slave = -1; soap = NULL; if(argc == 3) { name = argv[1]; config = argv[2]; cms = cms_serviceNew(name,config); if(cms != NULL){ os_signalHandlerExitRequestHandle erh = os_signalHandlerExitRequestHandleNil; if(!os_serviceGetSingleProcess()){ erh = os_signalHandlerRegisterExitRequestCallback(exitRequestHandler, NULL, NULL, NULL, cms); } while(cms->terminate == FALSE){ while( (slave < 0) && (cms->terminate == FALSE)){ slave = soap_accept(cms->soap); } if (slave < 0) { if(cms->configuration->verbosity > 0){ /* soap_accept is likely to return -1 when the soap service is shutdown * so should be an INFO message here rather than a WARNING */ OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "not accepting requests."); } cms->terminate = TRUE; } else { if(cms->configuration->verbosity > 6){ OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "Thread %d accepts connection from IP %d.%d.%d.%d\n", slave, (int)(cms->soap->ip>>24)&0xFF, (int)(cms->soap->ip>>16)&0xFF, (int)(cms->soap->ip>>8)&0xFF, (int)(cms->soap->ip&0xFF)); } client = cms_serviceLookupClient(cms); if(client != NULL){ soap = soap_copy(cms->soap); if (soap == NULL) { if(cms->configuration->verbosity > 0){ OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "Could not allocate SOAP environment."); } cms->terminate = TRUE; } else { soap->socket = slave; slave = -1; success = cms_clientHandleRequest(client, soap); if(success == FALSE){ soap->error = soap_receiver_fault(soap, "Could not handle request.", NULL); soap_send_fault(soap); soap_destroy(soap); soap_end(soap); soap_done(soap); os_free(soap); soap = NULL; } } } else { if(cms->configuration->verbosity > 3){ OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "Maximum number of clients reached."); } if (soap == NULL) { if(cms->configuration->verbosity > 0){ OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "Could not allocate SOAP environment."); } cms->terminate = TRUE; } else { soap->socket = slave; slave = -1; soap->error = soap_receiver_fault(soap, "Maximum number of clients reached.", NULL); soap_send_fault(soap); soap_destroy(soap); soap_end(soap); soap_done(soap); soap = NULL; } } } }
void process_requests(int server_s, struct soap *soap)/*by SeanHou*/ { /* :TODO:Monday, December 01, 2014 11:17:36 HKT:SeanHou: */ int OnvifEN = 0; int lookupindex = 0; char service_uri[100] = ""; memset((void*)&soap->peer, 0, sizeof(soap->peer)); soap->socket = SOAP_INVALID_SOCKET; soap->error = SOAP_OK; soap->errmode = 0; soap->keep_alive = 0; fprintf(stderr, "Warning:" \ "(==>%s).\n", __func__); /* :TODO:End--- */ int retval = 0; request *current, *trailer; if (pending_requests) { get_request(server_s); #ifdef ORIGINAL_BEHAVIOR pending_requests = 0; #endif } current = request_ready; while (current) { /* :TODO:Monday, December 01, 2014 11:18:42 HKT:SeanHou: juge is onvif */ OnvifEN = isonvif(current->client_stream, service_uri, &lookupindex); if(OnvifEN == 1) { fprintf(stderr, "[boa:onvif] Warning: is onvif line[%d]remote port[%d]h2ns[%d]remote ip[%s]\n", __LINE__, current->remote_port, htons(current->remote_port), current->remote_ip_addr); struct sockaddr_in onvif_client_addr; memset(&onvif_client_addr, 0, sizeof(onvif_client_addr)); onvif_client_addr.sin_family = AF_INET; onvif_client_addr.sin_port = htons(current->remote_port);//随机端口 onvif_client_addr.sin_addr.s_addr = inet_addr(current->remote_ip_addr);// soap->socket = current->fd; soap->peer = onvif_client_addr; if (soap_valid_socket(soap->socket)) { soap->ip = ntohl(soap->peer.sin_addr.s_addr); soap->port = (int)ntohs(soap->peer.sin_port); soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0); } g_onvif_buffer = (char *)soap_malloc(soap, sizeof(current->client_stream)); strcpy(g_onvif_buffer, current->client_stream);//mark soap_begin_recv(soap); if (soap_envelope_begin_in(soap)) { soap_send_fault(soap); } if (soap_recv_header(soap)) { soap_send_fault(soap); } if (soap_body_begin_in(soap)) { soap_send_fault(soap); } int errorCode = 0; if (errorCode = soap_serve_request(soap)) { fprintf(stderr, "[boa:onvif]soap_serve_request fail, errorCode %d \n", errorCode); soap_send_fault(soap); } memset(current->client_stream, 0, CLIENT_STREAM_SIZE ); soap_dealloc(soap, NULL); soap_destroy(soap); soap_end(soap); current->status = DONE; close(soap->socket); continue; } /* :TODO:End--- */ time(¤t_time); if (current->buffer_end && /* there is data in the buffer */ current->status != DEAD && current->status != DONE) { retval = req_flush(current); /* * retval can be -2=error, -1=blocked, or bytes left */ if (retval == -2) { /* error */ current->status = DEAD; retval = 0; } else if (retval >= 0) { /* notice the >= which is different from below? Here, we may just be flushing headers. We don't want to return 0 because we are not DONE or DEAD */ retval = 1; } } else { switch (current->status) { case READ_HEADER: case ONE_CR: case ONE_LF: case TWO_CR: retval = read_header(current); break; case BODY_READ: retval = read_body(current); break; case BODY_WRITE: retval = write_body(current); break; case WRITE: retval = process_get(current); break; case PIPE_READ: retval = read_from_pipe(current); break; case PIPE_WRITE: retval = write_from_pipe(current); break; case DONE: /* a non-status that will terminate the request */ retval = req_flush(current); /* * retval can be -2=error, -1=blocked, or bytes left */ if (retval == -2) { /* error */ current->status = DEAD; retval = 0; } else if (retval > 0) { retval = 1; } break; case DEAD: retval = 0; current->buffer_end = 0; SQUASH_KA(current); break; default: retval = 0; fprintf(stderr, "Unknown status (%d), " "closing!\n", current->status); current->status = DEAD; break; } } if (sigterm_flag) SQUASH_KA(current); /* we put this here instead of after the switch so that * if we are on the last request, and get_request is successful, * current->next is valid! */ if (pending_requests) get_request(server_s); switch (retval) { case -1: /* request blocked */ trailer = current; current = current->next; block_request(trailer); break; case 0: /* request complete */ current->time_last = current_time; trailer = current; current = current->next; free_request(&request_ready, trailer); break; case 1: /* more to do */ current->time_last = current_time; current = current->next; break; default: log_error_time(); fprintf(stderr, "Unknown retval in process.c - " "Status: %d, retval: %d\n", current->status, retval); current = current->next; break; } } }