• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ONION_DEBUG0函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ONION_DEBUG0函数的典型用法代码示例。如果您正苦于以下问题:C++ ONION_DEBUG0函数的具体用法?C++ ONION_DEBUG0怎么用?C++ ONION_DEBUG0使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ONION_DEBUG0函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: onion_handler_handle

/**
 * @short Tryes to handle the petition with that handler.
 * @memberof onion_handler_t
 *
 * It needs the handler to handle, the request and the response.
 *
 * It checks this parser, and siblings.
 * 
 * @returns If can not, returns OCS_NOT_PROCESSED (0), else the onion_connection_status. (normally OCS_PROCESSED)
 */
onion_connection_status onion_handler_handle(onion_handler *handler, onion_request *request, onion_response *response){
	onion_connection_status res;
	while (handler){
		if (handler->handler){
#ifdef __DEBUG0__
			char **bs=backtrace_symbols((void * const *)&handler->handler, 1);
			ONION_DEBUG0("Calling handler: %s",bs[0]);
			/* backtrace_symbols is explicitly documented
			   to malloc. We need to call the system free
			   routine, not our onion_low_free ! */
			onion_low_free(bs); /* Can't be onion_low_free.... */
#endif
			res=handler->handler(handler->priv_data, request, response);
			ONION_DEBUG0("Result: %d",res);
			if (res){
				// write pending data.
				if (!(response->flags&OR_HEADER_SENT) && response->buffer_pos<sizeof(response->buffer))
					onion_response_set_length(response, response->buffer_pos);
				onion_response_flush(response);
				if (res==OCS_WEBSOCKET){
					if (request->websocket)
						return onion_websocket_call(request->websocket);
					else{
						ONION_ERROR("Handler did set the OCS_WEBSOCKET, but did not initialize the websocket on this request.");
						return OCS_INTERNAL_ERROR;
					}
				}
				return res;
			}
		}
		handler=handler->next;
	}
	return OCS_NOT_PROCESSED;
}
开发者ID:MariadeAnton,项目名称:onion,代码行数:44,代码来源:handler.c


示例2: ONION_DEBUG0

static onion_dict *onion_sessions_mem_get(onion_sessions *sessions, const char *session_id){
	ONION_DEBUG0("Accessing session '%s'",session_id);
	onion_dict *sess=onion_dict_get_dict(sessions->data, session_id);
	if (!sess){
		ONION_DEBUG0("Unknown session '%s'.", session_id);
		return NULL;
	}
	return onion_dict_dup(sess);
}
开发者ID:MariadeAnton,项目名称:onion,代码行数:9,代码来源:sessions_mem.c


示例3: onion_response_flush

/**
 * @short Writes all buffered output waiting for sending.
 * @ingroup response
 *
 * If header has not been sent yet (delayed), it uses a temporary buffer to send it now. This
 * way header can use the buffer_size information to send the proper content-length, even when it
 * wasnt properly set by programmer. Whith this information its possib to keep alive the connection
 * on more cases.
 */
int onion_response_flush(onion_response * res) {
  res->sent_bytes += res->buffer_pos;
  res->sent_bytes_total += res->buffer_pos;
  if (res->buffer_pos == 0)     // Not used.
    return 0;
  if (!(res->flags & OR_HEADER_SENT)) { // Automatic header write
    ONION_DEBUG0
        ("Doing fast header hack: store current buffer, send current headers. Resend buffer.");
    char tmpb[sizeof(res->buffer)];
    int tmpp = res->buffer_pos;
    memcpy(tmpb, res->buffer, res->buffer_pos);
    res->buffer_pos = 0;

    onion_response_write_headers(res);
    onion_response_write(res, tmpb, tmpp);
    return 0;
  }
  if (res->flags & OR_SKIP_CONTENT)     // HEAD request
    return 0;
  ONION_DEBUG0("Flush %d bytes", res->buffer_pos);

  onion_request *req = res->request;
  ssize_t(*write) (onion_request *, const char *data, size_t len);
  write = req->connection.listen_point->write;

  ssize_t w;
  off_t pos = 0;
  //ONION_DEBUG0("Write %d bytes",res->buffer_pos);
  if (res->flags & OR_CHUNKED) {
    char tmp[16];
    snprintf(tmp, sizeof(tmp), "%X\r\n", (unsigned int)res->buffer_pos);
    if ((w = write(req, tmp, strlen(tmp))) <= 0) {
      ONION_WARNING("Error writing chunk encoding length. Aborting write.");
      return OCS_CLOSE_CONNECTION;
    }
    ONION_DEBUG0("Write %d-%d bytes", res->buffer_pos, w);
  }
  while ((w =
          write(req, &res->buffer[pos], res->buffer_pos)) != res->buffer_pos) {
    if (w <= 0 || res->buffer_pos < 0) {
      ONION_ERROR("Error writing %d bytes. Maybe closed connection. Code %d. ",
                  res->buffer_pos, w);
      perror("");
      res->buffer_pos = 0;
      return OCS_CLOSE_CONNECTION;
    }
    pos += w;
    ONION_DEBUG0("Write %d-%d bytes", res->buffer_pos, w);
    res->buffer_pos -= w;
  }
  if (res->flags & OR_CHUNKED) {
    write(req, "\r\n", 2);
  }
  res->buffer_pos = 0;
  return 0;
}
开发者ID:davidmoreno,项目名称:onion,代码行数:65,代码来源:response.c


