solanum-vs-hackint-and-char.../ircd/msgbuf.c

114 lines
2.3 KiB
C
Raw Normal View History

2016-02-10 06:08:58 +00:00
/*
* charybdis - an advanced ircd.
* Copyright (c) 2016 William Pitcock <nenolod@dereferenced.org>.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdinc.h"
#include "ircd_defs.h"
#include "msgbuf.h"
/*
* parse a message into a MsgBuf.
* returns 0 on success, 1 on error.
*/
int
msgbuf_parse(struct MsgBuf *msgbuf, char *line)
{
char *ch;
char *parv[MAXPARA];
size_t n_para;
int i;
/* skip any leading spaces */
for (ch = line; *ch && *ch == ' '; ch++)
;
msgbuf_init(msgbuf);
if (*ch == '@')
{
char *t = ch + 1;
2016-02-10 06:08:58 +00:00
ch = strchr(ch, ' ');
if (ch != NULL)
{
2016-02-10 06:46:32 +00:00
while (1)
2016-02-10 06:08:58 +00:00
{
char *next = strchr(t, ';');
char *eq = strchr(t, '=');
if (next != NULL)
{
2016-02-10 06:08:58 +00:00
*next = '\0';
if (eq > next)
eq = NULL;
}
2016-02-10 06:08:58 +00:00
if (eq != NULL)
*eq++ = '\0';
2016-02-10 06:08:58 +00:00
if (*t && *t != ' ')
msgbuf_append_tag(msgbuf, t, eq, 0);
else
break;
2016-02-10 06:46:32 +00:00
if (next != NULL)
t = next + 1;
else
break;
2016-02-10 06:08:58 +00:00
}
*ch++ = '\0';
2016-02-10 06:08:58 +00:00
}
}
/* skip any whitespace between tags and origin */
for (; *ch && *ch == ' '; ch++)
;
if (*ch == ':')
{
ch++;
msgbuf->origin = ch;
char *end = strchr(ch, ' ');
if (end == NULL)
return 1;
*end = '\0';
for (ch = end + 1; *ch && *ch == ' '; ch++)
;
}
if (*ch == '\0')
return 1;
n_para = rb_string_to_array(ch, parv, MAXPARA);
if (n_para == 0)
return 1;
msgbuf->cmd = parv[0];
2016-02-10 06:46:32 +00:00
for (i = 0; i < n_para; i++)
2016-02-10 06:08:58 +00:00
msgbuf_append_para(msgbuf, parv[i]);
return 0;
}