本文整理汇总了C++中ONION_DEBUG0函数的典型用法代码示例。如果您正苦于以下问题:C++ ONION_DEBUG0函数的具体用法?C++ ONION_DEBUG0怎么用?C++ ONION_DEBUG0使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ONION_DEBUG0函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}