/* ** 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; }
void client_task ( uint32_t index ) { SERVER_MESSAGE_PTR msg_ptr; _queue_id client_qid; bool result; client_qid = _msgq_open((_queue_number)(CLIENT_QUEUE_BASE + index), 0); if (client_qid == 0) { printf("\nCould not open a client message queue\n"); _task_block(); } while (TRUE) { /*allocate a message*/ msg_ptr = (SERVER_MESSAGE_PTR)_msg_alloc(message_pool); if (msg_ptr == NULL) { printf("\nCould not allocate a message\n"); _task_block(); } msg_ptr->HEADER.SOURCE_QID = client_qid; msg_ptr->HEADER.TARGET_QID = _msgq_get_id(0, SERVER_QUEUE); msg_ptr->HEADER.SIZE = sizeof(MESSAGE_HEADER_STRUCT) + strlen((char *)msg_ptr->DATA) + 1; msg_ptr->DATA[0] = ('A'+ index); printf("Client Task %ld\n", index); result = _msgq_send(msg_ptr); if (result != TRUE) { printf("\nCould not send a message\n"); _task_block(); } /* wait for a return message */ msg_ptr = _msgq_receive(client_qid, 0); if (msg_ptr == NULL) { printf("\nCould not receive a message\n"); _task_block(); } /* free the message */ _msg_free(msg_ptr); } }
void Log(char_ptr msg) { LOG_MESSAGE_PTR msg_ptr; if (log_pool) { msg_ptr = (LOG_MESSAGE_PTR)_msg_alloc(log_pool); if (msg_ptr != NULL) { msg_ptr->HEADER.TARGET_QID = _msgq_get_id(0, LOG_QUEUE); strncpy(msg_ptr->MESSAGE,msg,LOG_MESSAGE_SIZE); _msgq_send(msg_ptr); } } }
void main_task(uint_32 dest_core) { _pool_id msgpool; THE_MESSAGE_PTR msg_ptr; _queue_id my_qid,temp_qid; uint_32 expected; printf("\n\n\nMain task started\n"); /* start aux core (M4) */ _bsp_aux_core_start((void*)0x3f000000); /* wait for P1 to boot */ _time_delay(1000); my_qid = _msgq_open(MAIN_QUEUE,0); msgpool = _msgpool_create(sizeof(THE_MESSAGE), 8, 8, 0); msg_ptr = (THE_MESSAGE_PTR)_msg_alloc(msgpool); if (msg_ptr != NULL) { msg_ptr->HEADER.TARGET_QID = _msgq_get_id((_processor_number) dest_core,RESPONDER_QUEUE); msg_ptr->HEADER.SOURCE_QID = my_qid; msg_ptr->DATA = 0; } while (msg_ptr != NULL) { expected = msg_ptr->DATA+1; printf("Main task sending\n"); _msgq_send(msg_ptr); printf("Main task receiving..."); msg_ptr = _msgq_receive(MSGQ_ANY_QUEUE, 0); printf("done\n"); if (msg_ptr != NULL) { printf("Message: Size=%x, SQID= %x, TQID=%x, DATA = %x\n", msg_ptr->HEADER.SIZE, msg_ptr->HEADER.SOURCE_QID, msg_ptr->HEADER.TARGET_QID, msg_ptr->DATA ); if (msg_ptr->HEADER.SIZE != sizeof(THE_MESSAGE)) { log_error("Message wrong size\n"); } else if (msg_ptr->DATA != expected) { log_error("Message data incorrect\n"); } temp_qid = msg_ptr->HEADER.SOURCE_QID; msg_ptr->HEADER.SOURCE_QID = msg_ptr->HEADER.TARGET_QID; msg_ptr->HEADER.TARGET_QID = temp_qid; msg_ptr->DATA++; } } log_error("Message alloc/receive failed\n"); }
void main_task ( uint32_t dummy ) { _pool_id msgpool; THE_MESSAGE_PTR msg_ptr; _queue_id qid; _queue_id my_qid; uint32_t test_number = 0; my_qid = _msgq_open(MAIN_QUEUE,0); qid = _msgq_get_id(TEST2_ID,RESPONDER_QUEUE); msgpool = _msgpool_create(sizeof(THE_MESSAGE), 8, 8, 16); while (test_number < 1000) { msg_ptr = (THE_MESSAGE_PTR)_msg_alloc(msgpool); msg_ptr->HEADER.TARGET_QID = qid; msg_ptr->HEADER.SOURCE_QID = my_qid; msg_ptr->DATA = test_number++; putchar('-'); _msgq_send(msg_ptr); msg_ptr = _msgq_receive(MSGQ_ANY_QUEUE, 1000); if (msg_ptr == NULL) { puts("Receive failed\n"); //_task_block(); } else { if (msg_ptr->HEADER.SIZE != sizeof(THE_MESSAGE)) { puts("Message wrong size\n"); //_task_block(); } else { if (MSG_MUST_CONVERT_DATA_ENDIAN(msg_ptr->HEADER.CONTROL)) { _mem_swap_endian(global_endian_swap_def, &msg_ptr->DATA); } /* Endif */ if (msg_ptr->DATA != test_number) { puts("Message data incorrect\n"); //_task_block(); } else { puts("Message received\n"); } } _msg_free(msg_ptr); } } puts("All complete\n"); _task_block(); }
void _cmsg_add_aux(byte color, cptr str, int turn, int count) { msg_ptr m; /* Repeat last message? */ if (_msg_count) { m = msg_get(0); if (strcmp(string_buffer(m->msg), str) == 0) { m->count += count; m->turn = turn; m->color = color; return; } } m = _msgs[_msg_head]; if (!m) { m = _msg_alloc(NULL); _msgs[_msg_head] = m; _msg_count++; } else { string_clear(m->msg); string_shrink(m->msg, 128); } string_append_s(m->msg, str); m->turn = turn; m->count = count; m->color = color; _msg_head = (_msg_head + 1) % _msg_max; }
void main_task ( uint_32 parameter ) { MESSAGE_HEADER_STRUCT_PTR msg_ptr; _task_id created_task; _mqx_uint log_result; _mqx_uint event_result; _mqx_uint sem_result; _int_install_unexpected_isr(); printf("\nMQX %s\n",_mqx_version); printf("Hello from main_task().\n"); /* create the log component */ log_result = _log_create_component(); if (log_result != MQX_OK) { /* log component could not be created */ } /* endif */ /* Create the mutex component */ if (_mutex_create_component() != MQX_OK) { /* an error has been detected */ } /* create the event component */ event_result = _event_create_component(EVENT_INITIAL_NUMBER, EVENT_GROWTH, EVENT_MAXIMUM); if (event_result != MQX_OK) { /* event component could not be created */ printf("Error: Cannot create event component\n"); _task_block(); } /* endif */ /* create the semaphore component */ sem_result = _sem_create_component(SEM_INITIAL_NUMBER, SEM_GROWTH, SEM_MAXIMUM); if (sem_result != MQX_OK) { /* semaphore component could not be created */ printf("Error: Cannot create semaphore component\n"); _task_block(); } /* endif */ MsgPool_pool_id = _msgpool_create ( 8, 10, 0, 0); if (MsgPool_pool_id == MSGPOOL_NULL_POOL_ID) { /* _msgpool_create did not succeed */ printf("Error: Cannot create message pool\n"); _task_block(); } Main_Queue_qid = _msgq_open( MSGQ_FREE_QUEUE, SIZE_UNLIMITED); if (Main_Queue_qid == (_queue_id)0){ /* queue could not be opened */ printf("Error: Cannot open message pool\n"); _task_block(); } created_task = _task_create(0, SENDER, 0); if (created_task == MQX_NULL_TASK_ID) { /* task creation failed */ printf("Error: Cannot create task\n"); _task_block(); } created_task = _task_create(0, MUTEXA, 0); if (created_task == MQX_NULL_TASK_ID) { /* task creation failed */ printf("Error: Cannot create task\n"); _task_block(); } created_task = _task_create(0, MUTEXB, 0); if (created_task == MQX_NULL_TASK_ID) { /* task creation failed */ printf("Error: Cannot create task\n"); _task_block(); } created_task = _task_create(0, SEMA, 0); if (created_task == MQX_NULL_TASK_ID) { /* task creation failed */ printf("Error: Cannot create task\n"); _task_block(); } created_task = _task_create(0, SEMB, 0); if (created_task == MQX_NULL_TASK_ID) { /* task creation failed */ printf("Error: Cannot create task\n"); _task_block(); } created_task = _task_create(0, EVENTA, 0); if (created_task == MQX_NULL_TASK_ID) { /* task creation failed */ printf("Error: Cannot create task\n"); _task_block(); } created_task = _task_create(0, EVENTB, 0); if (created_task == MQX_NULL_TASK_ID) { /* task creation failed */ printf("Error: Cannot create task\n"); _task_block(); } #if MQX_KERNEL_LOGGING /* create log number 0 */ log_result = _klog_create(200, 0); if (log_result != MQX_OK) { /* log 0 could not be created */ printf("Error: Cannot create kernel log\n"); _task_block(); } /* endif */ /* define kernel logging */ _klog_control(0xFFFFFFFF, FALSE); _klog_control( KLOG_ENABLED | KLOG_FUNCTIONS_ENABLED | KLOG_INTERRUPTS_ENABLED | KLOG_SYSTEM_CLOCK_INT_ENABLED | KLOG_CONTEXT_ENABLED | KLOG_TASKING_FUNCTIONS | KLOG_ERROR_FUNCTIONS | KLOG_MESSAGE_FUNCTIONS | KLOG_INTERRUPT_FUNCTIONS | KLOG_MEMORY_FUNCTIONS | KLOG_TIME_FUNCTIONS | KLOG_EVENT_FUNCTIONS | KLOG_NAME_FUNCTIONS | KLOG_MUTEX_FUNCTIONS | KLOG_SEMAPHORE_FUNCTIONS | KLOG_WATCHDOG_FUNCTIONS, TRUE ); #endif /* ** LOOP - */ while ( TRUE ) { msg_ptr = _msg_alloc((_pool_id) MsgPool_pool_id ); if (msg_ptr == NULL) { /* No available message buffer */ } msg_ptr->SIZE = sizeof(MESSAGE_HEADER_STRUCT); msg_ptr->SOURCE_QID = msg_ptr->TARGET_QID; msg_ptr->TARGET_QID = Sender_Queue_qid; _msgq_send(msg_ptr); /* * Service the message queue - Main_Queue */ msg_ptr = _msgq_receive_ticks(Main_Queue_qid, NO_TIMEOUT); /* process message End_msg */ _msg_free(msg_ptr); } /* endwhile */ } /*end of task*/
/* ** Send extended string to socket (dynamic webpages). ** ** IN: ** HTTPSRV_STRUCT *server - server structure. ** HTTPSRV_SESSION_STRUCT *session - session for sending. ** char *str - string to send. ** uint32_t length - length of source string. ** ** OUT: ** none ** ** Return Value: ** int - number of bytes processed. */ static uint32_t httpsrv_sendextstr(HTTPSRV_STRUCT *server, HTTPSRV_SESSION_STRUCT *session, uint32_t length) { char *src; char* t_buffer; uint32_t n; uint32_t retval; t_buffer = session->response.script_buffer; src = session->buffer.data + session->buffer.offset; n = strlen(t_buffer); if (n == 0) /* Start searching for script token. */ { uint32_t n_send; uint32_t max; uint32_t i; char token[] = "<%"; i = 0; max = length; for (n_send = 0; (n_send < max) && (token[i]); n_send++) { if (src[n_send] == token[i]) { t_buffer[i] = token[i]; i++; max = ((n_send+2) < length) ? n_send+2 : length; } else { i = 0; max = length; session->response.script_buffer[0] = 0; } } session->buffer.offset = n_send - i; retval = i; } else if (n == 1) /* There was already the less-than sign.*/ { if (*src == '%') { /* There is script token spanning over two buffers. */ t_buffer[n] = *src; retval = 1; } else { /* There was no script token, send missing less-than sign. */ send(session->sock, session->response.script_buffer, n, 0); *((uint16_t *) session->response.script_buffer) = 0; retval = 0; } } else /* Script token beginning found, find end. */ { uint32_t name_length; char fname[HTTPSRVCFG_MAX_SCRIPT_LN] = {0}; uint32_t term_length; name_length = strcspn(src, " ;%<>\r\n\t\f"); if ((src[name_length] == '%') && (src[name_length + 1] == '>')) { term_length = 2; } else { term_length = 1; } if ((name_length > 1) && (name_length < HTTPSRVCFG_MAX_SCRIPT_LN)) { HTTPSRV_SCRIPT_MSG* msg_ptr; snprintf(fname, name_length+1, "%s", src); /* Form up message for handler task and send it. */ msg_ptr = _msg_alloc(server->script_msg_pool); if (msg_ptr != NULL) { 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_SSI_CALLBACK; msg_ptr->name = fname; msg_ptr->ses_tid = _task_get_id(); _msgq_send(msg_ptr); /* Wait until SSI is processed. */ _task_block(); } *((uint16_t *) session->response.script_buffer) = 0; } retval = name_length + term_length; } return(retval); }
/* ** Send extended string to socket (dynamic webpages). ** ** IN: ** HTTPSRV_STRUCT *server - server structure. ** HTTPSRV_SESSION_STRUCT *session - session for sending. ** char *str - string to send. ** uint32_t length - length of source string. ** ** OUT: ** none ** ** Return Value: ** int - number of bytes processed. */ static _mqx_int httpsrv_sendextstr(HTTPSRV_STRUCT *server, HTTPSRV_SESSION_STRUCT *session, char *str, uint32_t length) { char *src; int len, res; int add = 0; char fname[HTTPSRVCFG_MAX_SCRIPT_LN + 1]; uint32_t old_data = session->buffer.offset; src = str; fname[0] = 0; if (session->response.script_token) { // script token found len = (int)strcspn(src, " ;%<>\r\n\t"); if (len > 1 && len < HTTPSRVCFG_MAX_SCRIPT_LN) { HTTPSRV_SCRIPT_MSG* msg_ptr; snprintf(fname, len+1, "%s", src); /* Form up message for handler task and send it */ msg_ptr = _msg_alloc(server->script_msg_pool); if (msg_ptr != NULL) { 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_SSI_CALLBACK; msg_ptr->name = fname; msg_ptr->ses_tid = _task_get_id(); _msgq_send(msg_ptr); /* wait until SSI is processed */ _task_block(); } } if (src[len] == '%' && src[len + 1] == '>') { session->response.script_token = 0; len += 1; } len++; } else { for (len = 0; *src && len < length; src++, len++) { if (src[0] == '<' && src[1] == '%') { session->response.script_token = 1; src += 2; add = 2; break; } } res = send(session->sock, str, len, 0); session->buffer.offset = 0; _mem_zero(session->buffer.data, HTTPSRV_SES_BUF_SIZE_PRV); if (res < 0) { session->response.script_token = 0; #if MQX_USE_IO_OLD res = errno; #else res = _task_errno; #endif if (res != EAGAIN) { len = 0; } } else if (len != res) { session->response.script_token = 0; } } return ((len+add)-old_data); }