Save NETWORK, CHANTYPES, PREFIX from ISUPPORT

master
C. McEnroe 2020-02-02 17:37:36 -05:00
parent b535f0abdd
commit 0d6a60cc66
3 changed files with 21 additions and 8 deletions

4
chat.c
View File

@ -80,6 +80,10 @@ int main(int argc, char *argv[]) {
if (!user) user = nick; if (!user) user = nick;
if (!real) real = nick; if (!real) real = nick;
set(&self.network, host);
set(&self.chanTypes, "#&");
set(&self.prefixes, "@+");
ircConfig(insecure, cert, priv); ircConfig(insecure, cert, priv);
uiInit(); uiInit();

11
chat.h
View File

@ -65,12 +65,21 @@ enum Cap {
extern struct Self { extern struct Self {
bool debug; bool debug;
char *plain;
const char *join; const char *join;
enum Cap caps; enum Cap caps;
char *plain; char *network;
char *chanTypes;
char *prefixes;
char *nick; char *nick;
} self; } self;
static inline void set(char **field, const char *value) {
free(*field);
*field = strdup(value);
if (!*field) err(EX_OSERR, "strdup");
}
#define ENUM_TAG \ #define ENUM_TAG \
X("time", TagTime) X("time", TagTime)

View File

@ -59,12 +59,6 @@ static const char *capList(enum Cap caps) {
return buf; return buf;
} }
static void set(char **field, const char *value) {
free(*field);
*field = strdup(value);
if (!*field) err(EX_OSERR, "strdup");
}
static void require(struct Message *msg, bool origin, size_t len) { static void require(struct Message *msg, bool origin, size_t len) {
if (origin) { if (origin) {
if (!msg->nick) errx(EX_PROTOCOL, "%s missing origin", msg->cmd); if (!msg->nick) errx(EX_PROTOCOL, "%s missing origin", msg->cmd);
@ -158,16 +152,22 @@ static void handleReplyWelcome(struct Message *msg) {
} }
static void handleReplyISupport(struct Message *msg) { static void handleReplyISupport(struct Message *msg) {
// TODO: Extract CHANTYPES and PREFIX for future use.
for (size_t i = 1; i < ParamCap; ++i) { for (size_t i = 1; i < ParamCap; ++i) {
if (!msg->params[i]) break; if (!msg->params[i]) break;
char *key = strsep(&msg->params[i], "="); char *key = strsep(&msg->params[i], "=");
if (!msg->params[i]) continue; if (!msg->params[i]) continue;
if (!strcmp(key, "NETWORK")) { if (!strcmp(key, "NETWORK")) {
set(&self.network, msg->params[i]);
uiFormat( uiFormat(
Network, Cold, tagTime(msg), Network, Cold, tagTime(msg),
"You arrive in %s", msg->params[i] "You arrive in %s", msg->params[i]
); );
} else if (!strcmp(key, "CHANTYPES")) {
set(&self.chanTypes, msg->params[i]);
} else if (!strcmp(key, "PREFIX")) {
strsep(&msg->params[i], ")");
if (!msg->params[i]) continue;
set(&self.prefixes, msg->params[i]);
} }
} }
} }