예제 #1
0
파일: http.c 프로젝트: whtc123/mysource
void httpsession_read(struct event *ev,int what, void *d)
{
	size_t len=0;
	size_t conten_len=0;
	char *line=NULL;
	char *ptr=NULL;
	//ptr=buff_tail_ptr()
	HttpSession *session = (HttpSession *)d;
	len=buff_read(session->fd, session->request.buff, buff_tail_left(session->request.buff));
	if(len<=0 )
		goto fail;
	while( (line=buff_get_line( session->request.buff,EOL_CRLF)) !=NULL )
	{
		if(session->request.prase_status==HPARSE_HEAD )
		{
			if( strlen(line)==0 )
			{
				session->request.prase_status=HPARSE_CONTENT;
				break;
			}
			if(http_parse_head(&session->request, line) == -1)
			{
				TraceErr("http_parse_head fail\n");
				goto fail;
			}
			continue;
		}

		if(session->request.prase_status==HPARSE_FIRST_LINE)
		{
			if(http_parse_first_line(&session->request,line)==-1)
				goto fail;
			session->request.prase_status=HPARSE_HEAD;
			continue;
		}

	}

	if(session->request.prase_status== HPARSE_CONTENT )
	{
		if(buff_len(session->request.buff) >= session->request.content_len)
		{
			session->request.prase_status = HPARSE_DONE;
			if(httpserver_route_request(session)!=200)goto fail;
			//if(session->server->request_callback(session,session->server->arg) != 0 )
			//	goto fail;
			//event_fd_setflags(session->ev,EPOLLIN|EPOLLOUT);
			//event_fd_setcallback(session->ev,httpsession_write);
			event_fd_setcallback(session->ev,httpsession_file_write);
			event_fd_setflags(session->ev,EPOLLOUT);
		}
	}
	return;	

fail:
	TraceErr("httpsession_read fail\n");
	httpserver_session_free(session);
	return;
}
예제 #2
0
int parseDiskIOInfo(char *buff, diskInfo_t *arr, int *size)
{
     int      devFound = 0;
     char     line[512];
     char    *buff_ptr;
     
     buff_ptr = buff;
     do {
	  diskInfo_t di;
	  
	  buff_ptr = buff_get_line(line, 512, buff_ptr);
	  
	  if(!parseDiskLine(line, &di))
	       continue;
	  diskInfo_t *di2ptr = findDiskInfo(arr, *size, di.name);
	  if(!di2ptr) continue;
	  
	  *di2ptr = di;
//	  printf("Got dev %s %u %u\n", di.name, di.readSectors, di.writeSectors);
	  devFound++;
     } while(buff_ptr);

     return devFound;
}
예제 #3
0
int addTextPartner(mapper_t map, char *fileName) {

	int              res = 0;
	int              size;
	int              linenum=0;
	char            *buffCurrPos = NULL;
	char            *buff = NULL;

	char            *clusterName = NULL;
	cluster_entry_t *cEnt = NULL;
	mapper_cluster_info_t ci;
	mapper_range_info_t   ri;
	int              lineBuffSize = 200;
	char             lineBuff[200];

	char             host_name[255];
	    
	cluster_info_init(&ci);
	
	buff = getMapSourceBuff(fileName, 0, INPUT_FILE, &size);
	if(!buff) {
		debug_lr(MAP_DEBUG, "Error reading file\n");
		goto out;
	}
	buffCurrPos = (char*) buff;
	if(!buffCurrPos)
		goto out;

	// Reading the cluster commet/description
	if(lineBuffSize > size)
		lineBuffSize = size;
	buffCurrPos = buff_get_line(lineBuff, lineBuffSize, buffCurrPos);
	if(!buffCurrPos) {
		debug_lr(MAP_DEBUG, "First line is not ok\n");
		goto out;
	}
	
	linenum++;
	debug_lg(MAP_DEBUG, "Processing line: %s\n", lineBuff);

	ci.ci_desc = strdup(lineBuff);
	
	
	// Reading the cluster prio, dont-take dontgo...
	buffCurrPos = buff_get_line(lineBuff, lineBuffSize, buffCurrPos);
	if(!buffCurrPos) {
		debug_lr(MAP_DEBUG, "Second line is ok\n");
		goto out;
	}
	
	linenum++;
	debug_lg(MAP_DEBUG, "Processing line: %s\n", lineBuff);

	int cango, cantake, canexpend;
	if(sscanf(lineBuff, "%d %d %d %d",
		  &ci.ci_prio, &cango, &cantake, &canexpend) != 4)
		
	{
		debug_lr(MAP_DEBUG, "Second line is not in correct format\n");
		goto out;
	}
	ci.ci_cango     = (char)cango;
	ci.ci_cantake   = (char)cantake;
	ci.ci_canexpend = (char)canexpend;
	
	clusterName = getClusterName(fileName);
	
	if(!mapper_addCluster(map, -1, clusterName, &ci)) {
		debug_lr(MAP_DEBUG, "Failed to add cluster %s\n", clusterName);
		goto out;
	}
	free(ci.ci_desc);
	ci.ci_desc = NULL;
	
	// Checking that the cluster is not already there
	cEnt = get_cluster_entry_by_name(map, clusterName);
	if(!cEnt) {
		debug_lr(MAP_DEBUG, "Just added cluster is not there\n");
		goto out;
	}

	// Reading the ranges
	int base = 1;
	while( buffCurrPos && !(*buffCurrPos == '\0') )
	{
		linenum++;
		buffCurrPos = buff_get_line(lineBuff, lineBuffSize, buffCurrPos);
		debug_lg(MAP_DEBUG, "Processing line: %s\n", lineBuff);
		

		// Skeeing comments in map
		if(lineBuff[0] == '#')
		{
			debug_lg(MAP_DEBUG, "\t\tcomment\n");
			continue;
		}
		// Skeeping empty lines
		if(strlen(lineBuff) == 0)
			continue;
		
		int count, core, participate, proximate;
		if (sscanf(lineBuff, "%s %d %d %d %d",
			   host_name, &count, &core, &participate, &proximate) == 5) {
			debug_lb(MAP_DEBUG, "Found partner range entry %s %d\n",
				 host_name, count);
                        
			ri.ri_core        = (char) core;
			ri.ri_participate = (char) participate;
			ri.ri_proximate   = (char) proximate;
			
			// If the range is valid adding it to the cluster (the
			// single cluster we have)
			// Doing the initialization part only in the first time
			// the map become old
			
			if(mapper_addClusterHostRange(map, cEnt, base, host_name, count, &ri))
			{
				base += count;
			}
			else {
				goto out;
			}
		}
		else {
			lineBuff[strlen(lineBuff)] = '\0';
			debug_lr(MAP_DEBUG, "Found bad line %s\n", lineBuff);
			sprintf(map->errorMsg, "Bad line <%s>\n", lineBuff);
			goto out;
		}
	}
	
	res = 1;
	
 out:
        if(buff)
		free(buff);
	cluster_info_free(&ci);
	return res;
}
예제 #4
0
/** Setting the map from a buffer, treating it as  txt formatted (not xml)
 * @param buff     The buffer containing the map
 * @param size     Size of buffer
 * @return a map_parse_status_t enum to indicate the result
 */