示例4: parse_POST_multipart_content_type

static onion_connection_status parse_POST_multipart_content_type(onion_request *req, onion_buffer *data){
	onion_token *token=req->parser_data;
	int res=token_read_until(token, data,';');

	if (res<=1000)
		return res;

	//ONION_DEBUG("Got content type %s",token->str);

	onion_multipart_buffer *multipart=(onion_multipart_buffer*)token->extra;
	const char *name;
	name=strstr(token->str, "filename=");
	if (name){
		int l=strlen(token->str)-9;
		if (l>multipart->post_total_size){
			ONION_ERROR("Post buffer exhausted. content-Length wrong passed.");
			return OCS_INTERNAL_ERROR;
		}
		multipart->filename=multipart->data;
		memcpy(multipart->filename, name+9, l);
		multipart->filename[l]=0;
		multipart->data=multipart->data+l+1;
		if (*multipart->filename=='"' && multipart->filename[l-2]=='"'){
			multipart->filename[l-2]='\0';
			multipart->filename++;
		}
		ONION_DEBUG0("Set filename '%s'",multipart->filename);
	}
	else{
		name=strstr(token->str, "name=");
		if (name){
			int l=strlen(token->str)-5;
			if (l>multipart->post_total_size){
				ONION_ERROR("Post buffer exhausted. Content-Length had wrong size.");
				return OCS_INTERNAL_ERROR;
			}
			multipart->name=multipart->data;
			memcpy(multipart->name, name+5, l);
			multipart->name[l]=0;
			if (*multipart->name=='"' && multipart->name[l-2]=='"'){
				l-=2;
				multipart->name[l]='\0';
				multipart->name++;
			}
			multipart->data=multipart->name+l+1;
			ONION_DEBUG0("Set field name '%s'",multipart->name);
		}
	}


	if (res==STRING_NEW_LINE){
		req->parser=parse_POST_multipart_headers_key;
		return OCS_NEED_MORE_DATA;
	}
	return OCS_NEED_MORE_DATA;
}
开发者ID:CarlosDomingues,项目名称:onion,代码行数:56,代码来源:request_parser.c


示例5: onion_sessions_redis_get

static onion_dict* onion_sessions_redis_get(onion_sessions* sessions, const char *session_id)
{
    onion_session_redis *p = sessions->data;
    ONION_DEBUG0("Load session %s", session_id);
    onion_dict *ret = NULL;

#ifdef HAVE_PTHREADS
    pthread_mutex_lock(&p->mutex);
#endif

    // When commands are sent via redisCommand, they are interpolated by the library
    // so it will avoid any type of command injection. No need to worry about sending
    // the session_id directly to redis.
    redisReply* reply = redisCommand(p->context, "HEXISTS SESSIONS %b", session_id, strlen(session_id));

    if(reply->type != REDIS_REPLY_INTEGER)
    {
        ONION_ERROR("Error getting session_id");
        freeReplyObject(reply);
        goto exit;
    }
    else
    {
        if(reply->integer == 1)
        {
            freeReplyObject(reply);
            reply = redisCommand(p->context, "HGET SESSIONS %b", session_id, strlen(session_id));

            if(reply->type != REDIS_REPLY_STRING)
            {
                ONION_ERROR("Error loading session.");
                freeReplyObject(reply);
                goto exit;
            }
            else
            {
                ret = onion_dict_from_json(reply->str);
                freeReplyObject(reply);
                goto exit;
            }
        }
        else
        {
            ONION_DEBUG0("No session found. Returning NULL");
            freeReplyObject(reply);
            goto exit;
        }
    }
exit:
#ifdef HAVE_PTHREADS
    pthread_mutex_unlock(&p->mutex);
#endif
    return ret;
}
开发者ID:Zhangli88,项目名称:onion,代码行数:54,代码来源:sessions_redis.c


