00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _IScp_h_
00011 #define _IScp_h_
00012
00013
00014 #include "INet.h"
00015 #include "GDateTime.h"
00016
00017
00018 #define SCP_PORT 8010
00019 #define SCP_HTTP_VER 100 // VER * 100
00020 #define SCP_RETRIES 10
00021 #define SCP_SOCKET_TIMEOUT 10 // seconds
00022
00023 enum ScpCommand
00024 {
00025 SCP_NULL = 0,
00026 SCP_RESPONSE = 1,
00027 SCP_LOGIN = 2,
00028 SCP_QUIT = 3,
00029 SCP_SEARCH = 4,
00030 SCP_RESULT = 5,
00031 SCP_CREATE = 6,
00032 SCP_LOAD = 7,
00033 SCP_STORE = 8,
00034 SCP_DELETE = 9,
00035 SCP_POLL = 10,
00036 SCP_NOT_SCP = 11
00037 };
00038
00039 enum ScpObject
00040 {
00041 SCP_NONE = 0,
00042 SCP_USER = 1,
00043 SCP_EVENT = 2
00044 };
00045
00046
00047 class IScpData;
00048 class IScpServer;
00049
00050 class IScpUsage
00051 {
00052 public:
00053 virtual char *GetUsage(IScpServer *s) { return 0; }
00054 };
00055
00056 class IScp
00057 {
00058 bool Server;
00059
00060 protected:
00061 GUri Proxy;
00062 GUri Host;
00063 GStringPipe Info;
00064
00065 bool WriteData(GSocketI *&s, IScpData *d);
00066 bool ReadData(GSocketI *&s, IScpData *&d, int *HttpErr = 0);
00067
00068 public:
00069 IScp(bool server);
00070 virtual ~IScp();
00071
00072 void SetProxy(char *s) { Proxy = s; }
00073 char *GetInfo() { return Info.NewStr(); }
00074 };
00075
00076 class IScpSearch
00077 {
00078 public:
00079 int UserId;
00080 ScpObject Type;
00081 GDateTime Start;
00082 GDateTime End;
00083 char *Param;
00084
00085 IScpSearch();
00086 ~IScpSearch();
00087 };
00088
00089 class IScpData
00090 {
00091 friend class IScpClient;
00092 friend class IScpServer;
00093 friend class IScp;
00094
00095 ScpCommand Cmd;
00096 int Uid;
00097 static List<IScpData> Uids;
00098 ObjProperties Props;
00099
00100 public:
00101 ScpObject Type;
00102 int UserId;
00103 char *Data;
00104
00105
00106 IScpData(ScpCommand c = SCP_NULL);
00107 ~IScpData();
00108
00109
00110 int GetUid() { return Uid; }
00111 void SetUid(int i) { Uid = i; }
00112 static IScpData *GetObject(int id);
00113
00114
00115 char *GetStr(char *Field);
00116 void SetStr(char *Field, char *s);
00117 int GetInt(char *Field);
00118 void SetInt(char *Field, int i);
00119 };
00120
00121 class IScpClient : public IScp
00122 {
00123 GSocketI *s;
00124 int Session;
00125
00126 GSocketI *&Socket(bool Open = true);
00127 bool Request(IScpData *out, IScpData *&in);
00128
00129 public:
00130 bool *Loop;
00131
00132 IScpClient();
00133 ~IScpClient();
00134
00135 bool Connect(GSocketI *sock, char *Server, char *User, char *Pass);
00136 bool Quit();
00137 bool Search(IScpSearch *Search, IScpData *&Results);
00138 bool Load(int Uid, IScpData *Data);
00139 bool Save(IScpData *Data);
00140 bool Delete(IScpData *Data);
00141 bool Poll(List<int> &Changed);
00142 };
00143
00144 class IScpServer : public IScp
00145 {
00146 IScpUsage *Usage;
00147
00148 protected:
00149 virtual bool LoggedIn(int SeshId) { return false; }
00150
00151 bool Respond(GSocketI *s, int Code);
00152
00153 public:
00154 IScpServer(IScpUsage *usage = 0);
00155 ~IScpServer();
00156
00157 bool OnIdle(GSocketI *s);
00158
00159 virtual bool OnLogin(char *User, char *Pass, int Session) { return false; }
00160 virtual void OnQuit() { }
00161 virtual bool OnSearch(IScpSearch *Search, IScpData *Response) { return false; }
00162 virtual bool OnLoad(int Uid, IScpData *Data) { return false; }
00163 virtual int OnSave(IScpData *Data) { return false; }
00164 virtual bool OnDelete(IScpData *Data) { return false; }
00165 virtual bool OnPoll(IScpData *Data) { return false; }
00166 };
00167
00168
00169 #endif