static
int build(mapper_t map, const char *buff, int size)
{
    int linenum=0;
    char *buff_cur_pos = NULL;
//    int current_cluster_id = 0;
//    int current_part_id = 0;
    cluster_entry_t *cluster_ptr = NULL;
    int base, count;
//    char *tmp_ptr;

//    int saw_zone_def = 0;
    char line_buff[200];
    char host_name[80];
//    char default_zone_str[10];

    buff_cur_pos = (char*) buff;
    if(!buff_cur_pos)
	    return 0;

    cluster_ptr = &map->clusterArr[0]; 
    map->nrClusters = 1;
    cluster_ptr->c_id = 0;
    cluster_ptr->c_rangeList = NULL;

    
    while( buff_cur_pos && !(*buff_cur_pos == '\0') )
    {
	linenum++;
	buff_cur_pos = buff_get_line(line_buff, 200, buff_cur_pos);

	//debug_ly(MAP_DEBUG, "Processing line: '%s'\n", line_buff);
	// Skeeing comments in map
	if(line_buff[0] == '#')
	{
		debug_lg(MAP_DEBUG, "\t\tcomment\n");
		continue;
	}
	// Skeeping empty lines
	if(strlen(line_buff) == 0)
		continue;

	
	if (sscanf(line_buff, "%d %s %d", &base, host_name, &count) == 3) {
		debug_lb(MAP_DEBUG, "Found userview entry %d %s %d\n",
			 base, host_name, count);
		
		// If the range is valid adding it to the cluster (the single cluster we have)
		// Doing the initialization part only in the first time the map become old
		mapper_range_info_t ri;
		bzero(&ri, sizeof(ri));
		if(!mapper_addClusterHostRange(map, cluster_ptr, base, host_name, count, &ri))
		{
			return 0; 
		}
	}
	else {
		line_buff[strlen(line_buff)] = '\0';
		debug_lr(MAP_DEBUG, "Found bad line %s\n", line_buff);
		sprintf(map->errorMsg, "Bad line <%s>\n", line_buff);
		return 0;
	}
    }
    
    return 1;
}