示例6: onion_webdav_propfind

/**
 * @short Handles a propfind
 * 
 * @param path the shared path.
 */
onion_connection_status onion_webdav_propfind(const char *filename, onion_webdav *wd, onion_request* req, onion_response* res){
	// Prepare the basepath, necesary for props.
	char *basepath=NULL;
	int pathlen=0;
	const char *current_path=onion_request_get_path(req);
	const char *fullpath=onion_request_get_fullpath(req);
	pathlen=(current_path-fullpath);
	basepath=alloca(pathlen+1);
	memcpy(basepath, fullpath, pathlen+1);
	ONION_DEBUG0("Pathbase initial <%s> %d", basepath, pathlen); 
	while(basepath[pathlen]=='/' && pathlen>0)
		pathlen--;
	basepath[pathlen+1]=0;
				 
	ONION_DEBUG0("PROPFIND; pathbase %s", basepath);
	int depth;
	{
		const char *depths=onion_request_get_header(req, "Depth");
		if (!depths){
			ONION_ERROR("Missing Depth header on webdav request");
			return OCS_INTERNAL_ERROR;
		}
		if (strcmp(depths,"infinity")==0){
			ONION_ERROR("Infinity depth not supported yet.");
			return OCS_INTERNAL_ERROR;
		}
		depth=atoi(depths);
	}

	int props=onion_webdav_parse_propfind(onion_request_get_data(req));
	ONION_DEBUG("Asking for props %08X, depth %d", props, depth);
	
	onion_block *block=onion_webdav_write_propfind(basepath, filename, onion_request_get_path(req), depth, props);
	
	if (!block) // No block, resource does not exist
		return onion_shortcut_response("Not found", HTTP_NOT_FOUND, req, res);
		
	ONION_DEBUG0("Printing block %s", onion_block_data(block));
	
	onion_response_set_header(res, "Content-Type", "text/xml; charset=\"utf-8\"");
	onion_response_set_length(res, onion_block_size(block));
	onion_response_set_code(res, HTTP_MULTI_STATUS);
	onion_response_write_headers(res);
	onion_response_flush(res);
	
	onion_response_write(res, onion_block_data(block), onion_block_size(block));
	
	onion_block_free(block);
	
	return OCS_PROCESSED;
}
开发者ID:hchtym,项目名称:onion,代码行数:56,代码来源:webdav.c


示例7: prepare_PUT

/**
 * @short Prepares the PUT
 *
 * It saves the data to a temporal file, which name is stored at data.
 */
static onion_connection_status prepare_PUT(onion_request *req){
	onion_token *token=req->parser_data;
	const char *content_size=onion_dict_get(req->headers, "Content-Length");
	if (!content_size){
		ONION_ERROR("I need the Content-Length header to get data");
		return OCS_INTERNAL_ERROR;
	}
	size_t cl=atol(content_size);

	if (cl>req->connection.listen_point->server->max_file_size){
		ONION_ERROR("Trying to PUT a file bigger than allowed size");
		return OCS_INTERNAL_ERROR;
	}

	req->data=onion_block_new();

	char filename[]="/tmp/onion-XXXXXX";
	int fd=mkstemp(filename);
	if (fd<0)
		ONION_ERROR("Could not create temporary file at %s.", filename);

	onion_block_add_str(req->data, filename);
	ONION_DEBUG0("Creating PUT file %s (%d bytes long)", filename, token->extra_size);

	if (!req->FILES){
		req->FILES=onion_dict_new();
	}
	{
	const char *filename=onion_block_data(req->data);
	onion_dict_add(req->FILES,"filename", filename, 0);
	}


	if (cl==0){
		ONION_DEBUG0("Created 0 length file");
		close(fd);
		return OCS_REQUEST_READY;
	}

	int *pfd=onion_low_scalar_malloc(sizeof(fd));
	*pfd=fd;

	assert(token->extra==NULL);
	token->extra=(char*)pfd;
	token->extra_size=cl;
	token->pos=0;

	req->parser=parse_PUT;
	return OCS_NEED_MORE_DATA;
}
开发者ID:CarlosDomingues,项目名称:onion,代码行数:55,代码来源:request_parser.c


