Changeset 355e2ad
- Timestamp:
- 2015-10-01T01:01:48Z (9 years ago)
- Branches:
- master
- Children:
- 3cbf71d
- Parents:
- d797fb4
- git-author:
- dequis <dx@…> (18-08-15 05:53:17)
- git-committer:
- dequis <dx@…> (01-10-15 01:01:48)
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
rd797fb4 r355e2ad 10 10 11 11 # Program variables 12 objects = bitlbee.o dcc.o help.o ipc.o irc.o irc_im.o irc_c hannel.o irc_commands.o irc_send.o irc_user.o irc_util.o nick.o $(OTR_BI) query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o conf.o log.o12 objects = bitlbee.o dcc.o help.o ipc.o irc.o irc_im.o irc_cap.o irc_channel.o irc_commands.o irc_send.o irc_user.o irc_util.o nick.o $(OTR_BI) query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o conf.o log.o 13 13 headers = $(wildcard $(_SRCDIR_)*.h $(_SRCDIR_)lib/*.h $(_SRCDIR_)protocols/*.h) 14 14 subdirs = lib protocols -
irc.h
rd797fb4 r355e2ad 65 65 IRC_UTF8_NICKS = 0x10000, /* Disable ASCII restrictions on buddy nicks. */ 66 66 } irc_status_t; 67 68 typedef enum { 69 CAP_FOO = (1 << 0), 70 CAP_BAR = (1 << 1), 71 } irc_cap_flag_t; 67 72 68 73 struct irc_user; … … 352 357 void bee_irc_user_nick_reset(irc_user_t *iu); 353 358 359 /* irc_cap.c */ 360 void irc_cmd_cap(irc_t *irc, char **cmd); 361 354 362 #endif -
irc_commands.c
rd797fb4 r355e2ad 28 28 #include "help.h" 29 29 #include "ipc.h" 30 31 typedef guint32 cap_flag; /* 32 bits ought to be enough for anybody */32 33 typedef struct _cap_info {34 char *name;35 cap_flag flag;36 } cap_info_t;37 38 #define CAP_FOO (1 << 0)39 #define CAP_BAR (1 << 1)40 41 static const cap_info_t supported_caps[] = {42 {"foo", CAP_FOO},43 {"bar", CAP_BAR},44 {NULL},45 };46 47 static cap_flag cap_flag_from_string(char *cap_name) {48 int i;49 50 if (!cap_name && !cap_name[0]) {51 return 0;52 }53 54 if (cap_name[0] == '-') {55 cap_name++;56 }57 58 for (i = 0; supported_caps[i].name; i++) {59 if (strcmp(supported_caps[i].name, cap_name) == 0) {60 return supported_caps[i].flag;61 }62 }63 return 0;64 }65 66 static gboolean irc_cmd_cap_req(irc_t *irc, char *caps)67 {68 int i;69 char *lower = NULL;70 char **split = NULL;71 cap_flag new_caps = irc->caps;72 73 if (!caps || !caps[0]) {74 return FALSE;75 }76 77 lower = g_ascii_strdown(caps, -1);78 split = g_strsplit(lower, " ", -1);79 g_free(lower);80 81 for (i = 0; split[i]; i++) {82 gboolean remove;83 cap_flag flag;84 85 if (!split[i][0]) {86 continue; /* skip empty items (consecutive spaces) */87 }88 89 remove = (split[i][0] == '-');90 flag = cap_flag_from_string(split[i]);91 92 if (!flag || (remove && !(irc->caps & flag))) {93 /* unsupported cap, or removing something that isn't there */94 g_strfreev(split);95 return FALSE;96 }97 98 if (remove) {99 new_caps &= ~flag;100 } else {101 new_caps |= flag;102 }103 }104 105 /* if we got here, set the new caps and ack */106 irc->caps = new_caps;107 108 g_strfreev(split);109 return TRUE;110 }111 112 /* version can be "302" or NULL, but we don't need cap-3.2 for anything yet */113 static void irc_cmd_cap_ls(irc_t *irc, char *version) {114 int i;115 GString *str = g_string_sized_new(256);116 117 for (i = 0; supported_caps[i].name; i++) {118 if (i != 0) {119 g_string_append_c(str, ' ');120 }121 g_string_append(str, supported_caps[i].name);122 }123 124 irc_send_cap(irc, "LS", str->str);125 126 g_string_free(str, TRUE);127 }128 129 /* this one looks suspiciously similar to cap ls,130 * but cap-3.2 will make them very different */131 static void irc_cmd_cap_list(irc_t *irc) {132 int i;133 gboolean first = TRUE;134 GString *str = g_string_sized_new(256);135 136 for (i = 0; supported_caps[i].name; i++) {137 if (irc->caps & supported_caps[i].flag) {138 if (!first) {139 g_string_append_c(str, ' ');140 }141 first = FALSE;142 143 g_string_append(str, supported_caps[i].name);144 }145 }146 147 irc_send_cap(irc, "LIST", str->str);148 149 g_string_free(str, TRUE);150 }151 152 static void irc_cmd_cap(irc_t *irc, char **cmd)153 {154 if (!(irc->status & USTATUS_LOGGED_IN)) {155 /* Put registration on hold until CAP END */156 irc->status |= USTATUS_CAP_PENDING;157 }158 159 if (g_strcasecmp(cmd[1], "LS") == 0) {160 irc_cmd_cap_ls(irc, cmd[2]);161 162 } else if (g_strcasecmp(cmd[1], "LIST") == 0) {163 irc_cmd_cap_list(irc);164 165 } else if (g_strcasecmp(cmd[1], "REQ") == 0) {166 gboolean ack = irc_cmd_cap_req(irc, cmd[2]);167 168 irc_send_cap(irc, ack ? "ACK" : "NAK", cmd[2] ? : "");169 170 } else if (g_strcasecmp(cmd[1], "END") == 0) {171 irc->status &= ~USTATUS_CAP_PENDING;172 irc_check_login(irc);173 174 } else {175 irc_send_num(irc, 410, "%s :Invalid CAP command", cmd[1]);176 }177 178 }179 30 180 31 static void irc_cmd_pass(irc_t *irc, char **cmd) -
tests/Makefile
rd797fb4 r355e2ad 15 15 distclean: clean 16 16 17 main_objs = bitlbee.o conf.o dcc.o help.o ipc.o irc.o irc_c hannel.o irc_commands.o irc_im.o irc_send.o irc_user.o irc_util.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_xml.o17 main_objs = bitlbee.o conf.o dcc.o help.o ipc.o irc.o irc_cap.o irc_channel.o irc_commands.o irc_im.o irc_send.o irc_user.o irc_util.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_xml.o 18 18 19 19 test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_set.o check_jabber_sasl.o check_jabber_util.o
Note: See TracChangeset
for help on using the changeset viewer.