Ejemplo n.º 1
0
bool_t CC_CALL UILayer::setText(const tchar_t *_text, const uint32_t _len)
{
    if (_text == NULL || _len == 0) {
        if(text)
            text[0] = 0;
        textLen = 0;
        return TRUE;
    }

    if (text == NULL) {
        text = (tchar_t*)cc_malloc(sizeof(tchar_t) * _len + 1);
        maxTextLen = _len;
    } else if (maxTextLen < _len) {
        cc_free(text);
        text = (tchar_t*)cc_malloc(sizeof(tchar_t) * _len + 1);
        maxTextLen = _len;
    }

    if (text == NULL)
        return FALSE;

    _tcsncpy(text, _text, _len);

    text[_len] = 0;
    textLen = _len;
    return TRUE;
}
Ejemplo n.º 2
0
Archivo: socket.c Proyecto: CCQIU/CC
cckit_data_buffer_t* CC_CALL cckit_data_buffer_push(cckit_data_buffer_t **b)
{
	cc_double_iterator_t* base = NULL;
	if (b && *b) {
		return (cckit_data_buffer_t*)*b;
	}

	if (_global_cckit.buffer_lock) {
		cc_mutex_lock(_global_cckit.buffer_lock);
	}

	base = cc_double_link_pop_front(&_global_cckit.buffer_idle);
	if (base) {
		*b = cc_upcast(base, cckit_data_buffer_t, base);
	} else {
		*b = (cckit_data_buffer_t *)cc_malloc(sizeof(cckit_data_buffer_t));
	}

	if (*b) {
		(*b)->length = 0;
		cc_double_link_push_back(&_global_cckit.buffer_actived, &(*b)->base);
	}

	if (_global_cckit.buffer_lock) {
		cc_mutex_unlock(_global_cckit.buffer_lock);
	}
	return *b;
}
Ejemplo n.º 3
0
Archivo: sync.c Proyecto: CCQIU/CC
bool_t CC_CALL cckit_init_sync(int32_t count)
{
    int32_t i = 0;
    if (sync_queue_lock) {
        return TRUE;
    }
    
    cc_double_link_cleanup(&sync_queue_actived);
    cc_double_link_cleanup(&sync_queue_released);
    cc_double_link_cleanup(&sync_data_released);
    
    sync_queue_lock = cc_create_mutex();
    if (sync_queue_lock == NULL) {
        return FALSE;
    }
    
    cc_mutex_lock(sync_queue_lock);
    for (i = 0; i < count; i++) {
        cckit_sync_t *d = (cckit_sync_t *)cc_malloc(sizeof(cckit_sync_t));
        cc_double_link_push(&sync_queue_released, &d->base);
    }
    cc_mutex_unlock(sync_queue_lock);
    
    return TRUE;
}
Ejemplo n.º 4
0
static void fd_table_init(void)
{
	int size;
	size = sizeof(struct _fde) * FD_MAX;
	fd_table = NULL;
	fd_table = cc_malloc(size);
	assert(fd_table != NULL);
	memset(fd_table, 0, size);
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: selecli/squid
static void g_pstOrigDomainHistory_init(void)
{
    int size;

    size = sizeof(struct origDomainHistory *) * max_origDomainHistory_capacity;
    g_pstOrigDomainHistory = cc_malloc(size);
    assert(g_pstOrigDomainHistory != NULL);
    memset(g_pstOrigDomainHistory, 0, size);
}
Ejemplo n.º 6
0
bool_t CC_CALL cckit_http_request(const tchar_t *address, cckit_http_callback_t *cb)
{
	cc_event_args_t arg;
	cckit_http_t *http = (cckit_http_t*)cc_malloc(sizeof(cckit_http_t));
	if (http == NULL) {
		return FALSE;
	}

	http->cb.cb_success = cb->cb_success;
	http->cb.cb_header = cb->cb_header;
	http->cb.cb_error = cb->cb_error;
	http->cb.cb_before_send = cb->cb_before_send;
	http->cb.cb_read = cb->cb_read;
	http->cb.args = cb->args;

	http->valid = FALSE;
	http->response = NULL;
	http->length = 0;
	http->content_length = 0;

	http->address = cc_create_url(address);

	if (http->address == NULL) {
		cc_free(http);
		return FALSE;
    }
    
#ifdef CC_OPENSSL_HTTPS
    if (http->address->scheme == CC_SCHEME_HTTPS) {
        /*SSL init*/
        if(cc_atomic_inc_ref(_SSL_init_refcount)) {
            SSL_library_init();
            SSL_load_error_strings();
        }
    }
#endif
	arg.event_id = 0;
	arg.callback = _http_callback;
	arg.timeout = 60000;
	arg.args[0] = http;
	arg.args[1] = NULL;
	arg.args[2] = NULL;

	http->sock_event = cckit_tcp_connect(AF_INET, http->address->host, http->address->port, &arg, TRUE);

	if (http->sock_event == NULL) {
		return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 7
0
Archivo: sys_cond.c Proyecto: CCQIU/CC
/* Create a condition variable */
cc_condition_t* CC_CALL cc_create_condition(void)
{
    cc_condition_t *cond;

    cond = (cc_condition_t *) cc_malloc(sizeof(cc_condition_t));
    if ( cond ) {
        cond->lock = cc_create_mutex();
        cond->wait_sem = cc_create_semaphore(0);
        cond->wait_done = cc_create_semaphore(0);
        cond->waiting = cond->signals = 0;

        if ( cond->lock == NULL || cond->wait_sem == NULL || cond->wait_done == NULL ) {
            CC_ERROR_LOG(_T("create_condition() failed"));
            cc_destroy_condition(&cond);
        }
    }
    return(cond);
}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: selecli/squid
static void g_detect_tasks_init(void)
{
    int size;

    HashConfigure conf = {0};
    conf.name = "detect_tasks_init";
    conf.total = (2<<16)+1;
    conf.GetKey = DetectOriginIndexGetKey;
    conf.IsEqual = DetectOriginIndexIsEqual;
    conf.IsNull = DetectOriginIndexIsNull;
    conf.DoFree = (HashDoFree)free;
    g_detect_tasks_index = HashCreate( &conf );

    size = sizeof(struct DetectOrigin *) * max_tasks_capacity;
    g_detect_tasks = cc_malloc(size);
    assert(g_detect_tasks != NULL);
    memset(g_detect_tasks, 0, size);
}
Ejemplo n.º 9
0
Archivo: sys_sem.c Proyecto: CCQIU/CC
/* Create a semaphore */
cc_semaphore_t* CC_CALL cc_create_semaphore(int32_t initial_value)
{
    cc_semaphore_t *sem;

    /* Allocate sem memory */
    sem = (cc_semaphore_t *)cc_malloc(sizeof(*sem));
    if ( sem ) {
        sem->count = initial_value;
        sem->waiters_count = 0;
        sem->count_lock = cc_create_mutex();
        sem->count_nonzero = cc_create_condition();
        if ( sem->count_lock == NULL || sem->count_nonzero == NULL ) {
            CC_ERROR_LOG(_T("create semaphore failed"));
            cc_destroy_semaphore(&sem);
            return NULL;
        }
    } else {
        CC_ERROR_LOG(_T("Couldn't malloc semaphore"));
    }
    return(sem);
}
Ejemplo n.º 10
0
Archivo: sys_mutex.c Proyecto: CCQIU/CC
/** Create a mutex, initialized unlocked */
cc_mutex_t* CC_CALL cc_create_mutex(void)
{
    cc_mutex_t *mutex;

    /* Allocate mutex memory */
    mutex = (cc_mutex_t *)cc_malloc(sizeof(*mutex));
    if ( mutex ) {
        /* Create the mutex, with initial value signaled */
        mutex->sem = cc_create_semaphore(1);
        mutex->recursive = 0;
        mutex->owner = 0;
        if(mutex->sem == NULL)
        {
            safe_free(mutex);
            mutex = NULL;
        }
    } else {
        CC_ERROR_LOG(_T("Couldn't malloc mutex"));
    }
    return(mutex);
}
Ejemplo n.º 11
0
CGE_NS_BEGIN

bool_t CC_CALL Image::loadJPG(const byte_t *_imageData, int32_t _imageSize)
{
	__ImageSource ImageSource;

	/* allocate and initialize JPEG decompression object */
	struct jpeg_decompress_struct cinfo;
	struct __jpeg_error_mgr jerr;
	/* specify data source */
	struct jpeg_source_mgr jsrc;

	/* Used to point to image rows */
	byte_t** row_pointers = 0;
	byte_t* output = 0;
	uint32_t i,rowsRead;
	int16_t rowspan;
	bool_t use_CMYK = FALSE;

	CC_ASSERT(_imageData != NULL);
	if(_imageData == NULL) {
		return FALSE;
	}

	ImageSource.data = (byte_t *)(_imageData + 8);
	ImageSource.size = (uint32_t)_imageSize;
	ImageSource.offset = 0;

	cinfo.err = jpeg_std_error(&jerr.err_mgr);
	cinfo.err->error_exit = NULL;
	cinfo.err->output_message = NULL;

	/* compatibility fudge:
	   we need to use setjmp/longjmp for error handling as gcc-linux
	   crashes when throwing within external c code */
	if (setjmp(jerr.setjmp_buffer)) {
		/* If we get here, the JPEG code has signaled an error.
		   We need to clean up the JPEG object and return. */

		jpeg_destroy_decompress(&cinfo);

		return FALSE;
	}
	/* Now we can initialize the JPEG decompression object. */
	jpeg_create_decompress(&cinfo);


	/* Set up data pointer */
	jsrc.bytes_in_buffer = _imageSize;
	jsrc.next_input_byte = (JOCTET*)_imageData;
	cinfo.src = &jsrc;

	jsrc.init_source = init_source;
	jsrc.fill_input_buffer = fill_input_buffer;
	jsrc.skip_input_data = skip_input_data;
	jsrc.resync_to_restart = jpeg_resync_to_restart;
	jsrc.term_source = term_source;

	/* Decodes JPG input from whatever source
	   Does everything AFTER jpeg_create_decompress
	   and BEFORE jpeg_destroy_decompress
	   Caller is responsible for arranging these + setting up cinfo

	   read file parameters with jpeg_read_header() */
	jpeg_read_header(&cinfo, TRUE);

	if(cinfo.jpeg_color_space == JCS_CMYK)
	{
		cinfo.out_color_space = JCS_CMYK;
		cinfo.out_color_components = 4;
		use_CMYK = TRUE;
	} else {
		cinfo.out_color_space = JCS_RGB;
		cinfo.out_color_components = 3;
	}
	cinfo.output_gamma = 2.2f;
	cinfo.do_fancy_upsampling = FALSE;

	/* Start decompressor */
	jpeg_start_decompress(&cinfo);

	/* Get image data */
	rowspan = cinfo.image_width * cinfo.out_color_components;
	width = cinfo.image_width;
	height = cinfo.image_height;

	/* Allocate memory for buffer */
	output = (byte_t*)cc_malloc(sizeof(byte_t) * height * rowspan);
	/* Here we use the library's state variable cinfo.output_scanline as the
	   loop counter, so that we don't have to keep track ourselves.
	   Create array of row pointers for lib */
	row_pointers = (byte_t**)cc_malloc(sizeof(byte_t*) * height);

	for( i = 0; i < height; i++ )
		row_pointers[i] = &output[ i * rowspan ];

	rowsRead = 0;

	while( cinfo.output_scanline < cinfo.output_height )
		rowsRead += jpeg_read_scanlines( &cinfo, &row_pointers[rowsRead], cinfo.output_height - rowsRead );

	cc_free(row_pointers);
	/* Finish decompression */
	jpeg_finish_decompress(&cinfo);

	/* Release JPEG decompression object
	   This is an important step since it will release a good deal of memory.*/
	jpeg_destroy_decompress(&cinfo);

	if(use_CMYK == TRUE) {
		uint32_t i = 0, j = 0, size = 0;
		initData(CGE::CF_RGB888,width,height, NULL);
		size = 3 * width * height;

		if (imageData == NULL) {
			cc_free(output);
			return NULL;
		}

		if (imageData) {
			for (i = 0,j = 0; i < size; i += 3, j += 4) {
				// Also works without K, but has more contrast with K multiplied in
				//img->data[i + 0] = output[j + 2];
				//img->data[i + 1] = output[j + 1];
				//img->data[i + 2] = output[j + 0];
				imageData[i + 0] = (byte_t)(output[j+2] * (output[j + 3] / 255.f));
				imageData[i + 1] = (byte_t)(output[j+1] * (output[j + 3] / 255.f));
				imageData[i + 2] = (byte_t)(output[j+0] * (output[j + 3] / 255.f));
			}
		}
		cc_free(output);
		return TRUE;
	}
	return initData(CGE::CF_RGB888,width,height,output);
}
Ejemplo n.º 12
0
bool getBillingConfig(char* config)
{
	assert(config);
	FILE* cf;
	char buf[MAX_CONFIG_LENTH] = "";
	char buf_stay[MAX_CONFIG_LENTH] = "";

	if ( NULL == config)
	{
		addInfoLog(2,"failed to open config files name is empty");
		exit(0);
	}

	if ((cf = fopen(config, "r")) == NULL)
	{
		addInfoLog(2,"failed to open config files");
		exit(0);
	}

	struct billingConfNode *q = NULL;
	q = conf.confHead;
	uint32_t len;

	//get a line of info
	memset(buf,0,MAX_CONFIG_LENTH);
	while (fgets(buf, sizeof(buf) - 1, cf) )
	{
		//remove last char '\n'
		strcpy(buf_stay,buf);
		len = strlen(buf);
		if(len == 0 || buf[0] == '#')
			continue;
		*(buf + len - 1) = '\0';
		//finish check config file

		//token start
		char *token = strtok(buf, white_space);
		if (!token || strcasecmp(token, CONFIG_FIRST_FILED))
			continue;

		//the 2ND zone
		if (NULL == (token = strtok(NULL, white_space)))
			return false;

		if (strncmp(token, CONFIG_SECOND_FILED, sizeof(CONFIG_SECOND_FILED)))
		{
			char *tail = buf_stay + len - 3; 
			if (!strncmp(tail,"on",2))
			{
				conf.on_off = 1;
			}
			continue;
		}

		//the 3rd zone
		if (NULL == (token = strtok(NULL, white_space)))
			return false;

		if (strncmp(token, CONFIG_THIRD_FILED, sizeof(CONFIG_THIRD_FILED)))
			continue;

		//now finish check the first 3 zone like "cc_mod_billing sub_mod billingd"

		//now 4th zone
		if (NULL == (token = strtok(NULL, white_space)))
			return false;

		//get expect local on or off
		if( strcasecmp(token, "except_localhost") == 0 )
		{
			if (NULL == (token = strtok(NULL, white_space)))
				return false;

			if(!strcasecmp(token, "on"))
				conf.deny_local = 0;
			else if(!strcasecmp(token, "off"))
				conf.deny_local = 1;
		}

		//get expect chinache on or off
		if( strcasecmp(token, "except_chinacache") == 0 )
		{
			if (NULL == (token = strtok(NULL, white_space)))
				return false;

			if(!strcasecmp(token, "on"))
				conf.deny_chinacache = 0;
			else if(!strcasecmp(token, "off"))
				conf.deny_chinacache = 1;
		}
		//get path to write billing
		if( strcasecmp(token, "path") == 0 )
		{
			if (NULL == (token = strtok(NULL, white_space)))
				return false;

			strncpy(conf.path, token, MAX_PATH_LENTH);
			conf.path[MAX_PATH_LENTH] = '\0';
		}

		//get interval

		if( strcasecmp(token, "interval") == 0 )
		{
			if (NULL == (token = strtok(NULL, white_space)))
				return false;

			conf.interval = atoi(token);
		}

		//get regex
		if( strcasecmp(token, "regex") == 0 )
		{
			if (NULL == (token = strtok(NULL, white_space)))
				return false;


			//printf("---->regex = %s\n", token);

			struct billingConfNode *p = NULL;
			p = cc_malloc(sizeof(struct billingConfNode));
			if(!p)
			{
				//				printf("Error: malloc faild\n");
				return false;
			}


			strcpy(p->regDomain, token);

			//	printf("---->regex2 = %s\n", p->regDomain);

			p->regComp = (regex_t*)cc_malloc(sizeof(regex_t));

			if( regcomp(p->regComp, p->regDomain, REG_ICASE) != 0 )
			{
				addInfoLog(2,"regcomp error and exit!");
				exit(0);
			}


			//set new nod to 0.
			p->lbAttr.client.read_size = 0;
			p->lbAttr.client.write_size = 0;
			p->lbAttr.source.read_size = 0;
			p->lbAttr.source.write_size = 0;
			p->lbAttr.client.connection_times = 0;
			p->lbAttr.source.connection_times = 0;

			p->rbAttr.client.read_size = 0;
			p->rbAttr.client.write_size = 0;
			p->rbAttr.source.read_size = 0;
			p->rbAttr.source.write_size = 0;
			p->rbAttr.client.connection_times = 0;
			p->rbAttr.source.connection_times = 0;

			p->fbAttr.client.read_size = 0;
			p->fbAttr.client.write_size = 0;
			p->fbAttr.source.read_size = 0;
			p->fbAttr.source.write_size = 0;
			p->fbAttr.client.connection_times = 0;
			p->fbAttr.source.connection_times = 0;


			if(conf.confHead == NULL)
			{
				conf.confHead = p;
				q = p;
			}
			else
			{
				q->next = p;
				q = q->next;
			}
		}

		//get port
		if( strcasecmp(token, "port") == 0 )
		{
			token = strtok(NULL, white_space);

			if(!token)
				return false;

			uint32_t temp = atoi(token);
			if( (temp < 0) || (temp > 65336))
				return false;

			conf.port = temp;
		}
		if( strcasecmp(token, "debug_level") == 0 )
		{
			token = strtok(NULL, white_space);

			if(!token)
				return false;

			uint32_t temp = atoi(token);
			if( (temp < 0) || (temp > 3))
				return false;

			conf.debug_level = temp;
		}

		memset(buf,0,MAX_CONFIG_LENTH);
	}
	fclose(cf); //close config file
	char config_info[1024];
	addInfoLog(0,"we got these from config file squid.conf:");
	snprintf(config_info,1024,"\n\t\t conf.port =%d \n \t\t conf.interval= %d  \n\t\t conf.deny_local=%d \n\t\t conf.deny_chinacache=%d \n\t\t conf.debug_level=%d \n\t\t conf.path=%s",
			conf.port,conf.interval,conf.deny_local,conf.deny_chinacache,conf.debug_level,conf.path);
	addInfoLog(0,config_info);

	return true;
}
Ejemplo n.º 13
0
bool writelog()
{
	char entryInfo[1024];
	time_t oldtime = last_billing_out_time;
	time_t actual_time = last_billing_out_time;//实际写日志的时间,用来消除尖峰用的。
	last_billing_out_time = time(NULL);
	time_t this_up_time = mytime(NULL);

	//hashtable中的节点总数
	uint32_t entry_count = hashtable_entry_count;

	//全部的hashtable节点指针
	struct hash_entry** entry_array = cc_malloc(sizeof(struct hash_entry*) * entry_count);
	memset(entry_array, 0, sizeof(struct hash_entry*) * entry_count);

	//复制hashtable to an array
	get_all_entry(entry_array);


	struct wbilling* wb = cc_malloc(sizeof(struct wbilling));
	memset(wb, 0, sizeof(struct wbilling));

	pthread_t wptid;

	//此时已经完成数据的收集.
	//按照标准打印机可.

	char billing_name[MAX_PATH_LENTH];
	char filename[MAX_PATH_LENTH] ;
	memset(filename,0,MAX_PATH_LENTH);
	memset(billing_name,0,MAX_PATH_LENTH);

	char billing_file[5000000];
	memset(billing_file,0,5000000);
	char* bill = billing_file;
	uint32_t len = 0;

	//匹配到的放到正则中,匹配不到的话,放到这里
	struct hash_entry** left_entry = cc_malloc(sizeof(struct hash_entry*) * entry_count);
	memset(left_entry, 0, sizeof(struct hash_entry*) * entry_count);

	uint32_t left_entry_count = 0;
	uint32_t i = 0;
	uint32_t real_data = 0;

	struct billingConfNode* qRegex = conf.confHead;
	struct billingConfNode* rLoop = NULL;

	FILE * fd_billing_file;

	dealwith_filename(filename);

	for( i = 0 ; i < entry_count ; i++ ) {

		//检查一下是不是正则串里面的
		qRegex = conf.confHead;
		rLoop = NULL;
		for( rLoop = qRegex; rLoop; rLoop = rLoop->next) {

			if( regCheck(rLoop->regComp, entry_array[i]->host) == 0 ) {
				flowSum(&(rLoop->rbAttr), &(entry_array[i]->remote));
				flowSum(&(rLoop->lbAttr), &(entry_array[i]->local));
				flowSum(&(rLoop->fbAttr), &(entry_array[i]->fc));
				break;
			}
		}

		if( rLoop != NULL )
			continue;

		left_entry[left_entry_count] = entry_array[i];
		left_entry_count++;
	}

	//this used to cut the point value --start
	if (true == flag_cut_point) {
		//uint32_t file_recap_num = (last_billing_out_time - oldtime)/(conf.interval); 
		uint32_t file_recap_num = (this_up_time - last_up_time)/(conf.interval); 
		if (file_recap_num < 2)
		{
			addInfoLog(2,"something wrong happend \n");
			flag_cut_point = false;
			return false;
		}

		uint32_t time_split = (this_up_time - last_up_time)%(conf.interval);
		//判断时间间隔长短,采取四舍五入;
		if(time_split *2 > conf.interval)
		{
			file_recap_num ++;
		}

		snprintf(entryInfo,1024,"%d billing files will be generated, left_entry_count is %d\n", file_recap_num, left_entry_count);
		addInfoLog(0,entryInfo);
		uint32_t count = 0;  //将积累的流量写到多个文件。
		if (entry_count > 0)
		{
			for (count = 0; count<file_recap_num; count++)
			{
				memset(billing_file,0,5000000);
				len =0;
				actual_time += conf.interval;

				removeFlow(left_entry, left_entry_count);
				//	if (0 == left_entry_count)
				//		continue;

				snprintf(entryInfo,1024,"entry_count=%d,left_entry_count=%d recap_num=%d\n",entry_count,left_entry_count,file_recap_num);
				addInfoLog(0,entryInfo);
				//打印表头时间

				if(count < file_recap_num-1)
					len += sprintf(bill+len, "start in %u, to %u\n", (unsigned int)oldtime, (unsigned int)actual_time);
				else
					len += sprintf(bill+len, "start in %u, to %u\n", (unsigned int)oldtime, (unsigned int)last_billing_out_time);

				writelog_body(bill,len,file_recap_num,left_entry_count,left_entry,&real_data);

				if(strlen(billing_file) > 5000000)
				{
					printf("too many billing lines, quit\n");
					addInfoLog(2,"too many billing lines, quit");
					exit(1);
				}

				dealwith_filename(filename);
				memcpy(billing_name,filename,strlen(filename)-4);
				billing_name[strlen(filename)-4+1] = 0; // rm .tmp


				if( (fd_billing_file = fopen(filename, "w")) == NULL ) {
					snprintf(entryInfo,1024,"billing_file %s open fail",filename);  
					addInfoLog(2,entryInfo);
					exit(1);
				}       

				fprintf(fd_billing_file, "%s", billing_file);
				fflush(fd_billing_file);

				if(-1 == rename(filename, billing_name)) {
					snprintf(entryInfo,1024, "copy temp file to billing file error");
					addInfoLog(2,entryInfo);
					exit(1);
				}       

				fclose(fd_billing_file);
				oldtime = actual_time;

			}
		}

		flag_cut_point = false;
		for(i = 0; i < entry_count; i++)
			cc_free(entry_array[i]);

		cc_free(entry_array);
		cc_free(left_entry);
	}
	//this used to cut the point value --end
	else {
		snprintf(entryInfo,1024,"entry_count=%d,left_entry_count=%d\n",entry_count,left_entry_count);
		addInfoLog(0,entryInfo);


		//remove flow stat if set expect local or FC
		removeFlow(left_entry, left_entry_count);

		//打印表头时间
		len += sprintf(bill+len, "start in %u, to %u\n", (unsigned int)oldtime, (unsigned int)last_billing_out_time);

		writelog_body(bill,len,1,left_entry_count,left_entry,&real_data);

		for(i = 0; i < entry_count; i++)
			cc_free(entry_array[i]);

		cc_free(entry_array);
		cc_free(left_entry);

		wb->filename = cc_malloc(strlen(filename)+1);
		wb->content = cc_malloc(strlen(billing_file)+1);	
		memcpy(wb->filename, filename, strlen(filename)+1);
		memcpy(wb->content, billing_file, strlen(billing_file)+1);

		if(1 == real_data)
		{
			if(pthread_create(&wptid, NULL, writeFile, wb) != 0)
			{       
				addInfoLog(2,"A billing file write thread create failed. This file missed");
			}       
			pthread_detach(wptid);
		}
		else
		{
			snprintf(entryInfo,1024,"file[%s] has no data, discard it \n",wb->filename);
			addInfoLog(0,entryInfo);
		}
	}
	last_up_time = mytime(NULL);
	return true;
}
Ejemplo n.º 14
0
int parse_url_list(xmlNodePtr cur,char *token,rf_cli_session *sess){
	xmlChar *key,*id;
	cur = cur->xmlChildrenNode;

	bool b_find = false;

	while (cur != NULL) {
		if ((!xmlStrcmp(cur->name, (const xmlChar *)token))) {
			key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
			if(! (key && xmlStrlen(key))){
					xmlFree(key);
					goto NEXT;
			}

			id = xmlGetProp(cur,(const xmlChar *)"id");
			if(! (id && xmlStrlen(id))){
					xmlFree(id);
					xmlFree(key);
					goto NEXT;
			}

			b_find = true;

			rf_url_list * url = cc_malloc(sizeof(rf_url_list));
			url->buffer = cc_malloc(xmlStrlen(key) + 1);
			strcpy(url->buffer,(char *)key);

			/*
			//here we don't want to decode '&'
			char *c,*d;
			while((c = strstr(url->buffer,"%26")) != NULL){
			 *c++ = '&';
			 d = c + 2;
			 while((*d) != '\0') *c++ = *d++;
			 *c = '\0';
			 }
			 */

			url->len = xmlStrlen(key);
			url->id = strtoll((const char *)id, (char **)NULL, 10);

			xmlFree(key);
			xmlFree(id);

			/* Add Start: url remove host, by xin.yao, 2012-03-04 */
			urlRemoveHost(url);
			/* Add Ended: by xin.yao */

			cclog(4,"url: %s,id : %"PRINTF_UINT64_T, url->buffer,url->id);

			//add to url list
			if(sess->url_list == NULL){
				sess->url_list = url;
			}else{
				url->next = sess->url_list;
				sess->url_list = url;
			}

			sess->url_number++;
		}

NEXT:
		cur = cur->next;
	}

	return b_find ? RF_OK : RF_ERR_XML_PARSE;
}
Ejemplo n.º 15
0
int rf_parse_dir(xmlNodePtr cur,rf_cli_session *sess){
	if(sess->params == NULL){
		sess->params = cc_malloc(sizeof(rf_cli_dir_params));
	}

	rf_cli_dir_params *dir_params = (rf_cli_dir_params *)sess->params;

	bool b_action = false;
	bool b_dir = false;

	while (cur != NULL) {
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"action"))){
			xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
			dir_params->action = strtol((const char *)key, (char **)NULL, 10);
			b_action = true;

			cclog(4,"action : %s", key);
			xmlFree(key);
		}

		if ((!xmlStrcmp(cur->name, (const xmlChar *)"report_address"))){
			xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
			if(dir_params->report_address == NULL){
				dir_params->report_address = strdup((const char *)key);
			}

			cclog(4,"report_address: %s", dir_params->report_address);
			xmlFree(key);
		}

		if ((!xmlStrcmp(cur->name, (const xmlChar *)"dir"))){
			xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
			cclog(4,"dir : %s", key);

			if(xmlStrlen(key) > strlen("http://")){
				rf_url_list * url = cc_malloc(sizeof(rf_url_list));
				url->buffer = cc_malloc(xmlStrlen(key) + 1);
				strcpy(url->buffer,(char *)key);
				url->len = xmlStrlen(key);

				assert(sess->url_list == NULL);
				sess->url_list = url;
				b_dir = true;
			}
			else{
				cclog(1,"invalid url : %s",key);
				xmlFree(key);
				return RF_ERR_XML_INVALID_URL;
			}

			xmlFree(key);
		}

		cur = cur->next;
	}

	if(!(b_action && b_dir)){
		return RF_ERR_XML_PARSE;
	}

	return RF_OK;
}
Ejemplo n.º 16
0
http_response_t* http_parser(const char* head)
{
	http_response_t *response = NULL;
	const char_t *s = head;
	const char_t *tmp = NULL;
	int32_t tmp_len = 0;
	http_field_t *field = NULL;

	if (head == NULL)
		return NULL;

	response = (http_response_t *)cc_calloc(1, sizeof(http_response_t));

	s = _skip_space(s);

	response->http_major = 0;
	response->http_minor = 0;
	response->status = 0;
	cc_double_link_cleanup(&response->link);

	//HTTP 1.0 200
	if (_tolower(*s) == 'h' && _tolower(*(s + 1)) == 't' && _tolower(*(s + 2)) == 't' && _tolower(*(s + 3)) == 'p' && *(s + 4) == '/') {
		s = _skip_space(s + 5);

		if (_istdigit(*s)) {
			do
			response->http_major = (response->http_major * 10) + (*s++ - _T('0'));
			while (_istdigit(*s));

			if (*s == '.') {
				s = (s + 1);
				do
				response->http_minor = (response->http_minor * 10) + (*s++ - _T('0'));
				while (_istdigit(*s));
			}
		}

		//get http status
		if (*s == ' ') {
			s = (s + 1);
			do
			response->status = (response->status * 10) + (*s++ - _T('0'));
			while (_istdigit(*s));
		}
	}

	s = strstr(s, CRLF);
	if (s == NULL) {
		cc_free(response);
		return NULL;
	}

	while(*s) {
		field = (http_field_t *)cc_calloc(1, sizeof(http_field_t));

		s = _skip_space(s);
		tmp = s;
		tmp_len = 0;

		while(*tmp){
			tmp++;
			++tmp_len;
			if (*tmp == ':' || *tmp == 0) {
				field->field_name = (char_t *)cc_malloc(sizeof(char_t) * (tmp_len + 1));
				strncpy(field->field_name, s, tmp_len);
				field->field_name[tmp_len] = 0;
				break;
			}
		}

		if (tmp == NULL) {
			cc_free(field->field_name);
			cc_free(field);
			return response;
		}

		s = _skip_space(tmp + 1);
		tmp = s;
		tmp_len = 0;

		while(*tmp){
			tmp++;
			++tmp_len;
			if ((*tmp == CR && *(tmp + 1) == LF) || *tmp == 0) {
				field->field_value = (char_t *)cc_malloc(sizeof(char_t) * (tmp_len + 1));
				strncpy(field->field_value, s, tmp_len);
				field->field_value[tmp_len] = 0;
				break;
			}
		}

		cc_double_link_push_back(&response->link, &field->base_address);

		if(*tmp && (*tmp == CR && *(tmp + 1) == LF)) {
			s = tmp + 2;
			//结尾了
			if(*s && (*s == CR && *(s + 1) == LF))
				return response;
		}

	} 

	return response;
}