[asterisk-commits] anthonyl: branch anthonyl/http-redux r50532 - /team/anthonyl/http-redux/main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Jan 11 14:46:17 MST 2007


Author: anthonyl
Date: Thu Jan 11 15:46:17 2007
New Revision: 50532

URL: http://svn.digium.com/view/asterisk?view=rev&rev=50532
Log:
just commiting some code for backup reasons, really nothing happens with the new additions yet

Modified:
    team/anthonyl/http-redux/main/http.c

Modified: team/anthonyl/http-redux/main/http.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/http-redux/main/http.c?view=diff&rev=50532&r1=50531&r2=50532
==============================================================================
--- team/anthonyl/http-redux/main/http.c (original)
+++ team/anthonyl/http-redux/main/http.c Thu Jan 11 15:46:17 2007
@@ -200,6 +200,19 @@
 	{ "mp3", "audio/mpeg" },
 };
 
+/* let's handle some methods! */
+enum mehtods {
+	METHOD_GET = 1,
+	METHOD_POST = 2,
+};
+struct http_method {
+	char *method_string;
+	int  method;
+	int (*method_handler)(void);	/* at the moment i'm not sure if i want to use this */
+} http_methods[] = {
+	{"GET", METHOD_GET, NULL },
+	{"POST", METHOD_POST, NULL },
+};
 static char *ftype2mtype(const char *ftype, char *wkspace, int wkspacelen)
 {
 	int x;
@@ -409,15 +422,35 @@
 		prev = prev->next;
 	}
 }
-
-static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **title, int *contentlength, struct ast_variable **cookies)
+/*
+ 	these two functions will load params for the various http methods into a ast_variable list
+	then the infomration can be handled and processed however. all of the callbacks take the
+	list of vars as input to processes.
+*/
+struct ast_variable *process_get(char *uri)
+{
+	struct ast_variable *v;
+	
+	return v;
+}
+
+struct ast_variable *process_post(char *uri)
+{
+	struct ast_variable *v;
+	
+	return v;
+}
+
+static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **title, int *contentlength, struct ast_variable **cookies, int method)
 {
 	char *c;
 	char *params = uri;
 	struct ast_http_uri *urih=NULL;
 	int l;
 	struct ast_variable *vars=NULL, *v, *prev = NULL;
-
+	
+	ast_log(LOG_WARNING, "uri: %s\n", uri);
+	
 	strsep(&params, "?");
 	/* Extract arguments from the request and store them in variables. */
 	if (params) {
@@ -587,7 +620,7 @@
 	struct ast_variable *var, *prev=NULL, *vars=NULL;
 	char *uri, *c, *title=NULL;
 	int status = 200, contentlength = 0;
-
+	int i=0, method=0;
 	if (!fgets(buf, sizeof(buf), ser->f))
 		goto done;
 
@@ -659,11 +692,19 @@
 
 	if (!*uri)
 		c = ast_http_error(400, "Bad Request", NULL, "Invalid Request");
-	else if (strcasecmp(buf, "get")) 
+	
+	for (i=0;i<(sizeof(http_methods)/sizeof(struct http_method));i++) {
+		if (!strcasecmp(buf,http_methods[i].method_string)) {
+			ast_log(LOG_WARNING, "detected http method %s\n", http_methods[i].method_string);
+			method = http_methods[i].method;
+		}
+	}
+	
+	if (method == 0) 
 		c = ast_http_error(501, "Not Implemented", NULL,
 			"Attempt to use unimplemented / unsupported method");
 	else	/* try to serve it */
-		c = handle_uri(&ser->requestor, uri, &status, &title, &contentlength, &vars);
+		c = handle_uri(&ser->requestor, uri, &status, &title, &contentlength, &vars, method);
 
 	/* If they aren't mopped up already, clean up the cookies */
 	if (vars)



More information about the asterisk-commits mailing list