示例8: onion_request_get_cookies_dict

/**
 * @short Gets the dict with the cookies
 * @memberof onion_request_t
 *
 * @param req Request to get the cookies from
 *
 * @returns A dict with all the cookies. It might be empty.
 *
 * First call it generates the dict.
 */
onion_dict* onion_request_get_cookies_dict(onion_request* req) {
    if (req->cookies)
        return req->cookies;

    req->cookies=onion_dict_new();

    const char *ccookies=onion_request_get_header(req, "Cookie");
    if (!ccookies)
        return req->cookies;
    char *cookies=onion_low_strdup(ccookies); // I prepare a temporary string, will modify it.
    char *val=NULL;
    char *key=NULL;
    char *p=cookies;

    int first=1;
    while(*p) {
        if (*p!=' ' && !key && !val) {
            key=p;
        }
        else if (*p=='=' && key && !val) {
            *p=0;
            val=p+1;
        }
        else if (*p==';' && key && val) {
            *p=0;
            if (first) {
                // The first cookie is special as it is the pointer to the reserved area for all the keys and values
                // for all th eother cookies, to free at dict free.
                onion_dict_add(req->cookies, cookies, val, OD_FREE_KEY);
                first=0;
            }
            else
                onion_dict_add(req->cookies, key, val, 0); /// Can use as static data as will be freed at first cookie free
            ONION_DEBUG0("Add cookie <%s>=<%s> %d", key, val, first);
            val=NULL;
            key=NULL;
        }
        p++;
    }
    if (key && val && val<p) { // A final element, with value.
        if (first)
            onion_dict_add(req->cookies, cookies, val, OD_FREE_KEY);
        else
            onion_dict_add(req->cookies, key, val, 0);
        ONION_DEBUG0("Add cookie <%s>=<%s> %d", key, val, first);
    }

    return req->cookies;
}
开发者ID:scottrfrancis,项目名称:onion,代码行数:59,代码来源:request.c


示例9: onion_request_parse_query_to_dict

/**
 * @short Parses the query part to a given dictionary.
 *
 * The data is overwriten as necessary. It is NOT dupped, so if you free this char *p, please free the tree too.
 */
static void onion_request_parse_query_to_dict(onion_dict *dict, char *p){
	ONION_DEBUG0("Query to dict %s",p);
	char *key=NULL, *value=NULL;
	int state=0;  // 0 key, 1 value
	key=p;
	while(*p){
		if (state==0){
			if (*p=='='){
				*p='\0';
				value=p+1;
				state=1;
			}
			else if (*p=='&'){
				*p='\0';
				onion_unquote_inplace(key);
				ONION_DEBUG0("Adding key %s",key);
				onion_dict_add(dict, key, "", 0);
				key=p+1;
				state=0;
			}
		}
		else{
			if (*p=='&'){
				*p='\0';
				onion_unquote_inplace(key);
				onion_unquote_inplace(value);
				ONION_DEBUG0("Adding key %s=%-16s",key,value);
				onion_dict_add(dict, key, value, 0);
				key=p+1;
				state=0;
			}
		}
		p++;
	}
	if (state==0){
		if (key[0]!='\0'){
			onion_unquote_inplace(key);
			ONION_DEBUG0("Adding key %s",key);
			onion_dict_add(dict, key, "", 0);
		}
	}
	else{
		onion_unquote_inplace(key);
		onion_unquote_inplace(value);
		ONION_DEBUG0("Adding key %s=%-16s",key,value);
		onion_dict_add(dict, key, value, 0);
	}
}
开发者ID:CarlosDomingues,项目名称:onion,代码行数:53,代码来源:request_parser.c


示例10: parse_PUT

/**
 * @short Reads from the data to fulfill content-length data.
 * 
 * All data is writen a temporal file, which will be removed later.
 */
