void SmugMug::WebService::_slotHttpRequestFinished (int id, bool error) { qDebug () << "Request Finished: " << id; if (error) { _logHttpError (QString ("Request Finished: %1").arg (id)); } else { emit dataAvailable (_dataIn); bool err = false; QDomDocument doc; if (doc.setContent (_dataIn)) { QDomElement root = doc.documentElement(); if (!_isResponseValid (root)) { err = true; _responseFailed (root); } _handleResponse (id, root, err); } emit actionFinished (); qDebug () << "actionFinished: " << id; } }
INT32 _mongoSession::run() { INT32 rc = SDB_OK ; BOOLEAN bigEndian = FALSE ; UINT32 msgSize = 0 ; UINT32 headerLen = sizeof( mongoMsgHeader ) - sizeof( INT32 ) ; INT32 bodyLen = 0 ; engine::pmdEDUMgr *pmdEDUMgr = NULL ; CHAR *pBuff = NULL ; const CHAR *pBody = NULL ; const CHAR *pInMsg = NULL ; engine::monDBCB *mondbcb = engine::pmdGetKRCB()->getMonDBCB() ; if ( !_pEDUCB ) { rc = SDB_SYS ; goto error ; } pmdEDUMgr = _pEDUCB->getEDUMgr() ; bigEndian = checkBigEndian() ; while ( !_pEDUCB->isDisconnected() && !_socket.isClosed() ) { _pEDUCB->resetInterrupt() ; _pEDUCB->resetInfo( engine::EDU_INFO_ERROR ) ; _pEDUCB->resetLsn() ; rc = recvData( (CHAR*)&msgSize, sizeof(UINT32) ) ; if ( rc ) { if ( SDB_APP_FORCED != rc ) { PD_LOG( PDERROR, "Session[%s] failed to recv msg size, " "rc: %d", sessionName(), rc ) ; } break ; } if ( bigEndian ) { } if ( msgSize < headerLen || msgSize > SDB_MAX_MSG_LENGTH ) { PD_LOG( PDERROR, "Session[%s] recv msg size[%d] is less than " "mongoMsgHeader size[%d] or more than max msg size[%d]", sessionName(), msgSize, sizeof( mongoMsgHeader ), SDB_MAX_MSG_LENGTH ) ; rc = SDB_INVALIDARG ; break ; } else { pBuff = getBuff( msgSize + 1 ) ; if ( !pBuff ) { rc = SDB_OOM ; break ; } *(UINT32*)pBuff = msgSize ; rc = recvData( pBuff + sizeof(UINT32), msgSize - sizeof(UINT32) ) ; if ( rc ) { if ( SDB_APP_FORCED != rc ) { PD_LOG( PDERROR, "Session[%s] failed to recv rest msg, rc: %d", sessionName(), rc ) ; } break ; } pBuff[ msgSize ] = 0 ; { _resetBuffers() ; _converter.loadFrom( pBuff, msgSize ) ; rc = _converter.convert( _inBuffer ) ; if ( SDB_OK != rc && SDB_OPTION_NOT_SUPPORT != rc) { goto error ; } _pEDUCB->incEventCount() ; mondbcb->addReceiveNum() ; if ( SDB_OK != ( rc = pmdEDUMgr->activateEDU( _pEDUCB ) ) ) { PD_LOG( PDERROR, "Session[%s] activate edu failed, rc: %d", sessionName(), rc ) ; goto error ; } if ( _preProcessMsg( _converter.getParser(), _resource, _contextBuff ) ) { goto reply ; } pInMsg = _inBuffer.data() ; while ( NULL != pInMsg ) { rc = _processMsg( pInMsg ) ; if ( SDB_OK == rc ) { _authed = TRUE ; } rc = _converter.reConvert( _inBuffer, &_replyHeader ) ; if ( SDB_OK != rc ) { goto reply ; } else { if ( !_inBuffer.empty() ) { _contextBuff.release() ; pInMsg = _inBuffer.data() ; } else { pInMsg = NULL ; } } } reply: _handleResponse( _converter.getOpType(), _contextBuff ) ; pBody = _contextBuff.data() ; bodyLen = _contextBuff.size() ; INT32 rcTmp = _reply( &_replyHeader, pBody, bodyLen ) ; if ( rcTmp ) { PD_LOG( PDERROR, "Session[%s] failed to send response," "rc: %d", sessionName(), rcTmp ) ; goto error ; } pBody = NULL ; bodyLen = 0 ; _contextBuff.release() ; if ( SDB_OK != ( rc = pmdEDUMgr->waitEDU( _pEDUCB ) ) ) { PD_LOG( PDERROR, "Session[%s] wait edu failed, rc: %d", sessionName(), rc ) ; goto error ; } } } } // end while done: disconnect() ; return rc ; error: goto done ; }
/** Executes the command using HTTP. A CIM request encoded in XML is read from the input, and encapsulated in an HTTP request message. A channel is obtained for an HTTP connection, and the message is written to the channel. The response is written to the specified outPrintWriter, and consists of the CIM response encoded in XML. @param outPrintWriter the ostream to which output should be written @param errPrintWriter the ostream to which error output should be written @exception WbemExecException if an error is encountered in executing the command */ void WbemExecCommand::_executeHttp (ostream& outPrintWriter, ostream& errPrintWriter) { Uint32 size; Buffer content; Buffer contentCopy; Buffer message; Buffer httpHeaders; Buffer httpResponse; #ifdef PEGASUS_WMIMAPPER WMIWbemExecClient client; #else WbemExecClient client; #endif client.setTimeout( _timeout ); // // Check for invalid combination of options // The M-POST method may not be used with HTTP/1.0 // if ((!_useHTTP11) && (_useMPost)) { throw WbemExecException(WbemExecException::MPOST_HTTP10_INVALID); } // // If no hostName specified // Default to local host // if (!_hostNameSet) { _hostName = System::getHostName(); } if( !_portNumberSet ) { if( _useSSL ) { _portNumber = System::lookupPort( WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT ); } else { _portNumber = System::lookupPort( WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT ); } char buffer[32]; sprintf( buffer, "%lu", (unsigned long) _portNumber ); _portNumberStr = buffer; } // // Get XML request from input file // if (_inputFilePathSet) { // // Check that input file exists // if (!FileSystem::exists (_inputFilePath)) { throw WbemExecException(WbemExecException::INPUT_FILE_NONEXISTENT); } // // Check that input file is readable // if (!FileSystem::canRead (_inputFilePath)) { throw WbemExecException(WbemExecException::INPUT_FILE_NOT_READABLE); } // // Check that file is not empty // FileSystem::getFileSize (_inputFilePath, size); if (size == 0) { throw WbemExecException(WbemExecException::NO_INPUT); } // // Read from input file // try { FileSystem::loadFileToMemory (content, _inputFilePath); } catch (const CannotOpenFile&) { throw WbemExecException(WbemExecException::INPUT_FILE_CANNOT_OPEN); } } else { // // Read from cin // // (GetLine is defined in Pegasus/Common/String.[h,cpp], but is // not a class member.) // String line; while (GetLine (cin, line)) { content << line << '\n'; } if (content.size () == 0) { // // No input // throw WbemExecException(WbemExecException::NO_INPUT); } } // // Make a copy of the content because the XmlParser constructor // modifies the text // contentCopy << content; XmlParser parser ((char*) contentCopy.getData ()); try { _connectToServer( client, outPrintWriter ); // // Encapsulate XML request in an HTTP request // String hostName; if (_hostNameSet && _hostName.size()) { hostName = _hostName + String(":") + _portNumberStr; } message = XMLProcess::encapsulate( parser, hostName, _useMPost, _useHTTP11, content, httpHeaders ); if (_debugOutput1) { outPrintWriter << message.getData () << endl; } } catch (const XmlException& xe) { throw WbemExecException( WbemExecException::INVALID_XML, xe.getMessage()); } catch (const WbemExecException&) { throw; } catch (const Exception& ex) { throw WbemExecException( WbemExecException::CONNECT_FAIL, ex.getMessage()); } try { httpResponse = client.issueRequest( message ); } catch (const ConnectionTimeoutException&) { throw WbemExecException(WbemExecException::TIMED_OUT); } catch (const UnauthorizedAccess& ex) { throw WbemExecException( WbemExecException::CONNECT_FAIL, ex.getMessage()); } catch (const Exception& ex) { throw WbemExecException( WbemExecException::CONNECT_FAIL, ex.getMessage()); } // // Process the response message // _handleResponse( httpResponse, outPrintWriter, errPrintWriter ); }