Changeset 7882a6f in code
- Timestamp:
- Mar 10, 2014, 12:13:22 PM (11 years ago)
- Branches:
- master
- Children:
- fe81e9a
- Parents:
- e80f9fc
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cmd.c
re80f9fc r7882a6f 26 26 27 27 #include "icb.h" 28 #include "icbd.h" 28 29 29 30 extern int creategroups; … … 144 145 icb_status(s, STATUS_BOOT, "%s booted you", is->nick); 145 146 icb_status_group(s->group, s, STATUS_BOOT, "%s was booted", s->nick); 146 icb _drop(s, "booted");147 icbd_drop(s, "booted"); 147 148 } 148 149 … … 175 176 return; 176 177 } 177 icb _log(NULL, LOG_DEBUG, "%s created group %s",178 icbd_log(NULL, LOG_DEBUG, "%s created group %s", 178 179 is->nick, group); 179 180 } -
icb.c
re80f9fc r7882a6f 43 43 */ 44 44 void 45 icb_init(struct icbd_callbacks *ic) 46 { 47 icb_drop = ic->drop; 48 icb_log = ic->log; 49 icb_send = ic->send; 50 45 icb_init(void) 46 { 51 47 LIST_INIT(&groups); 52 48 … … 98 94 if (strlen(cmd) > 0 && cmd[0] == 'w') { 99 95 icb_error(is, "Command not implemented"); 100 icb _drop(is, NULL);96 icbd_drop(is, NULL); 101 97 return; 102 98 } 103 99 if (strlen(cmd) == 0 || strcmp(cmd, "login") != 0) { 104 100 icb_error(is, "Malformed login packet"); 105 icb _drop(is, NULL);101 icbd_drop(is, NULL); 106 102 return; 107 103 } … … 152 148 icb_vis(is->nick, nick, ICB_MAXNICKLEN, VIS_SP)) { 153 149 icb_error(is, "Invalid nick"); 154 icb _drop(is, NULL);150 icbd_drop(is, NULL); 155 151 return; 156 152 } … … 166 162 if (!creategroups) { 167 163 icb_error(is, "Invalid group %s", group); 168 icb _drop(is, NULL);164 icbd_drop(is, NULL); 169 165 return; 170 166 } else { … … 173 169 return; 174 170 } 175 icb _log(NULL, LOG_DEBUG, "%s created group %s",171 icbd_log(NULL, LOG_DEBUG, "%s created group %s", 176 172 is->nick, group); 177 173 } … … 180 176 if (strcmp(s->nick, is->nick) == 0) { 181 177 icb_error(is, "Nick is already in use"); 182 icb _drop(is, NULL);178 icbd_drop(is, NULL); 183 179 return; 184 180 } … … 238 234 if (s == is) 239 235 continue; 240 icb _send(s, buf, buflen + 1);236 icbd_send(s, buf, buflen + 1); 241 237 } 242 238 } … … 321 317 break; 322 318 default: 323 icb _log(is, LOG_ERR, "unknown cmdout type");319 icbd_log(is, LOG_ERR, "unknown cmdout type %d", type); 324 320 return; 325 321 } … … 367 363 buf[0] = buflen; 368 364 va_end(ap); 369 icb _send(is, buf, buflen + 1);365 icbd_send(is, buf, buflen + 1); 370 366 } 371 367 … … 390 386 } 391 387 logger(ig->name, "", buf); 392 icb _log(NULL, LOG_DEBUG, "%s", buf);388 icbd_log(NULL, LOG_DEBUG, "%s", buf); 393 389 va_end(ap); 394 390 } … … 409 405 buf[0] = ++buflen; /* account for ICB_M_ERROR */ 410 406 buf[1] = ICB_M_ERROR; 411 icb _send(is, buf, buflen + 1);412 icb _log(is, LOG_DEBUG, "%s", buf + 2);407 icbd_send(is, buf, buflen + 1); 408 icbd_log(is, LOG_DEBUG, "%s", buf + 2); 413 409 } 414 410 … … 620 616 va_end(ap); 621 617 buf[0] = buflen; 622 icb _send(is, buf, buflen + 1);618 icbd_send(is, buf, buflen + 1); 623 619 } 624 620 -
icb.h
re80f9fc r7882a6f 111 111 LIST_HEAD(icb_grlist, icb_group) groups; 112 112 113 struct icbd_callbacks {114 void (*drop)(struct icb_session *, char *);115 void (*log)(struct icb_session *, int, const char *, ...);116 void (*send)(struct icb_session *, char *, ssize_t);117 };118 119 113 #ifndef nitems 120 114 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) … … 122 116 123 117 /* cmd.c */ 124 void * icb_cmd_lookup(char *);118 void * icb_cmd_lookup(char *); 125 119 126 120 /* icb.c */ … … 130 124 void icb_delgroup(struct icb_group *); 131 125 void icb_error(struct icb_session *, const char *, ...); 132 void icb_init( struct icbd_callbacks *);126 void icb_init(void); 133 127 void icb_input(struct icb_session *); 134 128 inline int icb_ismod(struct icb_group *, struct icb_session *); … … 145 139 void icb_who(struct icb_session *, struct icb_group *); 146 140 int icb_vis(char *, const char *, size_t, int); 147 148 /* callbacks from icbd.c */149 void (*icb_drop)(struct icb_session *, char *);150 void (*icb_log)(struct icb_session *, int, const char *, ...);151 void (*icb_send)(struct icb_session *, char *, ssize_t); -
icbd.c
re80f9fc r7882a6f 65 65 void icbd_grplist(char *); 66 66 void icbd_restrict(void); 67 void icbd_ write(struct icb_session *, char *, ssize_t);67 void icbd_send(struct icb_session *, char *, ssize_t); 68 68 69 69 struct icbd_listener { … … 74 74 main(int argc, char *argv[]) 75 75 { 76 struct icbd_callbacks ic = { icbd_drop, icbd_log, icbd_write };77 76 const char *cause = NULL; 78 77 int ch, nsocks = 0, save_errno = 0; … … 80 79 81 80 /* init group lists before calling icb_addgroup */ 82 icb_init( &ic);81 icb_init(); 83 82 84 83 while ((ch = getopt(argc, argv, "46CdG:M:nL:S:v")) != -1) … … 391 390 392 391 void 393 icbd_ write(struct icb_session *is, char *buf, ssize_t size)392 icbd_send(struct icb_session *is, char *buf, ssize_t size) 394 393 { 395 394 if (bufferevent_write(is->bev, buf, size) == -1) -
icbd.h
re80f9fc r7882a6f 24 24 25 25 /* icbd.c */ 26 inline struct icb_session * 27 icbd_session_lookup(uint64_t); 26 void icbd_drop(struct icb_session *, char *); 27 void icbd_log(struct icb_session *, int, const char *, ...); 28 void icbd_send(struct icb_session *, char *, ssize_t); 28 29 void icbd_modupdate(void); 29 30 time_t getmonotime(void);
Note:
See TracChangeset
for help on using the changeset viewer.