int delete_message(message* p) { if(p==NULL) return 0; delete_command(p->commands); delete_notification(p->notifications); delete_request(p->requests); free(p); return 1; }
int vshttpclient_end_request(char* req_id) { if (NULL != req_id) { delete_request(req_id); } return 0; }
int delete_request(request* p) { if(p==NULL) return 0; delete_request(p->next); delete_cmd_msg(p->command_message); delete_data_msg(p->data_message); delete_fault_msg(p->fault_message); free(p->interface_name); free(p->interface_id); free(p); return 1; }
int delete_interface(interface* p) { if(p==NULL) return 0; delete_interface(p->next); delete_qualifier(p->qualifiers); delete_variable(p->variables); delete_command(p->commands); delete_notification(p->notifications); delete_request(p->requests); free(p->name); free(p->extends); free(p->id); free(p->description); free(p); return 1; }
void * handle_client_request(void * workerId) { int id = *((int *) workerId); char * request = NULL; int clientSocket, parseSuccess; struct http_request_s * request_obj; struct http_response_s * response_obj; char *response = NULL; printf("Hullo in %d\n", id); while(1) { clientSocket = -1; printf("Go to loop in %d\n", id); pthread_mutex_lock(&queue_mutex); { if(is_empty_queue(clientQueue)) { pthread_cond_wait(&queue_has_client, &queue_mutex); } else /* Take 1 client out of the queue */ dequeue(clientQueue, &clientSocket); } pthread_mutex_unlock(&queue_mutex); printf("Worker with id = %d handles socketId = %d\n", id, clientSocket); if(clientSocket >= 0) { /* Initalize for new request handling */ request_obj = create_request_struct(); response_obj = create_response_struct(); response = NULL; /* Handle the request of the client */ request = read_request(clientSocket); /* ssize_t numByte = recv(clientSocket, m_request, 1000, 0); m_request[numByte] = '\0'; */ printf("OK reading request\n"); /* Parse request */ parseSuccess = parse_http_request(request_obj, request, response_obj); response_obj->version = copy_str_dynamic(SUPPORT_HTTP); if(parseSuccess) { /* Check HTTP version */ if(strcasecmp(request_obj->version, SUPPORT_HTTP) != 0) { set_status_code_error(response_obj, 505, "505 HTTP Version Not Supported", "This server supports only HTTP/1.1"); } else { /* Check file access security */ if(count_occurence(request_obj->path, '/') > MAX_NUM_SLASH) set_status_code_error(response_obj, 401, "401 Unauthorized", "You are not authorized to access the requested file on this server"); else { exec_http_request(request_obj, response_obj); } } } /* Execute command and return output sprintf(response, "Server worker thread with id = %d handles request: %s", id, request); */ response = get_response_text(response_obj); send(clientSocket, response, strlen(response), 0); //recv(clientSocket, response, 100, 0); /* Close socket, free memory */ close(clientSocket); free(request); free(response); delete_request(&request_obj); delete_response(&response_obj); } } }
void CServer::handle_request(const char *request) { const char *p; int cmd_len; int ok; logger->log(3, "Got request: %s", request); p = strchr(request,' '); if (p == 0) { p = request + strlen(request); } cmd_len = p - request; while (*p == ' ') { p++; } ok = 0; if (cmd_len == 0) { logger->log(2, "Empty request!"); return; } char *command = new char[cmd_len+1]; memcpy(command, request, cmd_len); command[cmd_len] = 0; try { if (strcmp(command, "SEARCH") == 0) { ok = 1; search_request(p); } if (strcmp(command, "COUNT") == 0) { ok = 1; count_request(); } if (strcmp(command, "DELETEHOST") == 0) { ok = 1; delete_request(p); } if (strcmp(command, "LOAD") == 0) { ok = 1; load_request(p); } if (strcmp(command, "STATUS") == 0) { ok = 1; status_request(); } if (strcmp(command, "HOSTINFO") == 0) { ok = 1; host_info_request(p); } if (strcmp(command, "HOSTSTAT") == 0) { ok = 1; host_stat_request(p); } if (strcmp(command, "CACHEINFO") == 0) { ok = 1; cache_info_request(); } if (strcmp(command, "UPDATEHOSTS") == 0) { ok = 1; update_hosts_request(p); } if (strcmp(command, "SERVERSTAT") == 0) { ok = 1; server_stat_request(); } if (strcmp(command, "DEBUG") == 0) { ok = 1; debug_request(p); } if (strcmp(command, "DUMP") == 0) { ok = 1; dump_state_request(); } if (strcmp(command, "FULLSCAN") == 0) { ok = 1; enable_full_request(p); } if (strcmp(command, "WORDORDER") == 0) { ok = 1; word_order_request(); } if (strcmp(command, "CLEARPAGECACHE") == 0) { ok = 1; clear_pagecache_request(); } if (strcmp(command, "CLEARQUERYCACHE") == 0) { ok = 1; clear_querycache_request(); } if (strcmp(command, "DUMPFILES") == 0) { ok = 1; dump_files_request(p); } if (strcmp(command, "DUMPINDEX") == 0) { ok = 1; dump_index_request(p); } if (!ok) { throw std::runtime_error(std::string("Unrecognized request: ") + request); } } catch (std::runtime_error &e) { logger->log(1, "Error: %s", e.what()); send_string("ERROR"); } delete[] command; m_request_count++; }