void xmlrpc_server_httpsys( xmlrpc_env * const envP, const xmlrpc_server_httpsys_parms * const parmsP, unsigned int const parm_size ) { ULONG retCode; HANDLE hReqQueue = NULL; HTTPAPI_VERSION HttpApiVersion = HTTPAPI_VERSION_1; WCHAR wszURL[35]; XMLRPC_ASSERT_ENV_OK(envP); if (parm_size < XMLRPC_HSSIZE(authfn)) { xmlrpc_faultf(envP, "You must specify members at least up through " "'authfn' in the server parameters argument. " "That would mean the parameter size would be >= %u " "but you specified a size of %u", XMLRPC_HSSIZE(authfn), parm_size); return; } //Set logging options if (parmsP->logLevel>0) g_bDebug=TRUE; else g_bDebug=FALSE; if (parmsP->logLevel>1) g_bDebugString=TRUE; else g_bDebugString=FALSE; if (!parmsP->logFile) g_bDebug=FALSE; else StringCchPrintfA(g_fLogFile,MAX_PATH,parmsP->logFile); //construct the URL we are listening on if (parmsP->useSSL!=0) StringCchPrintf(wszURL,35,L"https://+:%u/RPC2",parmsP->portNum); else StringCchPrintf(wszURL,35,L"http://+:%u/RPC2",parmsP->portNum); global_registryP = parmsP->registryP; // Initialize HTTP APIs. retCode = HttpInitialize(HttpApiVersion, HTTP_INITIALIZE_SERVER, // Flags NULL // Reserved ); if (retCode != NO_ERROR) { xmlrpc_faultf(envP, "HttpInitialize failed with %lu", retCode); return; } // Create a Request Queue Handle retCode = HttpCreateHttpHandle(&hReqQueue, // Req Queue 0 // Reserved ); if (retCode != NO_ERROR) { xmlrpc_faultf(envP, "HttpCreateHttpHandle failed with %lu", retCode); goto CleanUp; } retCode = HttpAddUrl(hReqQueue, // Req Queue wszURL, // Fully qualified URL NULL // Reserved ); if (retCode != NO_ERROR) { xmlrpc_faultf(envP, "HttpAddUrl failed with %lu", retCode); goto CleanUp; } TraceW(L"we are listening for requests on the following url: %ws", wszURL); // Loop while receiving requests for(;;) { TraceW(L"Calling DoReceiveRequests()"); retCode = DoReceiveRequests(hReqQueue, parmsP); if(NO_ERROR == retCode) { TraceW(L"DoReceiveRequests() returned NO_ERROR, breaking"); break; } } CleanUp: TraceW(L"Tearing down the server.", wszURL); // Call HttpRemoveUrl for the URL that we added. HttpRemoveUrl( hReqQueue, wszURL ); // Close the Request Queue handle. if(hReqQueue) CloseHandle(hReqQueue); // Call HttpTerminate. HttpTerminate(HTTP_INITIALIZE_SERVER, NULL); return; }
DWORD CreateHttpListener( OUT PHTTP_LISTENER* httpListener ) { ULONG result; PHTTP_LISTENER _listener = (PHTTP_LISTENER)ALLOC_MEM(sizeof(HTTP_LISTENER)); ZeroMemory(_listener, sizeof(HTTP_LISTENER)); (*httpListener) = _listener; _listener->hRequestQueue = NULL; _listener->RequestQueueLength = 5000; // Default request queue length; _listener->errorCode = 0; _listener->urls = NULL; _listener->pthreadPoolIO = NULL; _listener->State = HTTP_LISTENER_STATE_FAULTED; _listener->stats = (PLISTENER_STATS)_aligned_malloc(sizeof(LISTENER_STATS),MEMORY_ALLOCATION_ALIGNMENT); HTTPAPI_VERSION HttpApiVersion = HTTPAPI_VERSION_2; // // Initialize HTTP APIs. // result = HttpInitialize( HttpApiVersion, HTTP_INITIALIZE_SERVER, // Flags NULL // Reserved ); if (result != NO_ERROR) { DEBUG_ASSERT(false); LOG_ERROR(L"\nHttpInitialize failed with %lu", result); } if(result == NO_ERROR) { result = HttpCreateServerSession(HttpApiVersion, &_listener->SessionId, NULL); if(result) { LOG_ERROR(L"\nHttpCreateServerSession failed with %lu", result); } } if(result == NO_ERROR) { result = HttpCreateRequestQueue(HttpApiVersion, NULL, NULL, 0, &_listener->hRequestQueue); if(result) { LOG_ERROR(L"\nHttpCreateRequestQueue failed with %lu", result); } } if(result == NO_ERROR) { result = HttpSetRequestQueueProperty(_listener->hRequestQueue, HttpServerQueueLengthProperty, &_listener->RequestQueueLength, sizeof(_listener->RequestQueueLength), NULL, NULL); if(result) { LOG_ERROR(L"\nHttpSetRequestQueueProperty failed with %lu", result); } } if(result == NO_ERROR) { if(SetFileCompletionNotificationModes(_listener->hRequestQueue, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | FILE_SKIP_SET_EVENT_ON_HANDLE) == FALSE) { result = GetLastError(); } } if(result == NO_ERROR) { result = HttpListenerInitializeThreadPool(_listener); } if(result == NO_ERROR) { _listener->pthreadPoolIO = CreateThreadpoolIo(_listener->hRequestQueue, HttpListenerDemuxer, (void*)_listener, &_listener->tpEnvironment); } InitializeIOContextCache(); InitializeHttpInputQueue(_listener); _listener->errorCode = result; return _listener->errorCode; }
BOOL InitializeHttpServer( PWCHAR pwszUrlPathToListenFor, PWCHAR pwszRootDirectory, PSERVER_CONTEXT pServerContext ) { ULONG ulResult; HRESULT hResult; hResult = StringCbCopyW( pServerContext->wszRootDirectory, MAX_STR_SIZE, pwszRootDirectory); if (FAILED(hResult)) { fprintf(stderr, "Invalid command line arguments. Application stopped.\n"); return FALSE; } ulResult = HttpInitialize( g_HttpApiVersion, HTTP_INITIALIZE_SERVER, NULL); if (ulResult != NO_ERROR) { fprintf(stderr, "HttpInitialized failed\n"); return FALSE; } pServerContext->bHttpInit = TRUE; ulResult = HttpCreateServerSession( g_HttpApiVersion, &(pServerContext->sessionId), 0); if (ulResult != NO_ERROR) { fprintf(stderr, "HttpCreateServerSession failed\n"); return FALSE; } ulResult = HttpCreateUrlGroup( pServerContext->sessionId, &(pServerContext->urlGroupId), 0); if (ulResult != NO_ERROR) { fprintf(stderr, "HttpCreateUrlGroup failed\n"); return FALSE; } ulResult = HttpAddUrlToUrlGroup( pServerContext->urlGroupId, pwszUrlPathToListenFor, (HTTP_URL_CONTEXT) NULL, 0); if (ulResult != NO_ERROR) { fwprintf(stderr, L"HttpAddUrlToUrlGroup failed with code 0x%x for url %s\n", ulResult, pwszUrlPathToListenFor); return FALSE; } return TRUE; }