00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <sys/types.h>
00042 #include <sys/socket.h>
00043
00044 #define IPCBUFSIZE 1024
00045
00046 #define PRIV_QUERY_NICK_ISREG 0x000001
00047 #define PRIV_QUERY_CHAN_ISREG 0x000002
00048 #define PRIV_QUERY_AKILL_LIST 0x000004
00049 #define PRIV_QUERY_NICK_PUBLIC 0x000008
00050 #define PRIV_QUERY_NICK_PRIVATE 0x000010
00051 #define PRIV_QUERY_NICK_UNMASK 0x000020
00052 #define PRIV_MAKE_NICK 0x000020
00053 #define PRIV_SET_BYPASS 0x000040
00054 #define PRIV_UNSET_BYPASS 0x000080
00055 #define PRIV_ALTER_RNICK_GEN 0x000100
00056 #define PRIV_ALTER_RNICK_2 0x000200
00057 #define PRIV_UNDEF 0x000400
00058 #define PRIV_ALTER_RNICK_3 0x000800
00059 #define PRIV_NOWNER_EQUIV 0x001000
00060 #define PRIV_COWNER_EQUIV 0x002000
00061 #define PRIV_RNICK_LOGIN 0x040000
00062 #define PRIV_RCHAN_LOGIN 0x080000
00063 #define PRIV_LOGW 0x100000
00064
00065 #define OPRIV_OWNER 0x000001
00066 #define OPRIV_SETPASS 0x000002
00067
00068 class IpcQ;
00069
00073 struct IpcQel
00074 {
00075 char *text;
00076 IpcQel *next;
00077 size_t len;
00078 };
00079
00086 class IpcQ
00087 {
00088 protected:
00094 char *qPush(char *text, char *sep, int *rlen) {
00095 IpcQel *z;
00096
00097 z = (IpcQel *)oalloc(sizeof(IpcQel) + (sep - text + 1));
00098
00099 *sep = '\0';
00100 *rlen = z->len = sep - text;
00101 z->text = (char *)oalloc(z->len + 1);
00102 strcpy(z->text, text);
00103
00104 if (firstEls == NULL)
00105 firstEls = lastEls = z;
00106 else
00107 {
00108 lastEls->next = z;
00109 lastEls = z;
00110 }
00111
00112 *sep = '\n';
00113
00114 return (sep + 1);
00115 }
00116
00117 public:
00118
00137 char *shove(char *textIn, size_t textLen, int *rlen) {
00138 char *p, *text = textIn;
00139
00140 for(p = text; p < (textIn + textLen); p++) {
00141 if (*p == '\n' || (*p == '\r' && p[1] == '\n')) {
00142 text = qPush(text, p, rlen);
00143 }
00144 }
00145
00146 return text;
00147 }
00148
00160 int pop(char cmd[IPCBUFSIZE]) {
00161 IpcQel *f;
00162 char *cp;
00163
00164 if (firstEls == NULL)
00165 return 0;
00166
00167 f = firstEls;
00168
00169 if (firstEls == lastEls)
00170 firstEls = lastEls = NULL;
00171 else
00172 firstEls = firstEls->next;
00173
00174 strncpy(cmd, f->text, IPCBUFSIZE);
00175 cmd[IPCBUFSIZE - 1] = '\0';
00176
00177 cp = cmd + strlen(cmd) - 1;
00178
00179 if (*cp == '\n' || *cp == '\r')
00180 *cp = '\0';
00181
00182 if ((cp - 1) > cmd && (cp[-1] == '\r' || cp[-1] == '\n'))
00183 cp[-1] = '\0';
00184
00185 free(f->text);
00186 free(f);
00187
00188 return 1;
00189 }
00190
00196 bool IsEmpty()
00197 {
00198 if (firstEls == NULL)
00199 return 1;
00200 return 0;
00201 }
00202
00207 void empty()
00208 {
00209 char cmd[1025];
00210
00211 while(pop(cmd))
00212 return;
00213 }
00214
00215 private:
00216 IpcQel *firstEls, *lastEls;
00217 };
00218
00219 enum sipc_obj_t
00220 {
00221 SIPC_UNDEF,
00222 SIPC_RNICK,
00223 SIPC_RCHAN,
00224 };
00225
00229 struct IpcConnectType
00230 {
00231 int fd;
00232 flag_t gpriv;
00233 flag_t opriv;
00234 struct in_addr addr;
00235 IpcQ buf;
00236 long cookie;
00237 long cookie_in;
00238
00239 char *user, *pass;
00240 char *objName, *objPass;
00241 enum sipc_obj_t objType;
00242 char s;
00243
00244 IpcConnectType *next;
00245
00246 void sWrite(const char *text);
00247 void fWrite(const char *text, ...);
00248 void fWriteLn(const char *text, ...);
00249 int sendAkills(int akillType, const char *searchText);
00250 flag_t GetPriv() {return gpriv;}
00251 int CheckPriv(flag_t pSys, flag_t pObj = 0);
00252 int CheckOrPriv(flag_t pSys, flag_t pObj = 0);
00253 };
00254
00260 class IpcType
00261 {
00262 public:
00263 int start(int portNum);
00264 void fdFillSet(fd_set &);
00265 int getListenfd() { return listenDesc; }
00266 int getTopfd() { return topFd; }
00267 void pollAndHandle(fd_set &read, fd_set &write, fd_set &except);
00268 void freeCon(IpcConnectType *);
00269 void addCon(IpcConnectType *);
00270 void delCon(IpcConnectType *);
00271
00272 IpcType() : listenDesc(-1), links(NULL) {}
00273 private:
00274 int ReadPackets(IpcConnectType *);
00275 void authMessage(IpcConnectType *, parse_t *);
00276 void authSysMessage(IpcConnectType *, parse_t *);
00277 void authObjMessage(IpcConnectType *, parse_t *);
00278 void queryMessage(IpcConnectType *, parse_t *);
00279 void querySysMessage(IpcConnectType *, parse_t *);
00280 void queryObjMessage(IpcConnectType *, parse_t *);
00281 int queryRegNickMessage(RegNickList *, const char *, IpcConnectType *, parse_t *);
00282 void makeMessage(IpcConnectType *, parse_t *);
00283 void alterMessage(IpcConnectType *, parse_t *);
00284 void logMessage(IpcConnectType *, parse_t *);
00285 void alterObjMessage(IpcConnectType *, parse_t *);
00286 int alterRegNickMessage(RegNickList *, const char *, IpcConnectType *, parse_t *);
00287
00288
00289 int listenDesc;
00290 int topFd;
00291 IpcConnectType *links;
00292 };