diff options
author | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-12-05 13:23:07 +0000 |
---|---|---|
committer | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-12-05 13:23:07 +0000 |
commit | 288490094a7fe9167747dc78d416940759a31197 (patch) | |
tree | 53dc4f5c2375f4b688b53ca8841630ddec5e1f88 /src/webserver | |
parent | 8ec1c47aed09c90343949d57c92760ba84738a46 (diff) | |
download | hercules-288490094a7fe9167747dc78d416940759a31197.tar.gz hercules-288490094a7fe9167747dc78d416940759a31197.tar.bz2 hercules-288490094a7fe9167747dc78d416940759a31197.tar.xz hercules-288490094a7fe9167747dc78d416940759a31197.zip |
- Massive EOL normalization & 'svn:eol-style native' flag setting for all txt/conf/h/c files.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9410 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/webserver')
-rw-r--r-- | src/webserver/doc/API.txt | 100 | ||||
-rw-r--r-- | src/webserver/generate.c | 76 | ||||
-rw-r--r-- | src/webserver/htmlstyle.c | 102 | ||||
-rw-r--r-- | src/webserver/logs.c | 16 | ||||
-rw-r--r-- | src/webserver/main.c | 284 | ||||
-rw-r--r-- | src/webserver/pages/about.c | 12 | ||||
-rw-r--r-- | src/webserver/pages/notdone.c | 10 | ||||
-rw-r--r-- | src/webserver/pages/sample.c | 48 | ||||
-rw-r--r-- | src/webserver/parse.c | 270 |
9 files changed, 459 insertions, 459 deletions
diff --git a/src/webserver/doc/API.txt b/src/webserver/doc/API.txt index 92f88c5e3..c80f7bd44 100644 --- a/src/webserver/doc/API.txt +++ b/src/webserver/doc/API.txt @@ -1,50 +1,50 @@ -Here's the webserver API, so you can work on the webserver.
-
-My personal goal is to make this interface simple, so that coding it
-will be like coding in some scripting language...
-
-
-
-char *get_param(char in_string[500], char swhat[500]);
-
-This function simply returns various data from the query string.
- *Pass get_param NOTHING longer than 500 in length!
-
- What do I pass where in_string is?
- The query string.
-
- What do I pass where swhat is?
- One of two things...
- Either 0 for the path of the 'page'
- or you can pass it the param you wish to lookup.
-
-
-
-
-
-
-char *get_query(char *inquery);
-
-This function simply returns a query string from the raw server request.
-This is used once in main, I doubt you'll need it.
-
-
-
-
-
-void web_send(int sockin, char *in_data);
-
-Super easy way of sending data to a webpage!
-Simply put in the socket name and then the data.
-
- Ex:
- web_send(socket, "I like cheese!\n");
-
-
-
-
-char *html_header(char* title);
-Easy way to print the eAthena header for the server.
-
- Ex:
- web_send(sockethere, html_header("About"));
+Here's the webserver API, so you can work on the webserver. + +My personal goal is to make this interface simple, so that coding it +will be like coding in some scripting language... + + + +char *get_param(char in_string[500], char swhat[500]); + +This function simply returns various data from the query string. + *Pass get_param NOTHING longer than 500 in length! + + What do I pass where in_string is? + The query string. + + What do I pass where swhat is? + One of two things... + Either 0 for the path of the 'page' + or you can pass it the param you wish to lookup. + + + + + + +char *get_query(char *inquery); + +This function simply returns a query string from the raw server request. +This is used once in main, I doubt you'll need it. + + + + + +void web_send(int sockin, char *in_data); + +Super easy way of sending data to a webpage! +Simply put in the socket name and then the data. + + Ex: + web_send(socket, "I like cheese!\n"); + + + + +char *html_header(char* title); +Easy way to print the eAthena header for the server. + + Ex: + web_send(sockethere, html_header("About")); diff --git a/src/webserver/generate.c b/src/webserver/generate.c index 26d2c7492..ad050db4c 100644 --- a/src/webserver/generate.c +++ b/src/webserver/generate.c @@ -1,38 +1,38 @@ -
-void generate_page(char password[25], int sock_in, char *query, char *ip)
-{
- char *page = get_param(query, 0);
- char *ppass = get_param(query, "password");
-
-
- if ( (ppass == 0) || (strcmp(password, ppass) != 0) )
- {
- web_send(sock_in, html_header("Enter your password"));
- web_send(sock_in, "<H1>NOT LOGGED IN!</H1><form action=\"/\" method=\"GET\">\n");
- web_send(sock_in, "Enter your password:<br>\n<input type=\"text\" name=\"password\">\n");
- web_send(sock_in, "<input type=\"submit\" value=\"Login\">\n");
- }
- else
- {
-
-
- //To make this simple, we will have a bunch of if statements
- //that then shoot out data off into functions.
-
-
- //The 'index'
- if ( strcmp(page, "/") == 0 )
- generate_notdone(sock_in, query, ip);
-
-
- //About page:
- if ( strcmp(page, "/about.html") == 0 )
- generate_about(sock_in, query, ip);
-
-
- //Test page:
- if ( strcmp(page, "/testing/") == 0 )
- generate_sample(sock_in, query, ip);
-
- }
-}
+ +void generate_page(char password[25], int sock_in, char *query, char *ip) +{ + char *page = get_param(query, 0); + char *ppass = get_param(query, "password"); + + + if ( (ppass == 0) || (strcmp(password, ppass) != 0) ) + { + web_send(sock_in, html_header("Enter your password")); + web_send(sock_in, "<H1>NOT LOGGED IN!</H1><form action=\"/\" method=\"GET\">\n"); + web_send(sock_in, "Enter your password:<br>\n<input type=\"text\" name=\"password\">\n"); + web_send(sock_in, "<input type=\"submit\" value=\"Login\">\n"); + } + else + { + + + //To make this simple, we will have a bunch of if statements + //that then shoot out data off into functions. + + + //The 'index' + if ( strcmp(page, "/") == 0 ) + generate_notdone(sock_in, query, ip); + + + //About page: + if ( strcmp(page, "/about.html") == 0 ) + generate_about(sock_in, query, ip); + + + //Test page: + if ( strcmp(page, "/testing/") == 0 ) + generate_sample(sock_in, query, ip); + + } +} diff --git a/src/webserver/htmlstyle.c b/src/webserver/htmlstyle.c index a1320a385..c3a4b927a 100644 --- a/src/webserver/htmlstyle.c +++ b/src/webserver/htmlstyle.c @@ -1,51 +1,51 @@ -char output[10000];
-
-char *html_header(char *title)
-{
- memset(output, 0x0, 10000);
- char *text = "<body text=\"#000000\" bgcolor=\"#939393\" link=\"#0033FF\">\n"
- "<br><table width=\"92%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\"\n"
- "align=\"center\" class=\"bordercolor\"><tbody><tr><td class=\"bordercolor\" width=\"100%\">\n"
- "<table bgcolor=\"#ffffff\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n"
- "<tbody><tr><td><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#ffffff\">\n"
- "<tbody><tr><img src=\"http://eathena.sourceforge.net/athena.jpg\" alt=\"Athena\">\n"
- "<td bgcolor=\"#ffffff\"></td></tr></tbody></table></td></tr></tbody></table>\n"
- "</td></tr><tr align=\"left\"><td class=\"bordercolor\"><table bgcolor=\"#c6c6c6\" width=\"100%\" cellspacing=\"0\"\n"
- "cellpadding=\"0\" style=\"text-align: left; margin-right: auto; margin-left: 0px;\">\n";
- "<tbody><tr><td width=\"100%\" align=\"center\"><table border=\"0\" width=\"100%\" cellpadding=\"3\"\n"
- "cellspacing=\"0\" bgcolor=\"#c6c6c6\" align=\"center\"><tbody><tr>"
- "<td valign=\"middle\" bgcolor=\"#c6c6c6\" align=\"center\"><a href=\"/cgi-bin/forum/YaBB.cgi\">"
- "<span style=\"text-decoration: underline;\"><span style=\"font-weight: bold;\">\n"
- "To the Forum</span></span></a><br></td></tr></tbody></table></td></tr></tbody>\n"
- "</table></td></tr><tr><td class=\"bordercolor\" align=\"center\">\n"
- "<table bgcolor=\"#ffffff\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n"
- "<tbody><tr><td width=\"100%\" align=\"center\"><table border=\"0\" width=\"100%\" cellpadding=\"5\"\n"
- "cellspacing=\"0\" bgcolor=\"#ffffff\" align=\"center\"><tbody><tr>\n"
- "<td valign=\"middle\" bgcolor=\"#ffffff\" align=\"center\"><font size=\"2\" color=\"#6e94b7\">\n"
- "<b>Athena</b> « Portal »</font></td></tr></tbody></table></td></tr></tbody>"
- "</table></td></tr></tbody></table>\n";
-
- sprintf(output, "<title>%s</title>\n%s\n", title, text);
-
- return output;
-}
-
-
-
-char *html_start_form(char *location, char *action)
-{
- memset(output, 0x0, 10000);
- sprintf(output, "<form action=\"%s\" method=\"%s\">", location, action);
- return output;
-
-
-}
-
-
-char *html_end_forum(void)
-{
- return "</form>";
-}
-
-
-
+char output[10000]; + +char *html_header(char *title) +{ + memset(output, 0x0, 10000); + char *text = "<body text=\"#000000\" bgcolor=\"#939393\" link=\"#0033FF\">\n" + "<br><table width=\"92%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\"\n" + "align=\"center\" class=\"bordercolor\"><tbody><tr><td class=\"bordercolor\" width=\"100%\">\n" + "<table bgcolor=\"#ffffff\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n" + "<tbody><tr><td><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#ffffff\">\n" + "<tbody><tr><img src=\"http://eathena.sourceforge.net/athena.jpg\" alt=\"Athena\">\n" + "<td bgcolor=\"#ffffff\"></td></tr></tbody></table></td></tr></tbody></table>\n" + "</td></tr><tr align=\"left\"><td class=\"bordercolor\"><table bgcolor=\"#c6c6c6\" width=\"100%\" cellspacing=\"0\"\n" + "cellpadding=\"0\" style=\"text-align: left; margin-right: auto; margin-left: 0px;\">\n"; + "<tbody><tr><td width=\"100%\" align=\"center\"><table border=\"0\" width=\"100%\" cellpadding=\"3\"\n" + "cellspacing=\"0\" bgcolor=\"#c6c6c6\" align=\"center\"><tbody><tr>" + "<td valign=\"middle\" bgcolor=\"#c6c6c6\" align=\"center\"><a href=\"/cgi-bin/forum/YaBB.cgi\">" + "<span style=\"text-decoration: underline;\"><span style=\"font-weight: bold;\">\n" + "To the Forum</span></span></a><br></td></tr></tbody></table></td></tr></tbody>\n" + "</table></td></tr><tr><td class=\"bordercolor\" align=\"center\">\n" + "<table bgcolor=\"#ffffff\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n" + "<tbody><tr><td width=\"100%\" align=\"center\"><table border=\"0\" width=\"100%\" cellpadding=\"5\"\n" + "cellspacing=\"0\" bgcolor=\"#ffffff\" align=\"center\"><tbody><tr>\n" + "<td valign=\"middle\" bgcolor=\"#ffffff\" align=\"center\"><font size=\"2\" color=\"#6e94b7\">\n" + "<b>Athena</b> « Portal »</font></td></tr></tbody></table></td></tr></tbody>" + "</table></td></tr></tbody></table>\n"; + + sprintf(output, "<title>%s</title>\n%s\n", title, text); + + return output; +} + + + +char *html_start_form(char *location, char *action) +{ + memset(output, 0x0, 10000); + sprintf(output, "<form action=\"%s\" method=\"%s\">", location, action); + return output; + + +} + + +char *html_end_forum(void) +{ + return "</form>"; +} + + + diff --git a/src/webserver/logs.c b/src/webserver/logs.c index faa1abf80..405b4882b 100644 --- a/src/webserver/logs.c +++ b/src/webserver/logs.c @@ -1,8 +1,8 @@ -#include <time.h>
-
-void log_visit(char *query, char *ip)
-{
- time_t timer;
- timer=time(NULL);
- printf("%s - \"%s\" - %s", ip, query, asctime(localtime(&timer)));
-}
+#include <time.h> + +void log_visit(char *query, char *ip) +{ + time_t timer; + timer=time(NULL); + printf("%s - \"%s\" - %s", ip, query, asctime(localtime(&timer))); +} diff --git a/src/webserver/main.c b/src/webserver/main.c index ac27c5e71..59362558e 100644 --- a/src/webserver/main.c +++ b/src/webserver/main.c @@ -1,142 +1,142 @@ -/***************************************************************************
- description
- -------------------
- author : (C) 2004 by Michael J. Flickinger
- email : mjflick@cpan.org
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/wait.h>
-#include <signal.h>
-
-#define BLOG 10
-
-char *header = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n";
-char recvin[500], password[25];
-int s_port;
-
-void sigchld_handler(int s)
-{
- while(wait(NULL) > 0);
-}
-
-int main(int argc, char **argv)
-{
- if (argc < 3)
- {
- printf("eAthena Web Server\n");
- printf("usage: %s [password] [port]\n", argv[0]);
- exit(0);
- }
-
- s_port = atoi(argv[2]);
-
- if ((s_port < 1) || (s_port > 65534))
- {
- printf("Error: The port you choose is not valid port.\n");
- exit(0);
- }
-
- if (strlen(argv[1]) > 25)
- {
- printf("Error: Your password is too long.\n");
- printf("It must be shorter than 25 characters.\n");
- exit(0);
- }
-
- memset(password, 0x0, 25);
- memcpy(password, argv[1], strlen(argv[1]));
-
- int sockfd, new_fd;
- struct sockaddr_in my_addr;
- struct sockaddr_in their_addr;
- int sin_size;
-
- struct sigaction sa;
-
- int yes=1;
-
- if ((sockfd = socket(AF_INET, SOCK_STREAM,0)) == -1)
- {
- perror("Darn, this is broken.");
- exit(0);
- }
-
- if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1)
- {
- perror("Error... :-(");
- }
-
- //Now we know we have a working socket. :-)
-
- my_addr.sin_family = AF_INET;
- my_addr.sin_port = htons(s_port);
- my_addr.sin_addr.s_addr = INADDR_ANY;
- memset(&(my_addr.sin_zero), '\0', 8);
-
- if ( bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)
- {
- perror("can not bind to this port");
- exit(0);
- }
-
- if ( listen(sockfd, BLOG) == -1)
- {
- perror("can not listen on port");
- exit(0);
- }
-
- sa.sa_handler = sigchld_handler;
-
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
-
- if (sigaction(SIGCHLD, &sa, NULL) == -1)
- {
- perror("sigaction sucks");
- exit(0);
- }
-
- printf("The eAthena webserver is up and listening on port %i.\n", s_port);
-
- while(1)
- {
- sin_size = sizeof(struct sockaddr_in);
- new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
-
- if (!fork())
- {
- close(sockfd);
- memset(recvin, 0x0, 500);
- recv(new_fd, recvin, 500, 0);
- send(new_fd, header, strlen(header), 0);
- generate_page(password, new_fd, get_query(recvin), inet_ntoa(their_addr.sin_addr));
- log_visit(get_query(recvin), inet_ntoa(their_addr.sin_addr));
-
- close(new_fd);
- exit(0);
- }
- close(new_fd);
- }
-
- return 0;
-}
+/*************************************************************************** + description + ------------------- + author : (C) 2004 by Michael J. Flickinger + email : mjflick@cpan.org + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/wait.h> +#include <signal.h> + +#define BLOG 10 + +char *header = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"; +char recvin[500], password[25]; +int s_port; + +void sigchld_handler(int s) +{ + while(wait(NULL) > 0); +} + +int main(int argc, char **argv) +{ + if (argc < 3) + { + printf("eAthena Web Server\n"); + printf("usage: %s [password] [port]\n", argv[0]); + exit(0); + } + + s_port = atoi(argv[2]); + + if ((s_port < 1) || (s_port > 65534)) + { + printf("Error: The port you choose is not valid port.\n"); + exit(0); + } + + if (strlen(argv[1]) > 25) + { + printf("Error: Your password is too long.\n"); + printf("It must be shorter than 25 characters.\n"); + exit(0); + } + + memset(password, 0x0, 25); + memcpy(password, argv[1], strlen(argv[1])); + + int sockfd, new_fd; + struct sockaddr_in my_addr; + struct sockaddr_in their_addr; + int sin_size; + + struct sigaction sa; + + int yes=1; + + if ((sockfd = socket(AF_INET, SOCK_STREAM,0)) == -1) + { + perror("Darn, this is broken."); + exit(0); + } + + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) + { + perror("Error... :-("); + } + + //Now we know we have a working socket. :-) + + my_addr.sin_family = AF_INET; + my_addr.sin_port = htons(s_port); + my_addr.sin_addr.s_addr = INADDR_ANY; + memset(&(my_addr.sin_zero), '\0', 8); + + if ( bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) + { + perror("can not bind to this port"); + exit(0); + } + + if ( listen(sockfd, BLOG) == -1) + { + perror("can not listen on port"); + exit(0); + } + + sa.sa_handler = sigchld_handler; + + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + + if (sigaction(SIGCHLD, &sa, NULL) == -1) + { + perror("sigaction sucks"); + exit(0); + } + + printf("The eAthena webserver is up and listening on port %i.\n", s_port); + + while(1) + { + sin_size = sizeof(struct sockaddr_in); + new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size); + + if (!fork()) + { + close(sockfd); + memset(recvin, 0x0, 500); + recv(new_fd, recvin, 500, 0); + send(new_fd, header, strlen(header), 0); + generate_page(password, new_fd, get_query(recvin), inet_ntoa(their_addr.sin_addr)); + log_visit(get_query(recvin), inet_ntoa(their_addr.sin_addr)); + + close(new_fd); + exit(0); + } + close(new_fd); + } + + return 0; +} diff --git a/src/webserver/pages/about.c b/src/webserver/pages/about.c index f1d94d1e0..2b0002ad8 100644 --- a/src/webserver/pages/about.c +++ b/src/webserver/pages/about.c @@ -1,6 +1,6 @@ -void generate_about(int sock_in, char *query, char *ip)
-{
-//printf("%s", html_header("About"));
- web_send(sock_in, html_header("About"));
- web_send(sock_in, "<center>eAthena Web Server!</center>\n");
-}
+void generate_about(int sock_in, char *query, char *ip) +{ +//printf("%s", html_header("About")); + web_send(sock_in, html_header("About")); + web_send(sock_in, "<center>eAthena Web Server!</center>\n"); +} diff --git a/src/webserver/pages/notdone.c b/src/webserver/pages/notdone.c index 07abd33da..a6492e361 100644 --- a/src/webserver/pages/notdone.c +++ b/src/webserver/pages/notdone.c @@ -1,5 +1,5 @@ -void generate_notdone(int sock_in, char *query, char *ip)
-{
- web_send(sock_in, "<title>Not here!</title>\n");
- web_send(sock_in, "<h2><center>This page/feature is not done yet.</center>\n</h2>");
-}
+void generate_notdone(int sock_in, char *query, char *ip) +{ + web_send(sock_in, "<title>Not here!</title>\n"); + web_send(sock_in, "<h2><center>This page/feature is not done yet.</center>\n</h2>"); +} diff --git a/src/webserver/pages/sample.c b/src/webserver/pages/sample.c index 7bec663f2..be900a1bf 100644 --- a/src/webserver/pages/sample.c +++ b/src/webserver/pages/sample.c @@ -1,24 +1,24 @@ -
-
-void generate_sample(int sock_in, char *query, char *ip)
-{
-
- char *name = get_param(query, "name");
-
- web_send(sock_in, "<title>SAMPLE</title>\n");
-
-
- //If a name was not entered...
- if ( name == '\0' )
- {
- web_send(sock_in, "<form action=\"/testing/\" method=\"GET\">\n");
- web_send(sock_in, "<input type=\"text\" name=\"name\">\n");
- web_send(sock_in, "<input type=\"submit\">\n");
- }
- else
- {
- web_send(sock_in, "Your name is: ");
- web_send(sock_in, get_param(query, "name"));
- }
-printf("OK!\n");
-}
+ + +void generate_sample(int sock_in, char *query, char *ip) +{ + + char *name = get_param(query, "name"); + + web_send(sock_in, "<title>SAMPLE</title>\n"); + + + //If a name was not entered... + if ( name == '\0' ) + { + web_send(sock_in, "<form action=\"/testing/\" method=\"GET\">\n"); + web_send(sock_in, "<input type=\"text\" name=\"name\">\n"); + web_send(sock_in, "<input type=\"submit\">\n"); + } + else + { + web_send(sock_in, "Your name is: "); + web_send(sock_in, get_param(query, "name")); + } +printf("OK!\n"); +} diff --git a/src/webserver/parse.c b/src/webserver/parse.c index 323261c6c..8e54a81de 100644 --- a/src/webserver/parse.c +++ b/src/webserver/parse.c @@ -1,135 +1,135 @@ -#include <stdlib.h>
-
-char filtered_query[2000];
-char rdata[500];
-char param_n[500];
-char param_d[500];
-
-
-char *get_query(char *inquery)
-{
- memset(filtered_query, 0x0, 2000);
- sscanf(inquery, "GET %s %[$]", filtered_query);
- return(filtered_query);
-}
-
-void web_send(int sockin, char *in_data)
-{
- send(sockin, in_data, strlen(in_data), 0);
-}
-
-
-//THIS IS BAD CODE BE CAREFULL WITH IT!
-//Watch out for buffer overflow...
-//When using please make sure to check the string size.
-
-//Also note:
-//I take no pride in this code, it is a really bad way of doing this...
-char *get_param(char in_string[500], char swhat[500])
-{
- int i = 0;
- int marker, iswitch, pint, dint;
- char flux[500];
- memset(flux, 0x0, 500);
-
- //Get the path of out "page"
- if (swhat == 0)
- {
- //while i is not equal to array size
- while (i != 500)
- {
- //if there is a question mark, halt!
- if (in_string[i] == '?')
- {
- i = 499;
- }
- else
- rdata[i] = in_string[i];
-
- i++;
- }
- return rdata;
- }
- else //so, we want a param...
- {
- //calculate where param begins
- while (i != 500)
- {
- if (in_string[i] == '?')
- {
- marker = i + 1;
- i = 499;
- }
- i++;
- }
-
- i = 0;
-
- //keep morons from trying to crash this
- if ((marker > 500)||(marker < 1))
- marker = 500;
-
- while(marker != 500)
- {
- if ((in_string[marker] != '&') && (in_string[marker] != '\0'))
- {
- flux[i] = in_string[marker];
- i++;
- }
- else
- {
-
- //we have a param, now we must dig through it
-
- //clear temp vars
- memset(param_n, 0x0, 500);
- memset(param_d, 0x0, 500);
- iswitch = 0;
- pint = 0;
- dint = 0;
- i = 0;
-
- //split result into param_n and param_d
- while(i != 500)
- {
- if ( (flux[i] != '=') && (flux[i] != '\0') )
- {
- if (iswitch == 0)
- {
- param_n[pint] = flux[i];
- pint++;
- }
- else
- {
- param_d[dint] = flux[i];
- dint++;
- }
- }
- else
- {
- iswitch = 1;
- }
- if (flux[i] == '\0')
- i = 499;
-
- i++;
- }
-
- if ( strcmp(param_n, swhat) == 0 )
- {
- return param_d;
- }
-
- i = 0;
- }
-
- if (in_string[marker] == '\0')
- {
- marker = 499;
- }
- marker++;
- }
- return 0;
- }
-}
-
+#include <stdlib.h> + +char filtered_query[2000]; +char rdata[500]; +char param_n[500]; +char param_d[500]; + + +char *get_query(char *inquery) +{ + memset(filtered_query, 0x0, 2000); + sscanf(inquery, "GET %s %[$]", filtered_query); + return(filtered_query); +} + +void web_send(int sockin, char *in_data) +{ + send(sockin, in_data, strlen(in_data), 0); +} + + +//THIS IS BAD CODE BE CAREFULL WITH IT! +//Watch out for buffer overflow... +//When using please make sure to check the string size. + +//Also note: +//I take no pride in this code, it is a really bad way of doing this... +char *get_param(char in_string[500], char swhat[500]) +{ + int i = 0; + int marker, iswitch, pint, dint; + char flux[500]; + memset(flux, 0x0, 500); + + //Get the path of out "page" + if (swhat == 0) + { + //while i is not equal to array size + while (i != 500) + { + //if there is a question mark, halt! + if (in_string[i] == '?') + { + i = 499; + } + else + rdata[i] = in_string[i]; + + i++; + } + return rdata; + } + else //so, we want a param... + { + //calculate where param begins + while (i != 500) + { + if (in_string[i] == '?') + { + marker = i + 1; + i = 499; + } + i++; + } + + i = 0; + + //keep morons from trying to crash this + if ((marker > 500)||(marker < 1)) + marker = 500; + + while(marker != 500) + { + if ((in_string[marker] != '&') && (in_string[marker] != '\0')) + { + flux[i] = in_string[marker]; + i++; + } + else + { + + //we have a param, now we must dig through it + + //clear temp vars + memset(param_n, 0x0, 500); + memset(param_d, 0x0, 500); + iswitch = 0; + pint = 0; + dint = 0; + i = 0; + + //split result into param_n and param_d + while(i != 500) + { + if ( (flux[i] != '=') && (flux[i] != '\0') ) + { + if (iswitch == 0) + { + param_n[pint] = flux[i]; + pint++; + } + else + { + param_d[dint] = flux[i]; + dint++; + } + } + else + { + iswitch = 1; + } + if (flux[i] == '\0') + i = 499; + + i++; + } + + if ( strcmp(param_n, swhat) == 0 ) + { + return param_d; + } + + i = 0; + } + + if (in_string[marker] == '\0') + { + marker = 499; + } + marker++; + } + return 0; + } +} + |