/*+++++++++++++ OnionServer-Class ++++++++++++++++++ */ int OnionServer::start_server() { onion_url *url=onion_root_url(m_ponion); const char *host, *port; if( m_psettingKinectGrid != NULL){ host = m_psettingKinectGrid->getString("host"); port = m_psettingKinectGrid->getString("port"); }else{ host = "0.0.0.0"; port = "8080"; } onion_set_hostname(m_ponion, host); // Force ipv4. onion_set_port(m_ponion, port); onion_url_add_with_data(url, "kinectgrid_settings.js", (void*)insert_json, m_psettingKinect, NULL); onion_url_add_with_data(url, "index.html", (void*)index_html, m_psettingKinectGrid, NULL); onion_url_add_with_data(url, "", (void*)index_html, m_psettingKinectGrid, NULL); //onion_url_add_with_data(url, "index.html", (void*)checkFormularValues, this, NULL); //onion_url_add_with_data(url, "", (void*)checkFormularValues, this, NULL); onion_url_add_with_data(url, "json", (void*)checkFormularValues, this, NULL); onion_url_add(url, "^.*$", (void*)search_file); /* Now, m_ponion get the O_DETACH_LISTEN flag on creation and the Extra thread is omitable. */ //start loop as thread //return pthread_create( &m_pthread, NULL, &start_myonion_server, m_ponion); onion_listen(m_ponion);//loop return 0; }
int main(void) { onion *o = onion_new(O_POOL); onion_url *root = onion_root_url(o); onion_url_add_handler(root, "^wd", onion_handler_webdav(".", NULL)); onion_listen(o); return 0; }
onion *websocket_server_new() { onion *o = onion_new(0); onion_url *urls = onion_root_url(o); onion_url_add(urls, "", ws_handler); onion_listen_point *lp = onion_buffer_listen_point_new(); onion_add_listen_point(o, NULL, NULL, lp); return o; }
int main(){ onion *o=onion_new(O_THREADED); onion_url *urls=onion_root_url(o); onion_url_add(urls, "", websocket_example); onion_listen(o); onion_free(o); return 0; }
// This fixes that whenever a session is created, but no new data is added, it does not set the proper cookie void t04_lot_of_sessionid(){ INIT_LOCAL(); onion *o=onion_new(O_ONE_LOOP); onion_server_set_write(o->server, empty_write); onion_url *url=onion_root_url(o); onion_url_add(url, "^.*", ask_session); char sessionid[256]; char tmp[1024]; char tmp2[4096]; onion_request *req; int i; set_data_on_session=1; req=onion_request_new(o->server, NULL, NULL); req->fullpath="/"; onion_request_process(req); FAIL_IF_NOT_EQUAL_INT(onion_dict_count(o->server->sessions->sessions), 1); FAIL_IF_EQUAL_STR(lastsessionid,""); strcpy(sessionid, lastsessionid); req->fullpath=NULL; onion_request_free(req); req=onion_request_new(o->server, NULL, NULL); req->fullpath="/"; snprintf(tmp,sizeof(tmp)," sessionid=xx%sxx;",lastsessionid); strcpy(tmp2,"Cookie:"); for(i=0;i<64;i++) strncat(tmp2, tmp, sizeof(tmp2)); snprintf(tmp,sizeof(tmp)," sessionid=%s\n",lastsessionid); strncat(tmp2, tmp, sizeof(tmp2)); ONION_DEBUG("Set cookies (%d bytes): %s",strlen(tmp2),tmp2); strcpy(tmp,"GET /\n"); onion_request_write(req,tmp,strlen(tmp)); // Here is the problem, at parsing too long headers onion_request_write(req,tmp2,strlen(tmp2)); // Here is the problem, at parsing too long headers onion_request_write(req,"\n",1); //onion_dict_add(req->headers, "Cookie", tmp2, 0); onion_request_process(req); FAIL_IF_NOT_EQUAL_INT(onion_dict_count(o->server->sessions->sessions), 1); FAIL_IF_EQUAL_STR(lastsessionid,""); FAIL_IF_NOT_EQUAL_STR(lastsessionid, sessionid); FAIL_IF_NOT(has_set_cookie); onion_request_free(req); onion_free(o); END_LOCAL(); }
int trivia(void) { printf("creating web-server\n"); o=onion_new(O_ONE_LOOP); printf("obtaining root url\n"); onion_url *urls=onion_root_url(o); printf("adding css skeleton\n"); if(add_css_page(urls)) { printf("error: add_questions(): %s\n", strerror(errno)); exit(1); } printf("adding questions\n"); if(add_questions(urls)) { printf("error: add_questions(): %s\n", strerror(errno)); exit(1); } printf("adding landing page\n"); if(add_start_page(urls)) { printf("error: add_landing_page(): %s\n", strerror(errno)); exit(1); } printf("adding done page\n"); if(add_done_page(urls)) { printf("error: add_done_page(): %s\n", strerror(errno)); exit(1); } printf("adding reset page\n"); if(add_reset_page(urls)) { printf("error: add_landing_page(): %s\n", strerror(errno)); exit(1); } printf("adding signal handlers\n"); signal(SIGTERM, onexit); signal(SIGINT, onexit); printf("adding listening point\n"); onion_add_listen_point(o, NULL, "80", onion_http_new()); printf("listening\n"); onion_listen(o); printf("freeing\n"); onion_free(o); return 0; }
//Initialize favicon int initializeFavicon(char *argv[]) { //What does this do? signal(SIGINT,shutdown_server); signal(SIGTERM,shutdown_server); //Initialize address and port o=onion_new(O_POOL); onion_set_timeout(o, 5000); onion_set_hostname(o,"0.0.0.0"); onion_set_port(o, argv[3]); onion_url *urls=onion_root_url(o); //Add handlers onion_url_add(urls, "", forward); onion_url_add(urls, "^(.*)$", forward); }
int main(int argc, char **argv){ o=onion_new(O_ONE_LOOP); #ifdef HAVE_REDIS onion_sessions *session_backend=onion_sessions_redis_new("localhost",6379); onion_set_session_backend(o, session_backend); #endif onion_url *root=onion_root_url(o); onion_url_add_handler(root, "status",onion_internal_status()); onion_url_add_handler(root, "^.*", onion_handler_new((onion_handler_handler)sessions, NULL, NULL)); signal(SIGINT, free_onion); onion_listen(o); return 0; }
int main(int argc, char **argv) { signal(SIGINT, shutdown_server); signal(SIGTERM, shutdown_server); ONION_VERSION_IS_COMPATIBLE_OR_ABORT(); o = onion_new(O_POOL); onion_set_timeout(o, 5000); onion_set_hostname(o, "0.0.0.0"); onion_url *urls = onion_root_url(o); onion_url_add_static(urls, "static", "Hello static world", HTTP_OK); onion_url_add(urls, "timeout", random_timeout); onion_url_add(urls, "", hello); onion_url_add(urls, "^(.*)$", hello); onion_listen(o); onion_free(o); return 0; }
Url(Onion &o) { ptr=onion_root_url(o.c_handler()); }
Url(Onion *o) { ptr=onion_root_url(o->c_handler()); }
// This fixes that whenever a session is created, but no new data is added, it does not set the proper cookie, and should not create a new session. void t03_bug_empty_session_is_new_session(){ INIT_LOCAL(); onion *o=onion_new(O_ONE_LOOP); onion_server_set_write(o->server, empty_write); onion_url *url=onion_root_url(o); onion_url_add(url, "^.*", ask_session); char sessionid[256]; char tmp[256]; set_data_on_session=1; onion_request *req=onion_request_new(o->server, NULL, NULL); req->fullpath="/"; onion_request_process(req); FAIL_IF_EQUAL_STR(lastsessionid,""); strcpy(sessionid, lastsessionid); req->fullpath=NULL; onion_request_free(req); FAIL_IF_NOT_EQUAL_INT(onion_dict_count(o->server->sessions->sessions), 1); req=onion_request_new(o->server, NULL, NULL); req->fullpath="/"; onion_dict_add(req->headers, "Cookie", "sessionid=xxx", 0); onion_request_process(req); FAIL_IF_EQUAL_STR(lastsessionid,""); FAIL_IF_EQUAL_STR(lastsessionid, sessionid); FAIL_IF_NOT(has_set_cookie); req->fullpath=NULL; onion_request_free(req); FAIL_IF_NOT_EQUAL_INT(onion_dict_count(o->server->sessions->sessions), 2); req=onion_request_new(o->server, NULL, NULL); req->fullpath="/"; snprintf(tmp,sizeof(tmp),"sessionid=%s",lastsessionid); onion_dict_add(req->headers, "Cookie", tmp, 0); onion_request_process(req); FAIL_IF_EQUAL_STR(lastsessionid,""); FAIL_IF_EQUAL_STR(lastsessionid, sessionid); FAIL_IF_NOT(has_set_cookie); strcpy(sessionid, lastsessionid); req->fullpath=NULL; onion_request_free(req); FAIL_IF_NOT_EQUAL_INT(onion_dict_count(o->server->sessions->sessions), 2); req=onion_request_new(o->server, NULL, NULL); req->fullpath="/"; snprintf(tmp,sizeof(tmp),"sessionid=%sxx",lastsessionid); onion_dict_add(req->headers, "Cookie", tmp, 0); onion_request_process(req); FAIL_IF_EQUAL_STR(lastsessionid,""); FAIL_IF_EQUAL_STR(lastsessionid, sessionid); FAIL_IF_NOT(has_set_cookie); req->fullpath=NULL; onion_request_free(req); FAIL_IF_NOT_EQUAL_INT(onion_dict_count(o->server->sessions->sessions), 3); // Ask for new, without session data, but I will not set data on session, so session is not created. set_data_on_session=0; req=onion_request_new(o->server, NULL, NULL); req->fullpath="/"; onion_request_process(req); FAIL_IF_EQUAL_STR(lastsessionid,""); strcpy(sessionid, lastsessionid); req->fullpath=NULL; FAIL_IF_NOT_EQUAL_INT(onion_dict_count(o->server->sessions->sessions), 4); // For a moment it exists, until onion realizes is not necesary. onion_request_free(req); FAIL_IF_NOT_EQUAL_INT(onion_dict_count(o->server->sessions->sessions), 3); onion_free(o); END_LOCAL(); }