Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle the TOPIC group of numerics

Includes the non-normative 331 RPL_X_TOPICWASSET
  • Loading branch information...
commit e7d13cf0848f416d2d2488d01c68c5253e219e3b 1 parent 7d4237b
Sound and Fury authored
Showing with 53 additions and 3 deletions.
  1. +46 −2 irc.c
  2. +7 −1 numeric.h
View
48 irc.c
@@ -132,7 +132,7 @@ int irc_rx(int fd, char ** data)
return(0);
}
-int irc_numeric(char *cmd, int b)
+int irc_numeric(char *cmd, int b) // TODO check the strtok()s for NULLs
{
int num=0;
char *ch;
@@ -173,7 +173,7 @@ int irc_numeric(char *cmd, int b)
{
bufs[b2].namreply=false;
char lmsg[32+strlen(ch)];
- sprintf(lmsg, "NAMES list received for %s\n", ch);
+ sprintf(lmsg, "NAMES list received for %s", ch);
buf_print(b2, c_status, lmsg, true);
}
}
@@ -189,6 +189,50 @@ int irc_numeric(char *cmd, int b)
if(strlen(motdline)>=skip) motdline+=skip;
buf_print(b, c_notice[1], motdline, true);
break;
+ case RPL_TOPIC: // 332 dest <channel> :<topic>
+ ch=strtok(NULL, " "); // channel
+ char *topic=strtok(NULL, "")+1;
+ for(b2=0;b2<nbufs;b2++)
+ {
+ if((bufs[b2].server==b) && (bufs[b2].type==CHANNEL) && (strcasecmp(ch, bufs[b2].bname)==0))
+ {
+ char tmsg[32+strlen(ch)+strlen(topic)];
+ sprintf(tmsg, "Topic for %s is %s", ch, topic);
+ buf_print(b2, c_notice[1], tmsg, true);
+ }
+ }
+ break;
+ case RPL_NOTOPIC: // 331 dest <channel> :No topic is set
+ ch=strtok(NULL, " "); // channel
+ for(b2=0;b2<nbufs;b2++)
+ {
+ if((bufs[b2].server==b) && (bufs[b2].type==CHANNEL) && (strcasecmp(ch, bufs[b2].bname)==0))
+ {
+ char tmsg[32+strlen(ch)];
+ sprintf(tmsg, "No topic is set for %s", ch);
+ buf_print(b2, c_notice[1], tmsg, true);
+ }
+ }
+ break;
+ case RPL_X_TOPICWASSET: // 331 dest <channel> <nick> <time>
+ ch=strtok(NULL, " "); // channel
+ char *nick=strtok(NULL, " "); // by whom?
+ char *time=strtok(NULL, ""); // when?
+ for(b2=0;b2<nbufs;b2++)
+ {
+ if((bufs[b2].server==b) && (bufs[b2].type==CHANNEL) && (strcasecmp(ch, bufs[b2].bname)==0))
+ {
+ time_t when;
+ sscanf(time, "%u", (unsigned int *)&when);
+ char ts[256];
+ struct tm *tm = gmtime(&when);
+ size_t tslen = strftime(ts, sizeof(ts), "%H:%M:%S GMT on %a, %d %b %Y", tm); // TODO options controlling date format (eg. ISO 8601)
+ char tmsg[32+strlen(nick)+tslen];
+ sprintf(tmsg, "Topic was set by %s at %s", nick, ts);
+ buf_print(b2, c_status, tmsg, true);
+ }
+ }
+ break;
default:
;
char *rest=strtok(NULL, "");
View
8 numeric.h
@@ -6,6 +6,11 @@
numeric: IRC numeric replies
*/
+/*
+ A symbolic name defined here does not necessarily imply recognition or decoding of that numeric reply.
+ Some numeric replies are non-normative; that is, they are not defined in the original RFC1459, but instead are either defined in later RFCs (1459 is still the standard at time of writing) or are entirely experimental. These are denoted with an X before the name (of the form RPL_X_BOGOSITY); where a numeric is being identified purely on the basis of usage "in the wild", the symbolic name will be completely arbitrary and may not align with usage elsewhere.
+*/
+
/* Error replies */
#define ERR_NOSUCHNICK 401 // "<nickname> :No such nick/channel" Used to indicate the nickname parameter supplied to a command is currently unused.
#define ERR_NOSUCHSERVER 402 // "<server name> :No such server" Used to indicate the server name given currently doesn't exist.
@@ -73,7 +78,8 @@
#define RPL_LISTEND 323 // ":End of /LIST" Replies RPL_LISTSTART, RPL_LIST, RPL_LISTEND mark the start, actual replies with data and end of the server's response to a LIST command. If there are no channels available to return, only the start and end reply must be sent.
#define RPL_CHANNELMODEIS 324 // "<channel> <mode> <mode params>"
#define RPL_NOTOPIC 331 // "<channel> :No topic is set"
-#define RPL_TOPIC 332 // "<channel> :<topic>" When sending a TOPIC message to determine the channel topic, one of two replies is sent. If the topic is set, RPL_TOPIC is sent back else RPL_NOTOPIC.
+#define RPL_TOPIC 332 // "<channel> :<topic>" When sending a TOPIC message to determine the channel topic, one of two replies is sent. If the topic is set, RPL_TOPIC is sent back else RPL_NOTOPIC.
+#define RPL_X_TOPICWASSET 333 // "<channel> <nick> <time>" Indicates who set the TOPIC, and when. Not normative.
#define RPL_INVITING 341 // "<channel> <nick>" Returned by the server to indicate that the attempted INVITE message was successful and is being passed onto the end client.
#define RPL_SUMMONING 342 // "<user> :Summoning user to IRC" Returned by a server answering a SUMMON message to indicate that it is summoning that user.
#define RPL_VERSION 351 // "<version>.<debuglevel> <server> :<comments>" Reply by the server showing its version details. The <version> is the version of the software being used (including any patchlevel revisions) and the <debuglevel> is used to indicate if the server is running in "debug mode". The "comments" field may contain any comments about the version or further version details.
Please sign in to comment.
Something went wrong with that request. Please try again.