00001
00002
00003
00004
00005
00006
00007
00008
00009
00015 #ifndef ADSONET_H
00016 #define ADSONET_H
00017
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #ifdef ADSO_WINDOWS
00021 #include <winsock.h>
00022 #else
00023 #include <unistd.h>
00024 #include <netdb.h>
00025 #include <netinet/in.h>
00026 #include <sys/socket.h>
00027 #endif
00028 #include <fcntl.h>
00029 #include <errno.h>
00030 #include <string.h>
00031 #include <sys/types.h>
00032 #include <adsobase.h>
00033
00034 #ifdef ADSO_WINDOWS
00035 #define CLOSESOCKET closesocket
00036 #define SOCKET_NONBLOCKING(s) { u_long a = 1; if(ioctlsocket(sockfd,FIONBIO,&a)) fatal("Failed to created nonblocking socket"); }
00037 #else
00038 #define CLOSESOCKET close
00039 #define SOCKET_NONBLOCKING(s) if(fcntl(s,F_SETFL,O_NONBLOCK)) fatal("Failed to created nonblocking socket");
00040 #endif
00041
00043
00045
00046 typedef unsigned int UserID;
00047
00048 void netInit();
00049
00050 struct DbEntry {
00051 UserID id;
00052 char *ip;
00053 char *userName;
00054 char *version;
00055 int postAge;
00056 int appTime;
00057 int postCount;
00058 int staticIp;
00059 char *hostType;
00060 char *state;
00061
00062 };
00063
00064 class Database {
00065 DbEntry **entries;
00066 int size,count;
00067
00068 public:
00069 DbEntry *getEntry(int i);
00070 void addEntry(DbEntry *);
00071 int entryCount(){ return count; }
00072 int requestDB();
00073 void purge();
00074 Database();
00075 ~Database();
00076 };
00077
00079
00081
00082 class HttpReq {
00083 int sockfd;
00084 struct hostent *he;
00085 struct sockaddr_in host_addr;
00086 char *hostname;
00087 char *reqString;
00088 char *buf;
00089 int bufSize;
00090 int bufCount,pos;
00091 int connecting, sending, receiving;
00092 int aborted, errorNumber, invalidHost, disabled;
00093 char stateMsg[256];
00094
00095 public:
00096 int get(char *filename);
00097 int getAsync(char *filename);
00098 int post(char *filename, char *data);
00099 int postAsync(char *filename, char *data);
00100 int reqDone();
00101 void abort();
00102 int isAborted() { return aborted; }
00103 int waitForSend(int timeout);
00104 int getError() { return errorNumber; }
00105 int hostValid() { return !invalidHost; }
00106 char *getLine();
00107 char *getText();
00108 char *getStateMsg();
00109 int isEnabled(){ return !disabled && !invalidHost; }
00110
00111 HttpReq(char *hostname);
00112 };
00113
00114 #endif
00115