Guest User

Untitled

a guest
Feb 7th, 2012
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Application: basic-webserver, Web.h
  3.  * Author: Project, UNX511, Team A
  4.  * Description: Web class (header) - responsible for creating sockets and listening for connections.
  5.  * A webserver that has been coded from scratch.
  6.  * It uses Linux's socket library to deal with connections.
  7.  *
  8.  * This application is licensed under Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
  9.  * See this for more information: http://creativecommons.org/licenses/by-nc-sa/3.0/
  10.  */
  11.  
  12. #ifndef _INCL_WEB
  13. #define _INCL_WEB
  14.  
  15. #include <sys/types.h>
  16. #include <sys/socket.h>
  17. #include <netinet/in.h>
  18. #include <sys/wait.h>
  19. #include <fcntl.h>
  20.  
  21. // C++ way of including things.
  22. #include <string>
  23. #include <cstring>
  24. #include <map>
  25. #include <iostream>
  26. #include <cerrno>
  27. #include <cstdio>
  28.  
  29. using namespace std;
  30.  
  31. #define BUFSIZE 8096
  32. #define ERROR   11
  33. #define LOG     22
  34. #define HTTP_GENERIC_HEADER "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
  35.  
  36. class Web {
  37.  
  38. private:
  39.    int _socket;
  40.    int _nSocket;
  41.    int _port;
  42.    socklen_t _clilen;
  43.    struct sockaddr_in
  44.       _serv_addr, _cli_addr;
  45. public:
  46.    Web();
  47.    Web(int port);
  48.    int run();
  49.    bool isHttpResponseOf(string haystack, string needle);
  50.    void process(int socket);
  51.    void log(int type, char* s1, char* s2, int num);
  52.    ~Web();
  53.  
  54. };
  55.  
  56. #endif
RAW Paste Data