static onion_connection_status parse_PUT(onion_request *req, onion_buffer *data){
	onion_token *token=req->parser_data;
	int length=data->size-data->pos;
	int exit=0;
	
	if (length>=token->extra_size-token->pos){
		exit=1;
		length=token->extra_size-token->pos;
	}

	//ONION_DEBUG0("Writing %d. %d / %d bytes", length, token->pos+length, token->extra_size);

	int *fd=(int*)token->extra;
	ssize_t w=write(*fd, &data->data[data->pos], length);
	if (w<0){
		ONION_ERROR("Could not write all data to temporal file.");
		return OCS_INTERNAL_ERROR;
	}
	data->pos+=length;
	token->pos+=length;

#if __DEBUG__
	const char *filename=onion_block_data(req->data);
	ONION_DEBUG0("Done with PUT. Created %s (%d bytes)", filename, token->pos);
#endif
	
	if (exit){
		close (*fd);
		free(fd);
		token->extra=NULL;
		return onion_request_process(req);
	}
	
	return OCS_NEED_MORE_DATA;
}
开发者ID:adnandzebic,项目名称:onion,代码行数:40,代码来源:request_parser.c


示例11: onion_poller_add

/**
 * @short Adds a file descriptor to poll.
 * @memberof onion_poller_t
 * @ingroup poller
 *
 * When new data is available (read/write/event) the given function
 * is called with that data.
 *
 * Once the slot is added is not safe anymore to set data on it, unless its detached from the epoll. (see EPOLLONESHOT)
 */
int onion_poller_add(onion_poller *poller, onion_poller_slot *el){
	ONION_DEBUG0("Adding fd %d for polling (%d)", el->fd, poller->n);

	pthread_mutex_lock(&poller->mutex);
	// I like head to be always the same, so I do some tricks to keep it. This is beacuse at head normally I have the listen fd, which is very accessed
	if (!poller->head)
		poller->head=el;
	else{
		el->next=poller->head->next;
		poller->head->next=el;
		poller->n++;
	}
	pthread_mutex_unlock(&poller->mutex);

	struct epoll_event ev;
	memset(&ev, 0, sizeof(ev));
	ev.events=el->type;
	ev.data.ptr=el;
	if (epoll_ctl(poller->fd, EPOLL_CTL_ADD, el->fd, &ev) < 0){
		ONION_ERROR("Error add descriptor to listen to. %s", strerror(errno));
		return 1;
	}
	onion_poller_timer_check(poller, el->timeout_limit);

	return 1;
}
开发者ID:LiKun-8,项目名称:onion,代码行数:36,代码来源:poller.c


示例12: onion_poller_free

/// @memberof onion_poller_t
void onion_poller_free(onion_poller *p){
	ONION_DEBUG("Free onion poller: %d waiting", p->n);
	p->stop=1;
	close(p->fd);
	// Wait until all pollers exit.

	if (pthread_mutex_trylock(&p->mutex)>0){
		ONION_WARNING("When cleaning the poller object, some poller is still active; not freeing memory");
	}
	else{
		onion_poller_slot *next=p->head;
		while (next){
			onion_poller_slot *tnext=next->next;
			if (next->shutdown)
				next->shutdown(next->shutdown_data);
			next=tnext;
		}
		pthread_mutex_unlock(&p->mutex);

		if (p->eventfd>=0)
			close(p->eventfd);
		if (p->timerfd>=0)
			close(p->timerfd);

		onion_poller_static_deinit();

		onion_low_free(p);
	}
	ONION_DEBUG0("Done");
}
开发者ID:LiKun-8,项目名称:onion,代码行数:31,代码来源:poller.c


示例13: parse_headers_KEY

static onion_connection_status parse_headers_KEY(onion_request *req, onion_buffer *data){
	onion_token *token=req->parser_data;
	
	int res=token_read_KEY(token, data);

	if (res<=1000)
		return res;

  ONION_DEBUG0("Got %d at KEY",res);
  
	if ( res == NEW_LINE ){
#if 0
		if ((req->flags&OR_METHODS)==OR_POST)
			return prepare_POST(req);
#endif
		if ((req->flags&OR_METHODS)==OR_PUT)
			return prepare_PUT(req);
		if (onion_request_get_header(req, "Content-Length")){ // Soem length, not POST, get data.
			int n=atoi(onion_request_get_header(req, "Content-Length"));
			if (n>0)
				return prepare_CONTENT_LENGTH(req);
		}
		
		return onion_request_process(req);
	}
	
	token->extra=strdup(token->str);
	
	req->parser=parse_headers_VALUE;
	return parse_headers_VALUE(req, data);
}
开发者ID:IPInfusion,项目名称:SDN-IP,代码行数:31,代码来源:request_parser.c


