Logo
~Sockets~
~Examples~
~Contact~


ServerSocket.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 //#include <stdio.h>
00024 
00025 #include "Deliver.h"
00026 #include "ServerSocket.h"
00027 #include "ServerHandler.h"
00028 
00029 #define DEB(x) x
00030 
00031 
00032 ServerSocket::ServerSocket(ISocketHandler& h)
00033 :HTTPSocket(h)
00034 ,Gemensamt()
00035 {
00036 }
00037 
00038 
00039 ServerSocket::~ServerSocket()
00040 {
00041 }
00042 
00043 
00044 void ServerSocket::OnFirst()
00045 {
00046         //printf("IsRequest: %s\n",IsRequest() ? "YES" : "NO");
00047         if (IsRequest())
00048         {
00049                 printf(" Method: %s\n",GetMethod().c_str());
00050                 printf(" URL: %s\n",GetUrl().c_str());
00051                 printf(" Http version: %s\n",GetHttpVersion().c_str());
00052         }
00053 
00054         //printf("IsResponse: %s\n",IsResponse() ? "YES" : "NO");
00055         if (IsResponse())
00056         {
00057                 //printf(" Http version: %s\n",GetHttpVersion().c_str());
00058                 //printf(" Status: %s\n",GetStatus().c_str());
00059                 //printf(" Status text: %s\n",GetStatusText().c_str());
00060         }
00061 
00062 }
00063 
00064 
00065 void ServerSocket::OnHeader(const std::string& key,const std::string& value)
00066 {
00067         //printf("OnHeader(): %s: %s\n",key.c_str(),value.c_str());
00068         if (!strcasecmp(key.c_str(),"host"))
00069         {
00070                 SetServer(value);
00071         }
00072         else
00073         if (!strcasecmp(key.c_str(),"user-agent"))
00074         {
00075                 SetUserAgent(value);
00076         }
00077         else
00078         if (!strcasecmp(key.c_str(),"referer"))
00079         {
00080                 SetHttpReferer(value);
00081         }
00082 }
00083 
00084 
00085 void ServerSocket::OnData(const char *,size_t)
00086 {
00087 }
00088 
00089 
00090 void ServerSocket::OnHeaderComplete()
00091 {
00092 #ifdef ENABLE_DETACH
00093         if (!Detach())
00094         {
00095 DEB(            printf("Detach() failed\n");)
00096                 SetCloseAndDelete();
00097         }
00098 #endif
00099 }
00100 
00101 
00102 void ServerSocket::OnDetached()
00103 {
00104         Deliver d(*this,GetServer(),"http",GetMethod(),GetUrl());
00105         d.Run();
00106 }
00107 
00108 
00109 void ServerSocket::Init() 
00110 {
00111         ServerHandler& ref = static_cast<ServerHandler&>(Handler());
00112         if (GetParent() -> GetPort() == ref.GetInt("secure/port"))
00113         {
00114                 EnableSSL();
00115         }
00116 }
00117 
00118 
00119 void ServerSocket::OnAccept() 
00120 {
00121         printf("Accept!\n");
00122         HTTPSocket::OnAccept();
00123 }
00124 
00125 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4