Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

sipc.h

Go to the documentation of this file.
00001 
00013 /*
00014  * Copyright (c) 2001 James Hess
00015  * All rights reserved.
00016  *
00017  * Redistribution and use in source and binary forms, with or without
00018  * modification, are permitted provided that the following conditions
00019  * are met:
00020  * 1. Redistributions of source code must retain the above copyright
00021  *    notice, this list of conditions and the following disclaimer.
00022  * 2. Redistributions in binary form must reproduce the above copyright
00023  *    notice, this list of conditions and the following disclaimer in the
00024  *    documentation and/or other materials provided with the distribution.
00025  * 3. Neither the name of the authors nor the names of its contributors
00026  *    may be used to endorse or promote products derived from this software
00027  *    without specific prior written permission.
00028  *
00029  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
00030  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00031  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00032  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
00033  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00034  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00035  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00036  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00037  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00038  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00039  * SUCH DAMAGE.
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 };

Generated at Sat Oct 25 20:56:09 2003 for Services using Doxygen.
Services Copyr. 1996-2001 Chip Norkus, Max Byrd, Greg Poma, Michael Graff, James Hess, Dafydd James. All rights reserved See LICENSE for licensing information.