Changeset dc96e6e
- Timestamp:
- 2015-09-11T02:31:10Z (9 years ago)
- Branches:
- master
- Children:
- b57fed0
- Parents:
- 0ef1c92
- git-author:
- dequis <dx@…> (28-07-15 04:48:49)
- git-committer:
- dequis <dx@…> (11-09-15 02:31:10)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
irc.h
r0ef1c92 rdc96e6e 103 103 104 104 struct bee *b; 105 guint32 caps; 105 106 } irc_t; 106 107 -
irc_commands.c
r0ef1c92 rdc96e6e 29 29 #include "ipc.h" 30 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 31 112 static void irc_cmd_cap(irc_t *irc, char **cmd) 32 113 { … … 38 119 if (g_strcasecmp(cmd[1], "LS") == 0) { 39 120 /* gboolean irc302 = (g_strcmp0(cmd[2], "302") == 0); */ 40 irc_send_cap(irc, "LS", ""); 121 //char *ls = g_strjoinv(" ", (char **) supported_caps); 122 123 irc_send_cap(irc, "LS", "foo bar"); 124 125 //g_free(ls); 41 126 42 127 } else if (g_strcasecmp(cmd[1], "LIST") == 0) { … … 44 129 45 130 } else if (g_strcasecmp(cmd[1], "REQ") == 0) { 46 irc_send_cap(irc, "NAK", cmd[2] ? : ""); 131 gboolean ack = irc_cmd_cap_req(irc, cmd[2]); 132 133 irc_send_cap(irc, ack ? "ACK" : "NAK", cmd[2] ? : ""); 47 134 48 135 } else if (g_strcasecmp(cmd[1], "END") == 0) {
Note: See TracChangeset
for help on using the changeset viewer.