示例14: onion_request_free

/**
 * @short Deletes a request and all its data
 * @memberof onion_request_t
 */
void onion_request_free(onion_request *req){
  ONION_DEBUG0("Free request %p", req);
	onion_dict_free(req->headers);
	
	if (req->parser_data){
		onion_request_parser_data_free(req->parser_data);
		req->parser_data=NULL;
	}
	
	if (req->fullpath)
		free(req->fullpath);
	if (req->GET)
		onion_dict_free(req->GET);
	if (req->POST)
		onion_dict_free(req->POST);
	if (req->FILES){
		onion_dict_preorder(req->FILES, unlink_files, NULL);
		onion_dict_free(req->FILES);
	}
	if (req->parser_data)
		free(req->parser_data);
	if (req->client_info)
		free(req->client_info);
	if (req->session_id)
		free(req->session_id);
	if (req->session)
		onion_dict_free(req->session); // Not really remove, just dereference
	if (req->data)
		onion_block_free(req->data);

	free(req);
}
开发者ID:cemonds,项目名称:onion,代码行数:36,代码来源:request.c


示例15: onion_request_guess_session_id

/**
 * @short Gets the sessionid cookie, if any, and sets it to req->session_id.
 * @memberof onion_request_t
 */
void onion_request_guess_session_id(onion_request *req){
	if (req->session_id) // already known.
		return;
	const char *v=onion_dict_get(req->headers, "Cookie");
	ONION_DEBUG("Session ID, maybe from %s",v);
	char *r=NULL;
	onion_dict *session;
	
	do{ // Check all possible sessions
		if (r)
			free(r);
		if (!v)
			return;
		v=strstr(v,"sessionid=");
		if (!v) // exit point, no session found.
			return;
		v+=10;
		r=strdup(v); // Maybe allocated more memory, not much anyway.
		char *p=r;
		while (*p!='\0' && *p!=';') p++;
		*p='\0';
		ONION_DEBUG0("Checking if %s exists in sessions", r);
		session=onion_sessions_get(req->server->sessions, r);
	}while(!session);
	
	req->session_id=r;
	req->session=session;
	ONION_DEBUG("Session ID, from cookie, is %s",req->session_id);
}
开发者ID:cemonds,项目名称:onion,代码行数:33,代码来源:request.c


示例16: onion_request_clean

/**
 * @short Cleans a request object to reuse it.
 * @memberof onion_request_t
 */
void onion_request_clean(onion_request* req){
  ONION_DEBUG0("Clean request %p", req);
  onion_dict_free(req->headers);
  req->headers=onion_dict_new();
  if (req->parser_data){
    onion_request_parser_data_free(req->parser_data);
    req->parser_data=NULL;
  }
  req->parser=NULL;
  req->flags&=0x0F00; // I keep server flags.
  if (req->fullpath){
    free(req->fullpath);
    req->path=req->fullpath=NULL;
  }
  if (req->GET){
    onion_dict_free(req->GET);
    req->GET=NULL;
  }
  if (req->POST){
    onion_dict_free(req->POST);
    req->POST=NULL;
  }
  if (req->FILES){
    onion_dict_preorder(req->FILES, unlink_files, NULL);
    onion_dict_free(req->FILES);
    req->FILES=NULL;
  }
  if (req->data){
    onion_block_free(req->data);
    req->data=NULL;
  }
}
开发者ID:cemonds,项目名称:onion,代码行数:36,代码来源:request.c


示例17: onion_response_write_headers

/**
 * @short Writes all the header to the given response
 * @memberof onion_response_t
 * @ingroup response
 *
 * It writes the headers and depending on the method, return OR_SKIP_CONTENT. this is set when in head mode. Handlers
 * should react to this return by not trying to write more, but if they try this object will just skip those writtings.
 *
 * Explicit calling to this function is not necessary, as as soon as the user calls any write function this will
 * be performed.
 *
 * As soon as the headers are written, any modification on them will be just ignored.
 *
 * @returns 0 if should procced to normal data write, or OR_SKIP_CONTENT if should not write content.
 */
