Changeset 7882a6f in code


Ignore:
Timestamp:
Mar 10, 2014, 12:13:22 PM (11 years ago)
Author:
Mike Belopuhov <mike@…>
Branches:
master
Children:
fe81e9a
Parents:
e80f9fc
Message:

Get rid of the icbd callbacks interface

I believe the idea was initially to have both icb and irc in one
daemon but that's not going to happen.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    re80f9fc r7882a6f  
    2626
    2727#include "icb.h"
     28#include "icbd.h"
    2829
    2930extern int creategroups;
     
    144145        icb_status(s, STATUS_BOOT, "%s booted you", is->nick);
    145146        icb_status_group(s->group, s, STATUS_BOOT, "%s was booted", s->nick);
    146         icb_drop(s, "booted");
     147        icbd_drop(s, "booted");
    147148}
    148149
     
    175176                                return;
    176177                        }
    177                         icb_log(NULL, LOG_DEBUG, "%s created group %s",
     178                        icbd_log(NULL, LOG_DEBUG, "%s created group %s",
    178179                            is->nick, group);
    179180                }
  • icb.c

    re80f9fc r7882a6f  
    4343 */
    4444void
    45 icb_init(struct icbd_callbacks *ic)
    46 {
    47         icb_drop = ic->drop;
    48         icb_log = ic->log;
    49         icb_send = ic->send;
    50 
     45icb_init(void)
     46{
    5147        LIST_INIT(&groups);
    5248
     
    9894                if (strlen(cmd) > 0 && cmd[0] == 'w') {
    9995                        icb_error(is, "Command not implemented");
    100                         icb_drop(is, NULL);
     96                        icbd_drop(is, NULL);
    10197                        return;
    10298                }
    10399                if (strlen(cmd) == 0 || strcmp(cmd, "login") != 0) {
    104100                        icb_error(is, "Malformed login packet");
    105                         icb_drop(is, NULL);
     101                        icbd_drop(is, NULL);
    106102                        return;
    107103                }
     
    152148            icb_vis(is->nick, nick, ICB_MAXNICKLEN, VIS_SP)) {
    153149                icb_error(is, "Invalid nick");
    154                 icb_drop(is, NULL);
     150                icbd_drop(is, NULL);
    155151                return;
    156152        }
     
    166162                if (!creategroups) {
    167163                        icb_error(is, "Invalid group %s", group);
    168                         icb_drop(is, NULL);
     164                        icbd_drop(is, NULL);
    169165                        return;
    170166                } else {
     
    173169                                return;
    174170                        }
    175                         icb_log(NULL, LOG_DEBUG, "%s created group %s",
     171                        icbd_log(NULL, LOG_DEBUG, "%s created group %s",
    176172                            is->nick, group);
    177173                }
     
    180176                if (strcmp(s->nick, is->nick) == 0) {
    181177                        icb_error(is, "Nick is already in use");
    182                         icb_drop(is, NULL);
     178                        icbd_drop(is, NULL);
    183179                        return;
    184180                }
     
    238234                if (s == is)
    239235                        continue;
    240                 icb_send(s, buf, buflen + 1);
     236                icbd_send(s, buf, buflen + 1);
    241237        }
    242238}
     
    321317                break;
    322318        default:
    323                 icb_log(is, LOG_ERR, "unknown cmdout type");
     319                icbd_log(is, LOG_ERR, "unknown cmdout type %d", type);
    324320                return;
    325321        }
     
    367363        buf[0] = buflen;
    368364        va_end(ap);
    369         icb_send(is, buf, buflen + 1);
     365        icbd_send(is, buf, buflen + 1);
    370366}
    371367
     
    390386        }
    391387        logger(ig->name, "", buf);
    392         icb_log(NULL, LOG_DEBUG, "%s", buf);
     388        icbd_log(NULL, LOG_DEBUG, "%s", buf);
    393389        va_end(ap);
    394390}
     
    409405        buf[0] = ++buflen; /* account for ICB_M_ERROR */
    410406        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);
    413409}
    414410
     
    620616        va_end(ap);
    621617        buf[0] = buflen;
    622         icb_send(is, buf, buflen + 1);
     618        icbd_send(is, buf, buflen + 1);
    623619}
    624620
  • icb.h

    re80f9fc r7882a6f  
    111111LIST_HEAD(icb_grlist, icb_group) groups;
    112112
    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 
    119113#ifndef nitems
    120114#define nitems(_a)      (sizeof((_a)) / sizeof((_a)[0]))
     
    122116
    123117/* cmd.c */
    124 void *icb_cmd_lookup(char *);
     118void *          icb_cmd_lookup(char *);
    125119
    126120/* icb.c */
     
    130124void            icb_delgroup(struct icb_group *);
    131125void            icb_error(struct icb_session *, const char *, ...);
    132 void            icb_init(struct icbd_callbacks *);
     126void            icb_init(void);
    133127void            icb_input(struct icb_session *);
    134128inline int      icb_ismod(struct icb_group *, struct icb_session *);
     
    145139void            icb_who(struct icb_session *, struct icb_group *);
    146140int             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  
    6565void icbd_grplist(char *);
    6666void icbd_restrict(void);
    67 void icbd_write(struct icb_session *, char *, ssize_t);
     67void icbd_send(struct icb_session *, char *, ssize_t);
    6868
    6969struct icbd_listener {
     
    7474main(int argc, char *argv[])
    7575{
    76         struct icbd_callbacks ic = { icbd_drop, icbd_log, icbd_write };
    7776        const char *cause = NULL;
    7877        int ch, nsocks = 0, save_errno = 0;
     
    8079
    8180        /* init group lists before calling icb_addgroup */
    82         icb_init(&ic);
     81        icb_init();
    8382
    8483        while ((ch = getopt(argc, argv, "46CdG:M:nL:S:v")) != -1)
     
    391390
    392391void
    393 icbd_write(struct icb_session *is, char *buf, ssize_t size)
     392icbd_send(struct icb_session *is, char *buf, ssize_t size)
    394393{
    395394        if (bufferevent_write(is->bev, buf, size) == -1)
  • icbd.h

    re80f9fc r7882a6f  
    2424
    2525/* icbd.c */
    26 inline struct icb_session *
    27                 icbd_session_lookup(uint64_t);
     26void            icbd_drop(struct icb_session *, char *);
     27void            icbd_log(struct icb_session *, int, const char *, ...);
     28void            icbd_send(struct icb_session *, char *, ssize_t);
    2829void            icbd_modupdate(void);
    2930time_t          getmonotime(void);
Note: See TracChangeset for help on using the changeset viewer.