Skip to content

Commit

Permalink
Added some comments to the Makefile and post example.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoreno committed Oct 5, 2011
1 parent 208d311 commit c05f31b
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions examples/post/post.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
/*
Onion HTTP server library
Copyright (C) 2011 David Moreno Montero
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <onion/onion.h>
#include <onion/shortcuts.h>

/**
* @short This handler just answers the content of the POST parameter "text"
*
* It checks if its a HEAD in which case it writes the headers, and if not just printfs the
* user data.
*/
onion_connection_status post_data(void *_, onion_request *req, onion_response *res){
onion_response_write_headers(res);
if (onion_request_get_flags(req)&OR_HEAD)
if (onion_request_get_flags(req)&OR_HEAD){
onion_response_write_headers(res);
return OCS_PROCESSED;
}
const char *user_data=onion_request_get_post(req,"text");
onion_response_printf(res, "The user wrote: %s", user_data);
return OCS_PROCESSED;
}

/**
* This example creates a onion server and adds two urls: the base one is a static content with a form, and the
* "data" URL is the post_data handler.
*/
int main(int argc, char **argv){
onion *o=onion_new(O_ONE_LOOP);
onion_url *urls=onion_root_url(o);
Expand Down

0 comments on commit c05f31b

Please sign in to comment.