int onion_response_write_headers(onion_response * res) {
  if (!res->request) {
    ONION_ERROR
        ("Bad formed response. Need a request at creation. Will not write headers.");
    return -1;
  }

  res->flags |= OR_HEADER_SENT; // I Set at the begining so I can do normal writing.
  res->request->flags |= OR_HEADER_SENT;
  char chunked = 0;

  if (res->request->flags & OR_HTTP11) {
    onion_response_printf(res, "HTTP/1.1 %d %s\r\n", res->code,
                          onion_response_code_description(res->code));
    //ONION_DEBUG("Response header: HTTP/1.1 %d %s\n",res->code, onion_response_code_description(res->code));
    if (!(res->flags & OR_LENGTH_SET) && onion_request_keep_alive(res->request)) {
      onion_response_write(res, CONNECTION_CHUNK_ENCODING,
                           sizeof(CONNECTION_CHUNK_ENCODING) - 1);
      chunked = 1;
    }
  } else {
    onion_response_printf(res, "HTTP/1.0 %d %s\r\n", res->code,
                          onion_response_code_description(res->code));
    //ONION_DEBUG("Response header: HTTP/1.0 %d %s\n",res->code, onion_response_code_description(res->code));
    if (res->flags & OR_LENGTH_SET)     // On HTTP/1.0, i need to state it. On 1.1 it is default.
      onion_response_write(res, CONNECTION_KEEP_ALIVE,
                           sizeof(CONNECTION_KEEP_ALIVE) - 1);
  }

  if (!(res->flags & OR_LENGTH_SET) && !chunked
      && !(res->flags & OR_CONNECTION_UPGRADE))
    onion_response_write(res, CONNECTION_CLOSE, sizeof(CONNECTION_CLOSE) - 1);

  if (res->flags & OR_CONNECTION_UPGRADE)
    onion_response_write(res, CONNECTION_UPGRADE,
                         sizeof(CONNECTION_UPGRADE) - 1);

  onion_dict_preorder(res->headers, write_header, res);

  if (res->request->session_id && (onion_dict_count(res->request->session) > 0))        // I have session with something, tell user
    onion_response_printf(res, "Set-Cookie: sessionid=%s; httponly; Path=/\n",
                          res->request->session_id);

  onion_response_write(res, "\r\n", 2);

  ONION_DEBUG0("Headers written");
  res->sent_bytes = -res->buffer_pos;   // the header size is not counted here. It will add again so start negative.

  if ((res->request->flags & OR_METHODS) == OR_HEAD) {
    onion_response_flush(res);
    res->flags |= OR_SKIP_CONTENT;
    return OR_SKIP_CONTENT;
  }
  if (chunked) {
    onion_response_flush(res);
    res->flags |= OR_CHUNKED;
  }

  return 0;
}
开发者ID:davidmoreno,项目名称:onion,代码行数:75,代码来源:response.c


示例18: parse_headers_KEY

static onion_connection_status parse_headers_KEY(onion_request *req, onion_buffer *data){
	onion_token *token=req->parser_data;

	int res=token_read_KEY(token, data);

	if (res<=1000)
		return res;

  ONION_DEBUG0("Got %d at KEY",res);

	if ( res == NEW_LINE ){
		if ((req->flags&OR_METHODS)==OR_POST){
			const char *content_type=onion_request_get_header(req, "Content-Type");
			if (content_type && (strstr(content_type,"application/x-www-form-urlencoded") || strstr(content_type, "boundary")))
				return prepare_POST(req);
		}
		if ((req->flags&OR_METHODS)==OR_PUT)
			return prepare_PUT(req);
		if (onion_request_get_header(req, "Content-Length")){ // Some length, not POST, get data.
			int n=atoi(onion_request_get_header(req, "Content-Length"));
			if (n>0)
				return prepare_CONTENT_LENGTH(req);
		}

		return OCS_REQUEST_READY;
	}
	assert(token->extra==NULL);
	token->extra=onion_low_strdup(token->str);

	req->parser=parse_headers_VALUE;
	return parse_headers_VALUE(req, data);
}
开发者ID:CarlosDomingues,项目名称:onion,代码行数:32,代码来源:request_parser.c


示例19: ONION_DEBUG0

