/** * @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); }
/** * @short Cleans all data used by this server * @memberof onion_server_t */ void onion_server_free(onion_server *server){ if (server->root_handler) onion_handler_free(server->root_handler); if (server->internal_error_handler) onion_handler_free(server->internal_error_handler); onion_mime_set(NULL); onion_sessions_free(server->sessions); free(server); }
/** * @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); }
/// Removes internal data for this handler. void onion_url_free_data(onion_url_data **d){ onion_url_data *next=*d; while (next){ onion_url_data *t=next; onion_handler_free(t->inside); if (t->flags&OUD_REGEXP) regfree(&t->regexp); else free(t->str); next=t->next; #ifdef __DEBUG__ free(t->orig); #endif free(t); } free(d); }
/** * @short Sets the error handler that will be called to return data to users on errors. * @memberof onion_server_t * * On the called handler, the request objet will have at flags the reason of * the error: OR_NOT_FOUND, OR_NOT_IMPLEMENTED or OR_INTERNAL_ERROR */ void onion_server_set_internal_error_handler(onion_server *server, onion_handler *handler){ if (server->internal_error_handler) onion_handler_free(server->internal_error_handler); server->internal_error_handler=handler; }
void onion_handler_auth_pam_delete(onion_handler_auth_pam_data *d){ free(d->pamname); free(d->realm); onion_handler_free(d->inside); free(d); }
/** * @short Frees the url. * @memberof onion_url_t */ void onion_url_free(onion_url* url){ onion_handler_free((onion_handler*)url); }
void t01_call_otemplate(){ INIT_LOCAL(); onion *s=onion_new(0); onion_set_root_handler(s, onion_handler_new((void*)_13_otemplate_html_handler_page, NULL, NULL)); onion_listen_point *lp=onion_buffer_listen_point_new(); onion_add_listen_point(s,NULL,NULL,lp); struct tests_call_otemplate tests; onion_request *req=onion_request_new(lp); FAIL_IF_NOT_EQUAL_INT(onion_request_write0(req, "GET /\n\n"), OCS_REQUEST_READY); FAIL_IF_NOT_EQUAL_INT(onion_request_process(req), OCS_CLOSE_CONNECTION); ONION_INFO("Got %s",onion_buffer_listen_point_get_buffer_data(req)); check_tests(onion_buffer_listen_point_get_buffer(req), &tests); FAIL_IF_NOT_EQUAL_INT(tests.ok_hello,1); FAIL_IF_NOT_EQUAL_INT(tests.ok_list,0); FAIL_IF_NOT_EQUAL_INT(tests.ok_title,0); FAIL_IF_NOT_EQUAL_INT(tests.ok_title_title,0); FAIL_IF_NOT_EQUAL_INT(tests.ok_encoding,0); onion_dict *d=onion_dict_new(); onion_dict_add(d, "title", "TITLE",0); onion_dict_add(d, "hello", "SHOULD NOT APPEAR",0); onion_dict_add(d, "quoted", "<\"Hello>",0); onion_request_clean(req); onion_handler_free(onion_get_root_handler(s)); onion_set_root_handler(s, onion_handler_new((void*)_13_otemplate_html_handler_page, d, NULL)); FAIL_IF_NOT_EQUAL_INT(onion_request_write0(req, "GET /\n\n"), OCS_REQUEST_READY); FAIL_IF_NOT_EQUAL_INT(onion_request_process(req), OCS_CLOSE_CONNECTION); ONION_INFO("Got %s",onion_buffer_listen_point_get_buffer_data(req)); check_tests(onion_buffer_listen_point_get_buffer(req), &tests); FAIL_IF_NOT_EQUAL_INT(tests.ok_hello,1); FAIL_IF_NOT_EQUAL_INT(tests.ok_list,0); FAIL_IF_NOT_EQUAL_INT(tests.ok_title,1); FAIL_IF_NOT_EQUAL_INT(tests.ok_title_title,1); FAIL_IF_NOT_EQUAL_INT(tests.ok_encoding,1); onion_dict *d2=onion_dict_new(); onion_dict_add(d2,"0","LIST 1",0); onion_dict_add(d2,"1","LIST 2",0); onion_dict_add(d2,"2","LIST 3",0); onion_dict_add(d,"list",d2, OD_DICT|OD_FREE_VALUE); onion_dict *f1=onion_dict_new(); onion_dict *f2=onion_dict_new(); onion_dict_add(f2, "0", "internal",0); onion_dict_add(f2, "1", "loop",0); onion_dict_add(f1, "loop", f2, OD_DICT|OD_FREE_VALUE); onion_dict_add(d, "loop", f1, OD_DICT|OD_FREE_VALUE); onion_request_clean(req); onion_handler_free(onion_get_root_handler(s)); onion_set_root_handler(s, onion_handler_new((void*)_13_otemplate_html_handler_page, d, (void*)onion_dict_free)); FAIL_IF_NOT_EQUAL_INT(onion_request_write0(req, "GET /\n\n"), OCS_REQUEST_READY); FAIL_IF_NOT_EQUAL_INT(onion_request_process(req), OCS_CLOSE_CONNECTION); check_tests(onion_buffer_listen_point_get_buffer(req), &tests); ONION_INFO("Got %s",onion_buffer_listen_point_get_buffer_data(req)); FAIL_IF_NOT_EQUAL_INT(tests.ok_hello,1); FAIL_IF_NOT_EQUAL_INT(tests.ok_list,1); FAIL_IF_NOT_EQUAL_INT(tests.ok_title,1); FAIL_IF_NOT_EQUAL_INT(tests.ok_title_title,1); FAIL_IF_NOT_EQUAL_INT(tests.ok_internal_loop,1); onion_request_free(req); onion_free(s); END_LOCAL(); }
virtual ~HandlerCBridge(){ onion_handler_free(ptr); };