本文整理汇总了C++中ONION_DEBUG函数的典型用法代码示例。如果您正苦于以下问题:C++ ONION_DEBUG函数的具体用法?C++ ONION_DEBUG怎么用?C++ ONION_DEBUG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ONION_DEBUG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onion_poller_stop
/**
* @short Marks the poller to stop ASAP
* @memberof onion_poller_t
* @ingroup poller
*/
void onion_poller_stop(onion_poller *p){
ONION_DEBUG("Stopping poller");
#ifdef HAVE_PTHREADS
pthread_mutex_lock(&p->mutex);
p->stop=1;
pthread_mutex_unlock(&p->mutex);
#else
p->stop=1;
#endif
char data[8]={0,0,0,0, 0,0,0,1};
int __attribute__((unused)) r=read(p->eventfd, data, 8); // Flush eventfd data, discard data
#ifdef HAVE_PTHREADS
pthread_mutex_lock(&p->mutex);
int n=p->npollers;
pthread_mutex_unlock(&p->mutex);
if (n>0){
int w=write(p->eventfd,data,8); // Tell another thread to exit
if (w<0){
ONION_ERROR("Error signaling poller to stop!");
}
}
else
ONION_DEBUG("Poller stopped");
#endif
}
示例2: 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);
}
示例3: oterm_out
/// Gets the output data
int oterm_out(process *o, onion_request *req, onion_response *res){
pthread_mutex_lock(&o->mutex);
if (onion_request_get_query(req, "initial")){
if (o->buffer[BUFFER_SIZE-1]!=0){ // If 0 then never wrote on it. So if not, write from pos to end too, first.
onion_response_write(res, &o->buffer[o->buffer_pos], BUFFER_SIZE-o->buffer_pos);
}
onion_response_write(res, o->buffer, o->buffer_pos);
onion_response_printf(res, "\033]oterm;%d;", o->buffer_pos);
onion_response_printf(res, "\033]url;https://localhost:8080/uuid/%s/;", o->uuid);
pthread_mutex_unlock(&o->mutex);
return OCS_PROCESSED;
}
int16_t p=atoi(onion_request_get_queryd(req, "pos", "0")); //o->buffer_pos;
ONION_DEBUG("Wait for data at %d", p);
while(p==o->buffer_pos) // We need it to be diferent, if not does not make sense to wake up
pthread_cond_wait(&o->dataReady, &o->mutex);
ONION_DEBUG("Data ready at %d (waiting from %d)", o->buffer_pos, p);
if (o->buffer_pos<p){
onion_response_write(res, &o->buffer[p], BUFFER_SIZE-p);
p=0;
}
onion_response_write(res, &o->buffer[p], o->buffer_pos-p);
onion_response_printf(res, "\033]oterm;%d;", o->buffer_pos);
pthread_mutex_unlock(&o->mutex);
return OCS_PROCESSED;
}
示例4: onion_free
/**
* @short Removes the allocated data
* @memberof onion_t
*/
void onion_free(onion *onion){
ONION_DEBUG("Onion free");
onion_listen_stop(onion);
if (onion->poller)
onion_poller_free(onion->poller);
if (onion->username)
free(onion->username);
if (onion->listen_points){
onion_listen_point **p=onion->listen_points;
while(*p!=NULL){
ONION_DEBUG("Free %p listen_point", *p);
onion_listen_point_free(*p++);
}
free(onion->listen_points);
}
if (onion->root_handler)
onion_handler_free(onion->root_handler);
if (onion->internal_error_handler)
onion_handler_free(onion->internal_error_handler);
onion_mime_set(NULL);
if (onion->sessions)
onion_sessions_free(onion->sessions);
#ifdef HAVE_PTHREADS
if (onion->threads)
free(onion->threads);
#endif
free(onion);
}
示例5: oterm_uuid
onion_connection_status oterm_uuid(void *data, onion_request *req, onion_response *res){
const char *path=onion_request_get_path(req);
ONION_DEBUG("Ask path %s (%p)", path, data);
// split id / function
int l=strlen(path)+1;
char *id=alloca(l);
char *function=NULL;
int i;
memcpy(id,path,l);
int func_pos=0;
for (i=0;i<l;i++){
if (id[i]=='/'){
if (!function && id[i+1]!='\0')
function=id+i+1;
id[i]=0;
func_pos=i;
break;
}
}
ONION_DEBUG("Id %s, function %s", id, function);
process *term=oterm_get_process_by_uuid(data, id);
if (!term)
return OCS_INTERNAL_ERROR;
if (!function)
return onion_shortcut_internal_redirect("static/oterm.html", req, res);
// do it
onion_request_advance_path(req, func_pos);
return oterm_process(data, term, function, req, res);
}
示例6: index_html_template
onion_connection_status index_html_template(onion_dict *context){
char *lang = (char*)malloc (3*sizeof(char));
strcpy(lang,"en\0");
ONION_DEBUG("Add to dict");
if (context) onion_dict_add(context, "LANG", lang, OD_FREE_VALUE);
ONION_DEBUG("Free dict");
if (context) onion_dict_free(context); // if you remove this line, it works correctly
return OCS_PROCESSED;
}
示例7: onion_version_is_compatible3
/**
* @short Checks a specific set of major.minor.patch and returns if the current using onion is ABI compatible.
*
* Onion uses SEMVER (http://semver.org/), and with this simple function its
* possible to check if your compiled code is compatible with the onion
* version.
*
* It also allows to in the rare case that there is some really bad version of
* onion to warn the users.
*
* Normally users need just to add a onion_version_is_compatible() check, and
* if not compatible abort:
*
* if (!onion_version_is_compatible()) abort();
*
*/
bool onion_version_is_compatible3(int major, int minor, int patch){
if (major != ONION_VERSION_MAJOR){
ONION_DEBUG("Onion major version (%d) is not compatible with program's (%d). Should match.", ONION_VERSION_MAJOR, major);
return false;
}
if (minor > ONION_VERSION_MINOR){
ONION_DEBUG("Onion minor version (%d) is not compatible with program's (%d). Program's has to be equal or greater.", ONION_VERSION_MINOR, minor);
return false;
}
return true;
}
示例8: onion_https_close
/**
* @short Closes the https connection
* @memberof onion_https_t
*
* It frees local data and closes the socket.
*
* @param req to close.
*/
static void onion_https_close(onion_request *req){
ONION_DEBUG("Close HTTPS connection");
gnutls_session_t session=(gnutls_session_t)req->connection.user_data;
if (session){
ONION_DEBUG("Free session %p", session);
gnutls_bye (session, GNUTLS_SHUT_WR);
gnutls_deinit(session);
}
onion_listen_point_request_close_socket(req);
}
示例9: onion_free
/**
* @short Removes the allocated data
* @memberof onion_t
*/
void onion_free(onion *onion){
ONION_DEBUG("Onion free");
if (onion->flags&O_LISTENING)
onion_listen_stop(onion);
if (onion->poller)
onion_poller_free(onion->poller);
if (onion->username)
onion_low_free(onion->username);
if (onion->listen_points){
onion_listen_point **p=onion->listen_points;
while(*p!=NULL){
ONION_DEBUG("Free %p listen_point", *p);
onion_listen_point_free(*p++);
}
onion_low_free(onion->listen_points);
}
if (onion->root_handler)
onion_handler_free(onion->root_handler);
if (onion->internal_error_handler)
onion_handler_free(onion->internal_error_handler);
onion_mime_set(NULL);
if (onion->sessions)
onion_sessions_free(onion->sessions);
{
#ifdef HAVE_PTHREADS
pthread_mutex_lock (&onion->mutex);
#endif
void* data = onion->client_data;
onion->client_data = NULL;
if (data && onion->client_data_free)
onion->client_data_free (data);
onion->client_data_free = NULL;
#ifdef HAVE_PTHREADS
pthread_mutex_unlock (&onion->mutex);
pthread_mutex_destroy (&onion->mutex);
#endif
};
#ifdef HAVE_PTHREADS
if (onion->threads)
onion_low_free(onion->threads);
#endif
if (!(onion->flags&O_NO_SIGTERM)){
signal(SIGINT,SIG_DFL);
signal(SIGTERM,SIG_DFL);
}
last_onion=NULL;
onion_low_free(onion);
}
示例10: onion_listen_point_request_init_from_socket
/**
* @short Default implementation that initializes the request from a socket
* @memberof onion_listen_point_t
*
* Accepts the connection and initializes it.
*
* @param req Request to initialize
* @returns <0 if error opening the connection
*/
int onion_listen_point_request_init_from_socket(onion_request *req){
onion_listen_point *op=req->connection.listen_point;
int listenfd=op->listenfd;
if (listenfd<0){
ONION_DEBUG("Listen point closed, no request allowed");
return -1;
}
/// Follows default socket implementation. If your protocol is socket based, just use it.
req->connection.cli_len = sizeof(req->connection.cli_addr);
int set_cloexec=SOCK_CLOEXEC == 0;
int clientfd=accept4(listenfd, (struct sockaddr *) &req->connection.cli_addr,
&req->connection.cli_len, SOCK_CLOEXEC);
if (clientfd<0){
ONION_DEBUG("Second try? errno %d, clientfd %d", errno, clientfd);
if (errno==ENOSYS){
clientfd=accept(listenfd, (struct sockaddr *) &req->connection.cli_addr,
&req->connection.cli_len);
}
ONION_DEBUG("How was it? errno %d, clientfd %d", errno, clientfd);
if (clientfd<0){
ONION_ERROR("Error accepting connection: %s",strerror(errno),errno);
onion_listen_point_request_close_socket(req);
return -1;
}
}
req->connection.fd=clientfd;
/// Thanks to Andrew Victor for pointing that without this client may block HTTPS connection. It could lead to DoS if occupies all connections.
{
struct timeval t;
t.tv_sec = op->server->timeout / 1000;
t.tv_usec = ( op->server->timeout % 1000 ) * 1000;
setsockopt(clientfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(struct timeval));
}
if(set_cloexec) { // Good compiler know how to cut this out
int flags=fcntl(clientfd, F_GETFD);
if (flags==-1){
ONION_ERROR("Retrieving flags from connection");
}
flags|=FD_CLOEXEC;
if (fcntl(clientfd, F_SETFD, flags)==-1){
ONION_ERROR("Setting FD_CLOEXEC to connection");
}
}
ONION_DEBUG0("New connection, socket %d",clientfd);
return 0;
}
示例11: while
void *t08_thread_write(onion_dict *d){
int n=0;
while (n!=N_READERS){
int i;
n=0;
//ONION_DEBUG("Lock read");
onion_dict_lock_read(d);
//ONION_DEBUG("Got read lock");
for (i=0;i<N_READERS;i++){
char tmp[16];
snprintf(tmp,16,"%d",i+1);
const char *r=onion_dict_get(d,tmp);
if (r)
n++;
}
//ONION_DEBUG("Unlock");
onion_dict_unlock(d);
//ONION_DEBUG("Lock write");
onion_dict_lock_write(d);
//ONION_DEBUG("Got write lock");
onion_dict_add(d, "test", "test", OD_DUP_ALL|OD_REPLACE);
//ONION_DEBUG("Unlock");
onion_dict_unlock(d);
ONION_DEBUG("Found %d answers, should be %d.", n, N_READERS);
usleep(200);
}
onion_dict_free(d);
return (char*)1;
}
示例12: POST_a_lot
void POST_a_lot(void) {
sleep(1);
onion_block *tosend = onion_block_new();
onion_block_add_str(tosend,
"POST /configuration HTTP/1.1\nHost: example.com\nContent-Type: x-application/garbage\nContent-Length: 1000000\n\n");
{
int i;
onion_block *bl = onion_block_new();
for (i = 0; i < 1000; i++) {
onion_block_add_char(bl, rand() & 255);
}
for (i = 0; i < 1000; i++) {
onion_block_add_block(tosend, bl);
}
onion_block_free(bl);
}
onion_block *bl = connect_and_send("127.0.0.1", "8080", tosend, 1024 * 64);
onion_block_free(tosend);
ONION_DEBUG("%p", strstr(onion_block_data(bl), "\n1000000\n"));
FAIL_IF_NOT(strstr(onion_block_data(bl), "\n1000000\n") != NULL);
onion_block_free(bl);
}
示例13: t05_post_content_json
void t05_post_content_json(){
INIT_LOCAL();
onion *server=onion_new(0);
onion_listen_point *lp=onion_buffer_listen_point_new();
json_response post_json = { 0 };
onion_add_listen_point(server,NULL,NULL,lp);
onion_set_root_handler(server, onion_handler_new((void*)&post_json_check,&post_json,NULL));
onion_request *req=onion_request_new(lp);
#define POST_HEADER "POST / HTTP/1.1\nContent-Type: application/json\nContent-Length: %d\n\n"
char tmp[1024];
int json_length=sizeof(JSON_EXAMPLE);
ONION_DEBUG("Post size is about %d",json_length);
snprintf(tmp, sizeof(tmp), POST_HEADER, json_length);
// ONION_DEBUG("%s",tmp);
onion_request_write(req,tmp,strlen(tmp));
onion_request_write(req,JSON_EXAMPLE,json_length);
// ONION_DEBUG("%s",JSON_EXAMPLE);
FAIL_IF_NOT_EQUAL_INT(post_json.processed, 2);
onion_request_free(req);
onion_free(server);
END_LOCAL();
}
示例14: onion_add_listen_point
/**
* @short Sets the port to listen to.
* @memberof onion_t
*
* Default listen point is HTTP at localhost:8080.
*
* @param server The onion server to act on.
* @param port The number of port to listen to, or service name, as string always.
*/
int onion_add_listen_point(onion* server, const char* hostname, const char* port, onion_listen_point* protocol){
if (protocol==NULL){
ONION_ERROR("Trying to add an invalid entry point. Ignoring.");
return -1;
}
protocol->server=server;
if (hostname)
protocol->hostname=strdup(hostname);
if (port)
protocol->port=strdup(port);
if (server->listen_points){
onion_listen_point **p=server->listen_points;
int protcount=0;
while (*p++) protcount++;
server->listen_points=realloc(server->listen_points, (protcount+2)*sizeof(onion_listen_point));
server->listen_points[protcount]=protocol;
server->listen_points[protcount+1]=NULL;
}
else{
server->listen_points=malloc(sizeof(onion_listen_point*)*2);
server->listen_points[0]=protocol;
server->listen_points[1]=NULL;
}
ONION_DEBUG("add %p listen_point (%p, %p, %p)", protocol, server->listen_points, *server->listen_points, *(server->listen_points+1));
return 0;
}
示例15: ONION_ERROR
/**
* @short Returns a poller object that helps polling on sockets and files
* @memberof onion_poller_t
*
* This poller is implemented through epoll, but other implementations are possible
*
*/
onion_poller *onion_poller_new(int n){
onion_poller *p=onion_low_malloc(sizeof(onion_poller));
p->fd=epoll_create1(EPOLL_CLOEXEC);
if (p->fd < 0){
ONION_ERROR("Error creating the poller. %s", strerror(errno));
onion_low_free(p);
return NULL;
}
p->eventfd=eventfd(0,EFD_CLOEXEC | EFD_NONBLOCK);
#if EFD_CLOEXEC == 0
fcntl(p->eventfd,F_SETFD,FD_CLOEXEC);
#endif
p->head=NULL;
p->n=0;
p->stop=0;
#ifdef HAVE_PTHREADS
ONION_DEBUG("Init thread stuff for poll. Eventfd at %d", p->eventfd);
p->npollers=0;
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&p->mutex, &attr);
pthread_mutexattr_destroy(&attr);
#endif
onion_poller_slot *ev=onion_poller_slot_new(p->eventfd,onion_poller_stop_helper,p);
onion_poller_add(p,ev);
return p;
}