/**
 * @short Creates the onion structure to fill with the server data, and later do the onion_listen()
 * @memberof onion_t
 * 
 * Creates an onion structure that can be used to set the server, port, SSL and similar parameters. It works over 
 * the onion structure, which is the main structure to control the listening of new connections throught TCP/IP.
 * 
 * A normal usage would be like this:
 * 
 * @code
 * 
 * onion *o=onion_new(O_THREADED);
 * onion_set_root_handler(o, onion_handler_directory("."));
 * onion_listen(o);
 * 
 * @endcode
 * 
 * @param flags Or'ed flags to use at the listening daemon. Normally one of O_ONE, O_ONE_LOOP or O_THREADED.
 * 
 * @returns The onion structure.
 * 
 * @see onion_mode_e onion_t
 */
onion *onion_new(int flags){
	ONION_DEBUG0("Some internal sizes: onion size: %d, request size %d, response size %d",sizeof(onion),sizeof(onion_request),sizeof(onion_response));
	if(SOCK_CLOEXEC == 0){
		ONION_WARNING("There is no support for SOCK_CLOEXEC compiled in libonion. This may be a SECURITY PROBLEM as connections may leak into executed programs.");
	}
	
	onion *o=calloc(1,sizeof(onion));
	o->flags=(flags&0x0FF)|O_SSL_AVAILABLE;
	o->timeout=5000; // 5 seconds of timeout, default.
	o->poller=onion_poller_new(15);
	if (!o->poller){
		free(o);
		return NULL;
	}
	o->sessions=onion_sessions_new();
	o->internal_error_handler=onion_handler_new((onion_handler_handler)onion_default_error, NULL, NULL);
	o->max_post_size=1024*1024; // 1MB
	o->max_file_size=1024*1024*1024; // 1GB
#ifdef HAVE_PTHREADS
	o->flags|=O_THREADS_AVALIABLE;
	o->nthreads=8;
	if (o->flags&O_THREADED)
		o->flags|=O_THREADS_ENABLED;
#endif
	return o;
}
开发者ID:KokaKiwi,项目名称:onion,代码行数:49,代码来源:onion.c


示例20: ONION_DEBUG0

/**
 * @short Creates the onion structure to fill with the server data, and later do the onion_listen()
 * @memberof onion_t
 * 
 * Creates an onion structure that can be used to set the server, port, SSL and similar parameters. It works over 
 * the onion structure, which is the main structure to control the listening of new connections throught TCP/IP.
 * 
 * A normal usage would be like this:
 * 
 * @code
 * 
 * onion *o=onion_new(O_THREADED);
 * onion_set_root_handler(o, onion_handler_directory("."));
 * onion_listen(o);
 * 
 * @endcode
 * 
 * @param flags Or'ed flags to use at the listening daemon. Normally one of O_ONE, O_ONE_LOOP or O_THREADED.
 * 
 * @returns The onion structure.
 * 
 * @see onion_mode_e onion_t
 */
onion *onion_new(int flags){
	ONION_DEBUG0("Some internal sizes: onion size: %d, request size %d, response size %d",sizeof(onion),sizeof(onion_request),sizeof(onion_response));
	if(SOCK_CLOEXEC == 0){
		ONION_WARNING("There is no support for SOCK_CLOEXEC compiled in libonion. This may be a SECURITY PROBLEM as connections may leak into executed programs.");
	}
	
	onion *o=malloc(sizeof(onion));
	o->flags=flags&0x0FF;
	o->listenfd=0;
	o->server=onion_server_new();
	o->timeout=5000; // 5 seconds of timeout, default.
	o->port=strdup("8080");
	o->hostname=strdup("::");
	o->username=NULL;
#ifdef HAVE_GNUTLS
	o->flags|=O_SSL_AVAILABLE;
#endif
#ifdef HAVE_PTHREADS
	o->flags|=O_THREADS_AVALIABLE;
	o->max_threads=15;
	if (o->flags&O_THREADED){
		o->flags|=O_THREADS_ENABLED;
		sem_init(&o->thread_count, 0, o->max_threads);
		pthread_mutex_init(&o->mutex, NULL);
	}
#endif
	o->poller=NULL;
	
	return o;
}
开发者ID:arunsirrpi,项目名称:onion,代码行数:53,代码来源:onion.c



注:本文中的ONION_DEBUG0函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ONLP_OID_ID_GET函数代码示例发布时间:2022-05-30
下一篇:
C++ ONION_DEBUG函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap