* the source (parv[0]) is a server.
*/
static void
-m_perform(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *notused)
+m_perform(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
node_t *node;
* the source (parv[0]) is a server.
*/
static void
-m_ping(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *source_p)
+m_ping(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
if (parc < 3)
return;
* the source (parv[0]) is a server.
*/
static void
-m_invite(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *source_p)
+m_invite(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
const struct ChannelConf *channel = NULL;
* the source (parv[0]) is a server.
*/
static void
-m_ctcp(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *source_p)
+m_ctcp(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
if (strncasecmp(parv[3], "\001VERSION\001", 9) == 0)
irc_send("NOTICE %s :\001VERSION Hybrid Open Proxy Monitor %s(%s)\001",
- source_p->irc_nick, VERSION, SERIALNUM);
+ source_p, VERSION, SERIALNUM);
}
/* m_privmsg
* the source (parv[0]) is a server.
*/
static void
-m_privmsg(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *source_p)
+m_privmsg(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
const struct ChannelConf *channel = NULL;
size_t nick_len;
* the source (parv[0]) is a server.
*/
static void
-m_notice(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *source_p)
+m_notice(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
static regex_t *preg = NULL;
regmatch_t pmatch[5];
* the source (parv[0]) is a server.
*/
static void
-m_userhost(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *source_p)
+m_userhost(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
if (parc < 4)
return;
* parv[4] = error text
*/
static void
-m_cannot_join(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *source_p)
+m_cannot_join(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
const struct ChannelConf *channel = NULL;
* parv[4] = error text
*/
static void
-m_kill(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *source_p)
+m_kill(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
/* Restart hopm to rehash */
main_restart();
* Return:
* pointer to new UserInfo struct, or NULL if parsing failed
*/
-static struct UserInfo *
+static const char *
userinfo_create(const char *source)
{
- struct UserInfo *ret;
- char tmp[MSGLENMAX];
- char *nick = tmp;
- char *username = NULL;
- char *hostname = NULL;
+ static char name[MSGLENMAX];
+ unsigned int has_user = 0;
+ unsigned int has_host = 0;
- strlcpy(tmp, source, sizeof(tmp));
+ strlcpy(name, source, sizeof(name));
- for (char *p = tmp; *p; ++p)
+ for (char *p = name; *p; ++p)
{
if (*p == '!')
{
*p = '\0';
- username = p + 1;
+ ++has_user;
continue;
}
- if (*p == '@')
+ if (*p == '@' && has_user)
{
- *p = '\0';
- hostname = p + 1;
+ ++has_host;
continue;
}
}
- if (username == NULL || hostname == NULL)
- return NULL;
-
- ret = xcalloc(sizeof(*ret));
- ret->irc_nick = xstrdup(nick);
- ret->irc_username = xstrdup(username);
- ret->irc_hostname = xstrdup(hostname);
-
- return ret;
+ if (has_user == 1 && has_host == 1)
+ return name;
+ return NULL;
};
-/* userinfo_free
- *
- * Free a UserInfo struct created with userinfo_create.
- *
- * Parameters:
- * source: struct to free
- *
- * Return: None
- */
-static void
-userinfo_free(struct UserInfo *source_p)
-{
- if (source_p == NULL)
- return;
-
- xfree(source_p->irc_nick);
- xfree(source_p->irc_username);
- xfree(source_p->irc_hostname);
- xfree(source_p);
-}
-
/* irc_init
*
* Resolve IRC host and perform other initialization.
{
if (strcasecmp(cmd->command, parv[1]) == 0)
{
- /* Generate a UserInfo struct from the source */
- struct UserInfo *source_p = userinfo_create(parv[0]);
-
- cmd->handler(parv, parc, msg, source_p);
- userinfo_free(source_p);
+ cmd->handler(parv, parc, msg, userinfo_create(parv[0]));
break;
}
}
* Pointer to new Command
*/
static struct Command *
-command_create(const struct OperCommandHash *tab, char *param, char *irc_nick,
+command_create(const struct OperCommandHash *tab, char *param, const char *irc_nick,
const struct ChannelConf *target)
{
struct Command *command = xcalloc(sizeof(*command));
*
*/
void
-command_parse(char *command, const struct ChannelConf *target,
- const struct UserInfo *source_p)
+command_parse(char *command, const struct ChannelConf *target, const char *source_p)
{
char *param; /* Parsed parameters */
static const struct OperCommandHash COMMAND_TABLE[] =
if (OPT_DEBUG)
log_printf("COMMAND -> Parsing command (%s) from %s [%s]", command,
- source_p->irc_nick, target->name);
+ source_p, target->name);
/* Only allow COMMANDMAX commands in the queue */
if (LIST_SIZE(&COMMANDS) >= COMMANDMAX)
if (strcasecmp(command, tab->command) == 0)
{
/* Queue this command */
- struct Command *cmd = command_create(tab, param, source_p->irc_nick, target);
+ struct Command *cmd = command_create(tab, param, source_p, target);
list_add(&COMMANDS, node_create(cmd));
break;
}
}
- irc_send("USERHOST %s", source_p->irc_nick);
+ irc_send("USERHOST %s", source_p);
}
/* command_timer