From: <eg...@us...> - 2006-08-31 20:16:23
|
Revision: 149 http://svn.sourceforge.net/opengate/?rev=149&view=rev Author: egore Date: 2006-08-31 13:16:09 -0700 (Thu, 31 Aug 2006) Log Message: ----------- add meta-server authentication Modified Paths: -------------- ChangeLog opengate.kdevelop src/opengate_server.cpp src/server/Makefile.am Added Paths: ----------- src/server/network_meta.cpp src/server/network_meta.h Modified: ChangeLog =================================================================== --- ChangeLog 2006-08-27 18:19:29 UTC (rev 148) +++ ChangeLog 2006-08-31 20:16:09 UTC (rev 149) @@ -1,5 +1,12 @@ 2006-08-27 Christoph Brill <eg...@us...> + * src/server/network_meta.h, src/server/network_meta.cpp: add method + to authenticate against the meta-server + + * src/opengate_server.cpp: test method for authentication + +2006-08-27 Christoph Brill <eg...@us...> + * configure.in: add support for libgrapple, add support for libxml2 * src/client/network.h, src/client/network.cpp, src/server/network.h, Modified: opengate.kdevelop =================================================================== --- opengate.kdevelop 2006-08-27 18:19:29 UTC (rev 148) +++ opengate.kdevelop 2006-08-31 20:16:09 UTC (rev 149) @@ -13,7 +13,7 @@ <ignoreparts/> <projectdirectory>.</projectdirectory> <absoluteprojectpath>false</absoluteprojectpath> - <description/> + <description></description> <versioncontrol>kdevsubversion</versioncontrol> </general> <kdevautoproject> @@ -23,7 +23,7 @@ <useactivetarget>true</useactivetarget> </general> <run> - <mainprogram>src/opengate-client</mainprogram> + <mainprogram>src/opengate-server</mainprogram> <terminal>true</terminal> <directoryradio>executable</directoryradio> <runarguments> @@ -32,7 +32,7 @@ <opengate-client/> </runarguments> <customdirectory>/</customdirectory> - <programargs/> + <programargs></programargs> <autocompile>true</autocompile> <envvars/> </run> @@ -224,12 +224,12 @@ </kdevcppsupport> <kdevdebugger> <general> - <programargs/> - <gdbpath/> + <programargs></programargs> + <gdbpath></gdbpath> <dbgshell>libtool</dbgshell> - <configGdbScript/> - <runShellScript/> - <runGdbScript/> + <configGdbScript></configGdbScript> + <runShellScript></runShellScript> + <runGdbScript></runGdbScript> <breakonloadinglibs>true</breakonloadinglibs> <separatetty>false</separatetty> <floatingtoolbar>false</floatingtoolbar> Modified: src/opengate_server.cpp =================================================================== --- src/opengate_server.cpp 2006-08-27 18:19:29 UTC (rev 148) +++ src/opengate_server.cpp 2006-08-31 20:16:09 UTC (rev 149) @@ -28,17 +28,8 @@ #include <signal.h> #include "server/network.h" +#include "server/network_meta.h" - -#include <stdio.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <string.h> - -#define DIRSIZE 1024 - bool done; /*! @brief a signal handler @@ -65,57 +56,14 @@ sleep(1); }*/ - char dir[DIRSIZE]; - int sd; - struct sockaddr_in sin; - struct sockaddr_in pin; - struct hostent *hp; + NetworkMeta* nwm = new NetworkMeta(); + printf("--(%d)--\n", nwm->check_login("XXX", "YYY")); - /* go find out about the desired host machine */ - if ((hp = gethostbyname("opengate.sourceforge.net")) == 0) { - perror("gethostbyname"); - exit(1); - } - - /* fill in the socket structure with host information */ - memset(&pin, 0, sizeof(pin)); - pin.sin_family = AF_INET; - pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; - pin.sin_port = htons(80); - - /* grab an Internet domain socket */ - if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - perror("socket"); - exit(1); - } - - /* connect to PORT on HOST */ - if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) { - perror("connect"); - exit(1); - } - - char* request = "GET /game/game_login.php HTTP/1.1\r\nHost: opengate.sourceforge.net\r\n\r\n"; - - /* send a message to the server PORT on machine HOST */ - if (send(sd, request, strlen(request), 0) == -1) { - perror("send"); - exit(1); - } - - /* wait for a message to come back from the server */ - if (recv(sd, dir, DIRSIZE, 0) == -1) { - perror("recv"); - exit(1); - } - - // spew-out the results and bail out of here! - printf("%s\n---\n", dir); - std::cout << "Shutting down" << std::endl; std::cout << "-------------" << std::endl; //delete(nw); + delete(nwm); return EXIT_SUCCESS; } Modified: src/server/Makefile.am =================================================================== --- src/server/Makefile.am 2006-08-27 18:19:29 UTC (rev 148) +++ src/server/Makefile.am 2006-08-31 20:16:09 UTC (rev 149) @@ -1,5 +1,5 @@ INCLUDES = $(all_includes) METASOURCES = AUTO noinst_LTLIBRARIES = libopengate-server.la -noinst_HEADERS = network.h -libopengate_server_la_SOURCES = network.cpp +noinst_HEADERS = network.h network_meta.h +libopengate_server_la_SOURCES = network.cpp network_meta.cpp Added: src/server/network_meta.cpp =================================================================== --- src/server/network_meta.cpp (rev 0) +++ src/server/network_meta.cpp 2006-08-31 20:16:09 UTC (rev 149) @@ -0,0 +1,125 @@ +/*************************************************************************** + * network_meta.h + * + * Sat Aug 31 21:04:10 2006 + * Copyright 2006 Christoph Brill + * Email <eg...@us...> + ****************************************************************************/ + +/* + * 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. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <network_meta.h> + +#include <iostream> + +int NetworkMeta::check_login(std::string username, std::string password) { + char dir[BUFFER_SIZE]; + int sd; + struct sockaddr_in sin; + struct sockaddr_in pin; + struct hostent *hp; + + std::string hostname = "opengate.sourceforge.net"; + + /* go find out about the desired host machine */ + if ((hp = gethostbyname(hostname.c_str())) == 0) { + perror("gethostbyname"); + exit(1); + } + + /* fill in the socket structure with host information */ + memset(&pin, 0, sizeof(pin)); + pin.sin_family = AF_INET; + pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; + pin.sin_port = htons(80); + + /* grab an Internet domain socket */ + if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + perror("socket"); + exit(1); + } + + /* connect to PORT on HOST */ + if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) { + perror("connect"); + exit(1); + } + + std::string request = "GET /game/game_login.php?username=" + username + "&password=" + password + " HTTP/1.1\r\nHost: " + hostname + "\r\n\r\n"; + + /* send a message to the server PORT on machine HOST */ + if (send(sd, request.c_str(), request.length(), 0) == -1) { + perror("send"); + exit(1); + } + + /* wait for a message to come back from the server */ + if (recv(sd, dir, BUFFER_SIZE, 0) == -1) { + perror("recv"); + exit(1); + } + + char* error = strstr(dir, "404 Not Found\r\n"); + if (error) { + return -100; + } + error = strstr(dir, "400 Bad Request\r\n"); + if (error) { + return -101; + } + + char* content = strstr(dir, "Content-Length: "); + if (content) { + // Apache 2.x + + // determine data length + content += strlen("Content-Length: "); + char* data_len_str = strstr(content, "\r\n"); + *data_len_str = '\0'; + int data_len = atoi(content); + *data_len_str = '\r'; + + // determine data + char* data = strstr(content, "\r\n\r\n"); + data += strlen("\r\n\r\n"); + char* data2 = data + data_len; + *data2 = '\0'; + int result = atoi(data); + return result; + + } else { + // Apache 1.3x + + content = strstr(dir, "\r\n\r\n"); + + // determine data length + content += strlen("\r\n\r\n"); + char* data_len_str = strstr(content, "\r\n"); + *data_len_str = '\0'; + int data_len = atoi(content); + *data_len_str = '\r'; + + // determine data + data_len_str += strlen("\r\n"); + char* data = strstr(data_len_str, "\r\n"); + data += strlen("\r\n"); + char* data2 = data + data_len; + *data2 = '\0'; + int result = atoi(data); + return result; + } +} Property changes on: src/server/network_meta.cpp ___________________________________________________________________ Name: svn:mime-type + text/x-c++src Name: svn:eol-style + native Added: src/server/network_meta.h =================================================================== --- src/server/network_meta.h (rev 0) +++ src/server/network_meta.h 2006-08-31 20:16:09 UTC (rev 149) @@ -0,0 +1,48 @@ +/*************************************************************************** + * network_meta.h + * + * Sat Aug 31 21:04:10 2006 + * Copyright 2006 Christoph Brill + * Email <eg...@us...> + ****************************************************************************/ + +/* + * 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. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _OPENGATE_NETWORK_META_ +#define _OPENGATE_NETWORK_META_ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <string.h> +#include <string> + +#define BUFFER_SIZE 512 + +class NetworkMeta { +public: + int check_login(std::string username, std::string password); + +}; + +#endif Property changes on: src/server/network_meta.h ___________________________________________________________________ Name: svn:mime-type + text/x-c++hdr Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |