Add IRCv3 tags parsing, fix parsing
This commit is contained in:
parent
8a3a4c9912
commit
17821f54be
|
@ -20,14 +20,23 @@
|
|||
#define UIRC_INCUDED
|
||||
|
||||
struct irc_message {
|
||||
signed short cmd;
|
||||
char* args[14];
|
||||
unsigned int argc;
|
||||
struct tags {
|
||||
/* See https://ircv3.net/registry#tags for more information */
|
||||
char* account;
|
||||
char* batch;
|
||||
char* label;
|
||||
char* msgid;
|
||||
char* multiline_concat; /* NOTE: Still a draft */
|
||||
char* time;
|
||||
} tags;
|
||||
struct source {
|
||||
char* nick;
|
||||
char* user;
|
||||
char* host;
|
||||
} source;
|
||||
signed short cmd;
|
||||
char* args[14];
|
||||
unsigned int argc;
|
||||
char* msg;
|
||||
};
|
||||
|
||||
|
|
36
src/uirc.c
36
src/uirc.c
|
@ -61,18 +61,46 @@ const char* uirc_ircmd[] = {
|
|||
int uirc_tokenize_message(struct irc_message* irc_msg, char* line)
|
||||
{
|
||||
char *progr, *command;
|
||||
progr = line; /* Set progress to starting point */
|
||||
progr = line;
|
||||
|
||||
if (*progr == '@') {
|
||||
char* tags;
|
||||
if ((tags = strtok_r(progr + 1, " ", &progr)) != NULL) {
|
||||
char *ctag = tags, *cval;
|
||||
do {
|
||||
if ((cval = strchr(ctag, '=')) != NULL) {
|
||||
*(cval++) = '\0';
|
||||
if (!strcmp(ctag, "time")) {
|
||||
irc_msg->tags.time = cval;
|
||||
} else if (!strcmp(ctag, "account")) {
|
||||
irc_msg->tags.account = cval;
|
||||
} else if (!strcmp(ctag, "batch")) {
|
||||
irc_msg->tags.batch = cval;
|
||||
} else if (!strcmp(ctag, "label")) {
|
||||
irc_msg->tags.label = cval;
|
||||
} else if (!strcmp(ctag, "msgid")) {
|
||||
irc_msg->tags.msgid = cval;
|
||||
} else if (!strcmp(ctag, "multiline-concat")) {
|
||||
irc_msg->tags.multiline_concat = cval;
|
||||
}
|
||||
if ((ctag = strchr(cval, ';')) != NULL)
|
||||
*(ctag++) = '\0';
|
||||
}
|
||||
} while (ctag != NULL);
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
if (*progr == ':') {
|
||||
char* prefix;
|
||||
if ((prefix = strtok_r(progr, " ", &progr) + 1) != NULL) {
|
||||
if ((prefix = strtok_r(progr + 1, " ", &progr)) != NULL) {
|
||||
if ((irc_msg->source.host = strchr(prefix, '@')) != NULL) {
|
||||
*(irc_msg->source.host++) = '\0';
|
||||
if ((irc_msg->source.user = strchr(prefix, '!')) != NULL)
|
||||
*(irc_msg->source.user++) = '\0';
|
||||
}
|
||||
irc_msg->source.nick = prefix;
|
||||
}
|
||||
irc_msg->source.nick = prefix; /* NOTE: This may be the server instead of a nick according to RFC2812, it is left to the library user to decide how to interpret this based on the context. */
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
command = strtok_r(progr, " ", &progr);
|
||||
|
|
|
@ -16,10 +16,7 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "../include/uirc.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
Reference in New Issue