Example #1
0
void
on_new_dialog_response                 (GtkDialog       *dialog,
                                        gint             response_id,
                                        gpointer         user_data)
{
   switch(response_id)
   {
       case GTK_RESPONSE_YES:
            // trza zapisac:
            gtk_widget_hide(GTK_WIDGET(dialog));
			save_request(clear_scenery);
			return;

       case GTK_RESPONSE_NO:
            clear_scenery();

       case GTK_RESPONSE_CANCEL:
            gtk_widget_hide(GTK_WIDGET(dialog));

       case GTK_RESPONSE_DELETE_EVENT:
            return;

       default:
            Publisher::warn("Code bug:\nUnknown response from the 'new dialog'");
   }
}
Example #2
0
int vshttpclient_send_request_new(const char* http_url, const char* http_port,
		kVSHttpReq req, void* req_data, char out_req_id[])
{
	int result = -1;
	
	if (NULL == http_url
	    || NULL == http_port
	    || NULL == req_data
	    || NULL == out_req_id)
	{
	    vshttp_printf("param err\n");
	    return result;
	}
	
	memset(out_req_id, 0, REQ_ID_LEN);
	
	switch (req)
	{
	case kAttackedHostQueryReq:
		{
			AttackedHostHttpReq* AttackedHostReq = 
				new AttackedHostHttpReq((VSHttpAttackedHostReq*)req_data);
			AttackedHostReq->SetRespCallback(g_resp_callback);
			strcpy(out_req_id, AttackedHostReq->GetId());
			result = AttackedHostReq->SendRequest(http_url, http_port);
			if (result >= 0)
			{
				save_request(AttackedHostReq);
			}
			break;
		}
	default:
		break;
	}

	return result;
}
Example #3
0
void
complete(int how, runner *run)
{
    struct request *req = run->req;
    save_request(how, run);

    evtimer_del(&req->timeoutev);
    debug("complete(): evtimer_del(&req->timeoutev);\n");

    /* enqueue the next one */
    if(params.count<0 || counts.conns<params.count){
        // re-scheduling is handled by the callback
        if(!qps_enabled()){
            if(!rpc_enabled() || req->evcon_reqno<params.rpc){
                dispatch(run, req->evcon_reqno + 1);
            }else{
                // re-establish the connection
                evhttp_connection_free(run->evcon);
                mkhttp(run);
                dispatch(run, 1);
            }
        }
    }else{
        /* We'll count this as a close. I guess that's ok. */
        evhttp_connection_free(req->evcon);
        if(--params.concurrency == 0){
            evtimer_del(&reportev);
            debug("last call to reportcb\n");
            reportcb(0, 0, nil);  /* issue a last report */
        }
    }

    if(!qps_enabled())
      // FIXME possible memory leak
      free(req);
}
Example #4
0
void* consumerThread(void *args) {
	int id = *((int *)args);
	double random;
	struct drand48_data randBuffer;
	int sock;
	QElement *elmnt;
	ssize_t rcvBytes;
	int type;
	int ret;
	HttpGet httpGet;
	ssize_t totalSize;	
	char *savedBuffer;
	
	int lenBuffer = sizeof(char) * BUFSIZE;
	char *buffer;
	
	srand48_r(time(NULL), &randBuffer);
	
	while (1) {
		totalSize = 0;
		
		pthread_mutex_lock(&queue_mutex);
		while (hasPending == 0) {
			LOG_INFO("Consumer[%d] is waiting.\n", id);
			pthread_cond_wait(&queue_cond, &queue_mutex);
		}
		
		if (queue_clients.size > 0 && queue_webservers.size > 0) {
			drand48_r(&randBuffer, &random);
			if (random < 0.5) {
				elmnt = pop_queue(&queue_clients);
			} else {
				elmnt = pop_queue(&queue_webservers);
			}
		} else if (queue_clients.size > 0) {
			elmnt = pop_queue(&queue_clients);
		} else {
			elmnt = pop_queue(&queue_webservers);
		}
		
		hasPending--;
		if (hasPending > 0) {
			pthread_cond_signal(&queue_cond);
		}
		
		pthread_mutex_unlock(&queue_mutex);
		
		buffer = (char *) malloc(lenBuffer);
		if (buffer == NULL) {
			LOG_ERROR("Not enough free memory space\n");
			return NULL;
		}
		
		sock = elmnt->clSock;
		free(elmnt);

		rcvBytes = recv(sock, buffer, lenBuffer, 0);
		if (rcvBytes < 0) {
			LOG_ERROR("Consumer[%d]: An error occurred while receiving data from the client.\n", id);
			continue;
		} else if (rcvBytes == 0) {
			LOG_ERROR("Consumer[%d]: The client has performed a shutdown.\n", id);
			continue;
		}
		totalSize += rcvBytes;
		
		type = findHttpMessageType(buffer, rcvBytes);
		if (type == HTTP_GET) {
			int webSock;
			LOG_INFO("Consumer[%d]: Get Message received\n", id);
			
			ret = parseHttpGetMsg(buffer, rcvBytes, &httpGet);
			
			if (ret == HTTP_PARSER_ERROR || ret == NO_MEMORY_ERROR) {
				sendHttpBadReqMsg(sock);
			} else if (ret == HTTP_HOST_NOT_FOUND){
				sendHttpNotFoundMsg(sock);
			} else if (ret == OK) {
				char* response = get_response_cache(cache, httpGet.request, httpGet.reqLen);
				if (response != NULL) {
					LOG_INFO("\tConsumer[%d]: Cache Hit\n", id);
					
					update_cache(cache, httpGet.request, httpGet.reqLen);
					
					ret = sendSingleHttpResponseMsg(response, strlen(response), sock);
					if (ret != OK) {
						LOG_ERROR("Consumer[%d]: Unable to send the response Message\n", id);
					}
				} else {
					LOG_INFO("\tConsumer[%d]: No Cache Hit\n", id);
					
					if (contains_request(httpGet.request, httpGet.reqLen) != FOUND) {
						LOG_INFO("\tConsumer[%d]: Does not contain that request\n", id);								
						webSock = sendHttpGetMsgToServer(&httpGet);
						if (webSock < 0) {
							LOG_ERROR("Consumer[%d]: Did not send the HttpGetMessage to the Webserver\n", id);
						} else {
							if (save_request(httpGet.request, httpGet.reqLen, webSock, sock) != OK) {
								LOG_ERROR("Consumer[%d]: An error occurred while saving the request\n", id);
							}
							if (insertFD(webSock) != OK) {
								LOG_ERROR("Consumer[%d]: An error occurred while saving the socket\n", id);
							}
						}
					} else {
						LOG_INFO("\tConsumer[%d]: Does contain that request\n", id);	
						webSock = get_request(httpGet.request, httpGet.reqLen);
					}
					
					if (map_client_with_webserver(webSock, sock) != OK) {
						LOG_ERROR("Consumer[%d]: An error occurred while making the mapping between client's socket and webserver's one.\n", id);
					}
				}
				
				clear_httpGetMsg(&httpGet);
			}
		} else if (type == HTTP_RESPONSE) {
			LOG_INFO("Consumer[%d]: Response Message received\n", id);
			
			Queue* clSocks = find_appropriate_clients(sock);
			if (clSocks == NULL) {
				LOG_ERROR("Consumer[%d]: Could not find the appropriate clients.\n", id);
				continue;
			}
			
			savedBuffer = (char *) malloc(sizeof(char) * rcvBytes);
			if (savedBuffer == NULL) {
				LOG_ERROR("Consumer[%d]: Not enough free memory space.\n", id);
				continue;
			}
			
			memcpy(savedBuffer, buffer, rcvBytes);
			
			char *t;
			ssize_t prevSize = rcvBytes;
			memset(buffer, 0, lenBuffer);
			while ((rcvBytes = recv(sock, buffer, lenBuffer, 0)) != 0) {
				totalSize += rcvBytes;
				t = realloc(savedBuffer, totalSize);
				if (t == NULL) {
					LOG_ERROR("Consumer[%d]: Not enough free memory space.\n", id);
					break;
				}
				
				savedBuffer = t;
				memcpy(savedBuffer + prevSize, buffer, rcvBytes);
				prevSize = totalSize;
			}
			
			QElement *iter;
			char *req;
			int clSock = -1;
			for (iter = clSocks->head; iter != NULL; iter = iter->next) {
				req = get_hashmap(&cl_req_map, &iter->clSock, sizeof(int));
				if (req != NULL) {
					if (put_response_cache(cache, req, strlen(req) + 1, savedBuffer, totalSize) != OK) {
						LOG_ERROR("Consumer[%d]: Could not insert it in the cache\n", id);
					} 
					clSock = iter->clSock;
					break;
				}
			}
			
			ret = sendHttpResponseMsg(savedBuffer, totalSize, clSocks);
			if (ret != OK) {
				LOG_ERROR("Consumer[%d]: Unable to send the response Message\n", id);
			}
			
			
			if (remove_appropiate_clients(sock) != OK) {
				LOG_ERROR("Consumer[%d]: Could not remove the appropriate clients from the hash map\n", id);
			}
			if (remove_request(sock, clSock) != OK) {
				LOG_ERROR("Consumer[%d]: Could not remove the request from the hash map\n", id);
			}
			
			if (savedBuffer != NULL) {
				free(savedBuffer);
			}
			
		} else {
			LOG_INFO("Consumer[%d]: Unknown type of message\n", id);
			sendHttpBadReqMsg(sock);
		}
		
		free(buffer);
	}
	
	return NULL;
}
Example #5
0
void
on_save_mi_activate (GtkMenuItem * menuitem, gpointer user_data)
{
  save_request();
}
Example #6
0
void
on_save_toolbutton_clicked (GtkToolButton * toolbutton, gpointer user_data)
{
  save_request();
}