inline void SendResult(QTSS_StreamRef inStream) { SendHeader(inStream); if (sAdminPtr != NULL) sAdminPtr->RespondToQuery(inStream,sQueryPtr,sQueryPtr->GetRootID()); }
bool CClient::Send(const void *buffer, size_t len, int reply) { CHeader Header; ssize_t res; bool ret; /* Setup header */ Header.AddReply(reply); Header.AddDate(); Header.AddServer(); if (len > 0) Header.AddLength(len); Header.AddEnd(); /* Send header */ ret = SendHeader(Header); if (!ret) return false; /* Send data */ if (len > 0) { res = Write(buffer, len); if (res <= 0) return false; } return true; }
/** * @brief * Send a file to the client */ void HttpServerConnection::SendFile(EHttpStatus nStatus, const String &sFilename) { // Open file File cFile(sFilename); if (cFile.Open(File::FileRead)) { // Send header SendHeader(nStatus, MimeTypeManager::GetMimeType(sFilename), cFile.GetSize()); // Read in chunks of 256 bytes char szBuffer[256]; while (!cFile.IsEof()) { // Read from file const uint32 nSize = cFile.Read(szBuffer, 1, 255); // Send if (nSize > 0) Send(szBuffer, nSize); } // Close file cFile.Close(); // Close connection Disconnect(); } else { // Error: File not found SendError(Http_404_NotFound); } }
void Http::SendFile(char *path, struct stat *st) { const char *mime_type = GetMimeType(strrchr(path, '.')); SendHeader(mime_type, st->st_size, 200); if (strcmp(request.request_method, "HEAD") != 0) SendFileStream(path, st); }
void PostScript::DoProlog () { vector<string>::iterator it; for (it = headers.begin(); it != headers.end(); ++ it) { SendHeader (it->c_str()); } DoDefinitions (); }
/** * @brief * Send data to the client */ void HttpServerConnection::SendData(EHttpStatus nStatus, const String &sMimeType, const String &sContent) { // Send header SendHeader(nStatus, sMimeType, sContent.GetLength()); // Send page Send(sContent); // Close connection Disconnect(); }
int HttpResponseX::Write(const char * fmt, ...) { if(!m_header_sended) { SendHeader(); } va_list args; va_start(args, fmt); int count = FCGX_VFPrintF(request_->GetFCGX_Request()->out, fmt, args); va_end(args); return count; }
uint32_t NormalUart::Send(uint32_t *Data, uint32_t Length) { SendHeader(&mH); for (uint32_t i = 0; i < Length; ++i){ SendInt(&mH,Data[i]); } ChangeEndian(Data,Length*sizeof(uint32_t)); crcInit(); crc checksum = crcFast((unsigned char*)Data,Length*sizeof(uint32_t)); //ChangeEndian(&checksum,1); SendInt(&mH,checksum); return Length; }
unsigned int WINAPI WorkerHealthThread(VOID *pParam) { ST_CLIENT_SOCK *pstClientSock = NULL; pstClientSock = (ST_CLIENT_SOCK *)pParam; SOCKET sockServer; sockServer = pstClientSock->sockServer; DWORD dwRet; WriteLog(E_LOG_LEVEL_DEBUG, "Start Worker Health Thread"); while (g_bThreadExit) { WriteLog(E_LOG_LEVEL_DEBUG, "One cycle start, continue"); /* each 1 minute, send HealthData to Server */ ::Sleep(SLEEP_TIME); /* First, send Header */ dwRet = SendHeader(sockServer); if (dwRet != E_RET_SUCCESS) { continue; } /* Second, send Health Data */ WriteLog(E_LOG_LEVEL_DEBUG, "Send Health Data to Server"); dwRet = SendHealthData(sockServer); if (dwRet != E_RET_SUCCESS) { continue; } /* Third, receive Health Data not yet!! */ WriteLog(E_LOG_LEVEL_DEBUG, "Recv Health Data from server"); dwRet = RecvHealthData(sockServer); if (dwRet != E_RET_SUCCESS) { continue; } WriteLog(E_LOG_LEVEL_DEBUG, "One cycle end, continue"); } return 0; }
void TDCLInspectorCommand::SendCommand( TDCLStream* inStream, ProgressFuncPtr inProgressFuncPtr /* = nil */, void* inRefCon /* = nil */ ) { KUInt32 theLength = SendHeader( inStream ); KDEBUG2( "<< Command %.8X, length %i", (unsigned int) GetCommand(), (int) GetLength() ); if (inProgressFuncPtr) { (*inProgressFuncPtr)( inRefCon, ((double) 16) / ((double) (16 + theLength)) ); } if (theLength) { SendBody( inStream, theLength, inProgressFuncPtr, inRefCon ); } inStream->FlushOutput(); if (inProgressFuncPtr) { (*inProgressFuncPtr)( inRefCon, 1.0 ); } }
bool CHttpProtocol::Connect() { SOCKADDR_IN SockAddr; PREQUEST pReq = new REQUEST; if (pReq == NULL) { // 处理错误 printf("No memory for request\n"); return false; } pReq->Socket = INVALID_SOCKET; pReq->hFile = INVALID_HANDLE_VALUE; pReq->dwRecv = 0; pReq->dwSend = 0; // Accept a client socket pReq->Socket = accept(ListenSocket, (LPSOCKADDR)&SockAddr, NULL); // No longer need server socket closesocket(ListenSocket); if (pReq->Socket == INVALID_SOCKET) { printf("accept failed: %d\n", WSAGetLastError()); closesocket(ListenSocket); WSACleanup(); return false; } // 将客户端网络地址转换为用点分割的IP地址 printf("%s Connecting on socket:%d\n", inet_ntoa(SockAddr.sin_addr), pReq->Socket); char buf[DATA_BUFSIZE] = ""; bool nRet; // 接收request data if (!RecvRequest(pReq, buf, sizeof(buf))) { Disconnect(pReq); delete pReq; return false; } // 分析request信息 Analyse(pReq, buf); if(!strcmp(HTTP_STATUS_NOTIMPLEMENTED, pReq->StatuCodeReason)) { printf("Request method not implemented\n"); return false; } // 生成并返回头部 if(!SendHeader(pReq)) { printf("Send header failed\n"); return false; } // 向client传送数据 if(pReq->nMethod == METHOD_GET) SendFile(pReq); Disconnect(pReq); delete pReq; return true; }
QTSS_Error FilterRequest(QTSS_Filter_Params* inParams) { if (NULL == inParams || NULL == inParams->inRTSPSession || NULL == inParams->inRTSPRequest) { Assert(0); return QTSS_NoErr; } OSMutexLocker locker(sAdminMutex); //check to see if we should handle this request. Invokation is triggered //by a "GET /" request QTSS_Error err = QTSS_NoErr; QTSS_RTSPRequestObject theRequest = inParams->inRTSPRequest; UInt32 paramLen = sizeof(sSessID); err = QTSS_GetValue(inParams->inRTSPSession, qtssRTSPSesID, 0, (void*)&sSessID, ¶mLen); if (err != QTSS_NoErr) return QTSS_NoErr; StrPtrLen theFullRequest; err = QTSS_GetValuePtr(theRequest, qtssRTSPReqFullRequest, 0, (void**)&theFullRequest.Ptr, &theFullRequest.Len); if (err != QTSS_NoErr) return QTSS_NoErr; StringParser fullRequest(&theFullRequest); if ( !IsAdminRequest(&fullRequest) ) return QTSS_NoErr; if ( !AcceptSession(inParams->inRTSPSession) ) { (void)QTSS_Write(inParams->inRTSPRequest, sPermissionDeniedHeader, ::strlen(sPermissionDeniedHeader), NULL, 0); (void)QTSS_Write(inParams->inRTSPRequest, sHTMLBody, ::strlen(sHTMLBody), NULL, 0); KeepSession(theRequest,false); return QTSS_NoErr; } if(!GetRequestAuthenticatedState(inParams)) // must authenticate before handling { if(QTSS_IsGlobalLocked()) // must NOT be global locked return QTSS_RequestFailed; if (!IsAuthentic(inParams,&fullRequest)) { (void)QTSS_Write(inParams->inRTSPRequest, sUnauthorizedResponseHeader, ::strlen(sUnauthorizedResponseHeader), NULL, 0); (void)QTSS_Write(inParams->inRTSPRequest, sHTMLBody, ::strlen(sHTMLBody), NULL, 0); KeepSession(theRequest,false); return QTSS_NoErr; } } if (GetRequestFlushState(inParams)) { StillFlushing(inParams,true); return QTSS_NoErr; } if (!QTSS_IsGlobalLocked()) { if (InWaitInterval(inParams)) return QTSS_NoErr; //qtss_printf("New Request Wait for GlobalLock session=%"_U32BITARG_"\n",sSessID); (void)QTSS_RequestGlobalLock(); KeepSession(theRequest,true); return QTSS_NoErr; } //qtss_printf("Handle request session=%"_U32BITARG_"\n",sSessID); APITests_DEBUG(); if (sQueryPtr != NULL) { delete sQueryPtr; sQueryPtr = NULL; } sQueryPtr = NEW QueryURI(&theFullRequest); if (sQueryPtr == NULL) return QTSS_NoErr; ShowQuery_DEBUG(); if (sAdminPtr != NULL) { delete sAdminPtr; sAdminPtr = NULL; } UInt32 result = sQueryPtr->EvalQuery(NULL, NULL); if (result == 0) do { if( ElementNode_CountPtrs() > 0) { ElementNode_ShowPtrs(); Assert(0); } GetQueryData(theRequest); SendResult(theRequest); delete sAdminPtr; sAdminPtr = NULL; if (sQueryPtr && !sQueryPtr->QueryHasReponse()) { UInt32 err = 404; (void) sQueryPtr->EvalQuery(&err,NULL); ReportErr(inParams, err); break; } if (sQueryPtr && sQueryPtr->QueryHasReponse()) { ReportErr(inParams, sQueryPtr->GetEvaluResult()); } if (sQueryPtr->fIsPref && sQueryPtr->GetEvaluResult() == 0) { QTSS_ServiceID id; (void) QTSS_IDForService(QTSS_REREAD_PREFS_SERVICE, &id); (void) QTSS_DoService(id, NULL); } } while(false); else { SendHeader(theRequest); ReportErr(inParams, sQueryPtr->GetEvaluResult()); } if (sQueryPtr != NULL) { delete sQueryPtr; sQueryPtr = NULL; } (void) StillFlushing(inParams,true); return QTSS_NoErr; }
bool CClient::SendFile(const char *filepath) { CFile File; CHeader Header; char buffer[BUF_MAXLEN]; size_t len; bool res; /* Open file */ res = File.Open(filepath); /* File not found */ if (!res) { /* Handle error */ HandleError(REPLY_NOENT); goto out; } /* Get file size */ len = File.Size(); /* No contents? */ if (!len) { /* Handle error */ HandleError(REPLY_INTERR); res = false; goto out; } /* Setup header */ Header.AddReply(REPLY_OK); Header.AddDate(); Header.AddServer(); Header.AddLength(len); Header.AddEnd(); /* Send header */ res = SendHeader(Header); if (!res) goto out; /* Read loop */ while (len) { ssize_t ret, size; /* Block size */ size = (len > BUF_MAXLEN) ? BUF_MAXLEN : len; /* Read block */ res = File.Read(buffer, size); if (!res) break; /* Send block */ ret = Write(buffer, size); if (ret != size) { res = false; break; } /* Update length */ len -= size; } out: /* Close file */ File.Close(); return res; }
size_t HttpResponseX::WriteByte(const void *buf, size_t buf_size){ if(!m_header_sended){ SendHeader(); } return FCGX_PutStr((const char *)buf, (int)buf_size, request_->GetFCGX_Request()->out ); }
int SenderExp(hash *data_table, char *code) { ksocket_t cli_fd; struct sockaddr_in srv_addr; char *temp = 0x00; int addr_len; int opt = 1; int i, r; //listNode *pCur = 0; #ifdef KSOCKET_ADDR_SAFE mm_segment_t oldfs; old_fs = get_fs(); set_fs(KERNEL_DS); #endif memset(&srv_addr, 0, sizeof(srv_addr)); srv_addr.sin_family = AF_INET; srv_addr.sin_port = htons(SERVER_PORT); srv_addr.sin_addr.s_addr = inet_addr(SERVER_ADDR); addr_len = sizeof(struct sockaddr_in); cli_fd = ksocket(AF_INET, SOCK_STREAM, 0); if(cli_fd == 0) { return -1; } if(ksetsockopt(cli_fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)) < 0) { return -1; } if(kconnect(cli_fd, (struct sockaddr *)&srv_addr, addr_len) < 0) { return -1; } temp = inet_ntoa(&srv_addr.sin_addr); printk("connected to : %s %d\n", temp, ntohs(srv_addr.sin_port)); kfree(temp); if(strcmp(code, "exp") == 0) { r = SendHeader(cli_fd, code, data_table); printk("hdr : %d\n", r); for(i=0; i<HASH_SIZE; i++) { listNode *cur = data_table->item[i].head; while(cur) { r = SendExpData(cli_fd, &(cur->data)); if (r <= 0) continue; printk("payload : %d\n", r); PrintData(&(cur->data)); cur = cur->next; } } } kclose(cli_fd); #ifdef KSOCKET_ADDR_SAFE set_fs(old_fs); #endif return 0; }