ngwt__Note *IncidenceConverter::convertToNote(KCal::Journal *journal) { if(!journal) return 0; ngwt__Note *note = soap_new_ngwt__Note(soap(), -1); note->startDate = 0; if(!convertToCalendarItem(journal, note)) { soap_dealloc(soap(), note); return 0; } if(journal->doesFloat()) { if(journal->dtStart().isValid()) note->startDate = qDateToString(journal->dtStart().date()); } else { if(journal->dtStart().isValid()) note->startDate = qDateTimeToString(journal->dtStart(), mTimezone); } if(!note->subject) note->subject = qStringToString(QString("NO SUBJECT")); return note; }
ngwt__Task* IncidenceConverter::convertToTask( KCal::Todo* todo ) { if ( !todo ) return 0; ngwt__Task* task = soap_new_ngwt__Task( soap(), -1 ); task->startDate = 0; task->dueDate = 0; task->assignedDate = 0; task->taskPriority = 0; task->completed = 0; if ( !convertToCalendarItem( todo, task ) ) { soap_dealloc( soap(), task ); return 0; } if ( todo->dtStart().isValid() ) task->startDate = kDateTimeToString( todo->dtStart(), mTimeSpec ); if ( todo->hasDueDate() ) { task->dueDate = kDateTimeToString( todo->dtDue() ); } // FIXME: Restore custom priorities QString priority = QString::number( todo->priority() ); task->taskPriority = qStringToString( priority ); task->completed = (bool*)soap_malloc( soap(), 1 ); if ( todo->isCompleted() ) (*task->completed) = true; else (*task->completed) = false; return task; }
ngwt__Appointment *IncidenceConverter::convertToAppointment(KCal::Event *event) { kdDebug() << "IncidenceConverter::convertToAppointment()" << endl; if(!event) return 0; ngwt__Appointment *appointment = soap_new_ngwt__Appointment(soap(), -1); appointment->startDate = 0; appointment->endDate = 0; appointment->startDay = 0; appointment->endDay = 0; appointment->acceptLevel = 0; appointment->alarm = 0; appointment->allDayEvent = 0; appointment->place = 0; appointment->timezone = 0; if(!convertToCalendarItem(event, appointment)) { soap_dealloc(soap(), appointment); return 0; } if(event->doesFloat()) { bool *allDayEvent = (bool *)soap_malloc(soap(), 1); (*allDayEvent) = true; appointment->allDayEvent = allDayEvent; if(event->dtStart().isValid()) { /* kdDebug() << " convertToAppointment() raw start date: " << event->dtStart().toString() << endl;*/ QDateTime start = event->dtStart(); start.setTime(QTime(0, 0, 0)); appointment->startDate = qDateTimeToChar(start, mTimezone); //appointment->startDay = qDateToString( event->dtStart().date()/*.addDays( -1 )*/ ); /* kdDebug() << " converted start date: " << appointment->startDate << endl;*/ } else kdDebug() << " event start date not valid " << endl; if(event->hasEndDate()) { // kdDebug() << " convertToAppointment() raw end date: " << event->dtEnd().toString() << endl; QDateTime end = event->dtEnd(); end = end.addDays(1); end.setTime(QTime(0, 0, 0)); appointment->endDate = qDateTimeToChar(end, mTimezone); //appointment->endDay = qDateToString( event->dtEnd().date() ); // kdDebug() << " converted end date:" << appointment->endDate << endl; } else kdDebug() << " event end date not valid " << endl; } else { appointment->allDayEvent = 0; if(event->dtStart().isValid()) appointment->startDate = qDateTimeToChar(event->dtStart(), mTimezone); if(event->hasEndDate()) appointment->endDate = qDateTimeToChar(event->dtEnd(), mTimezone); } enum ngwt__AcceptLevel *al = (enum ngwt__AcceptLevel *)soap_malloc(soap(), sizeof(enum ngwt__AcceptLevel)); *al = Busy; appointment->acceptLevel = al; KCal::Alarm::List alarms = event->alarms(); if(!alarms.isEmpty()) { ngwt__Alarm *alarm = soap_new_ngwt__Alarm(soap(), -1); alarm->__item = alarms.first()->startOffset().asSeconds() * -1; bool *enabled = (bool *)soap_malloc(soap(), sizeof(bool)); *enabled = alarms.first()->enabled(); alarm->enabled = enabled; appointment->alarm = alarm; } else appointment->alarm = 0; if(!event->location().isEmpty()) { std::string *location = qStringToString(event->location()); appointment->place = location; } else appointment->place = 0; appointment->timezone = 0; return appointment; }
/* * 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 }
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; } } }