Permalink
Browse files

Added some comments to the Makefile and post example.

  • Loading branch information...
1 parent 208d311 commit c05f31bfd6e643921fb7ac7213982bd01dc00274 @davidmoreno committed Oct 5, 2011
Showing with 31 additions and 2 deletions.
  1. +31 −2 examples/post/post.c
View
@@ -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);

0 comments on commit c05f31b

Please sign in to comment.