/* ** Read data from client to CGI script ** ** IN: ** uint32_t ses_handle - handle to session used for reading ** char* buffer - user buffer to read data to ** uint32_t length - size of buffer in bytes ** ** OUT: ** none ** ** Return Value: ** uint32_t - Number of bytes read */ uint32_t HTTPSRV_cgi_read(uint32_t ses_handle, char* buffer, uint32_t length) { HTTPSRV_SESSION_STRUCT* session = (HTTPSRV_SESSION_STRUCT*) ses_handle; uint32_t retval; if ( (session == NULL) || (buffer == NULL) || (length == 0) ) { return(0); } retval = httpsrv_read(session, buffer, length); if (retval > 0) { RTCS_ASSERT(retval <= session->request.content_length); if (retval <= session->request.content_length) { session->request.content_length -= retval; } } else { if (RTCS_geterror(session->sock) == RTCSERR_TCP_TIMED_OUT) { retval = 0; } } session->time = RTCS_time_get(); return(retval); }
/* ** Function for CGI request processing ** ** IN: ** HTTPSRV_SESSION_STRUCT* session - session structure pointer. ** HTTPSRV_STRUCT* server - pointer to server structure (needed for session parameters). ** char* cgi_name - name of cgi function. ** ** OUT: ** none ** ** Return Value: ** none */ void httpsrv_process_cgi(HTTPSRV_STRUCT *server, HTTPSRV_SESSION_STRUCT *session, char* cgi_name) { HTTPSRV_SCRIPT_MSG* msg_ptr; msg_ptr = _msg_alloc(server->script_msg_pool); if (msg_ptr == NULL) { /* Out of memory - report server error */ session->response.status_code = HTTPSRV_CODE_INTERNAL_ERROR; return; } msg_ptr->header.TARGET_QID = server->script_msgq; msg_ptr->header.SOURCE_QID = server->script_msgq; msg_ptr->header.SIZE = sizeof(HTTPSRV_SCRIPT_MSG); msg_ptr->session = session; msg_ptr->type = HTTPSRV_CGI_CALLBACK; msg_ptr->name = cgi_name; msg_ptr->ses_tid = _task_get_id(); _msgq_send(msg_ptr); /* wait until CGI is processed */ _task_block(); /* ** There is some unread content from client after CGI finished. ** It must be read and discarded if we have keep-alive enabled ** so it does not affect next request. */ if (session->request.content_length) { char *tmp = NULL; tmp = _mem_alloc(HTTPSRV_TMP_BUFFER_SIZE); if (tmp != NULL) { uint32_t length = session->request.content_length; while(length) { uint32_t retval; retval = httpsrv_read(session, tmp, HTTPSRV_TMP_BUFFER_SIZE); if (!retval) { break; } length -= retval; } _mem_free(tmp); session->request.content_length = 0; } } return; }
/* ** Read data from client to CGI script ** ** IN: ** uint_32 ses_handle - handle to session used for reading ** char* buffer - user buffer to read data to ** uint_32 length - size of buffer in bytes ** ** OUT: ** none ** ** Return Value: ** uint_32 - Number of bytes read */ uint_32 HTTPSRV_cgi_read(uint_32 ses_handle, char* buffer, uint_32 length) { HTTPSRV_SESSION_STRUCT* session = (HTTPSRV_SESSION_STRUCT*) ses_handle; uint_32 retval; retval = httpsrv_read(session, buffer, length); if (retval > 0) { session->request.content_length -= retval; } return(retval); }