- Change userinfo_create() to not always allocate memory for each user message; impro...
authormichael <michael@82007160-df01-0410-b94d-b575c5fd34c7>
Thu, 25 Jun 2015 14:36:47 +0000 (14:36 +0000)
committermichael <michael@82007160-df01-0410-b94d-b575c5fd34c7>
Thu, 25 Jun 2015 14:36:47 +0000 (14:36 +0000)
- Remove now unused userinfo_free()

git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/trunk@6198 82007160-df01-0410-b94d-b575c5fd34c7

src/irc.c
src/irc.h
src/opercmd.c
src/opercmd.h

index 2cf51bd8945ceb96ec6eaf77bacab113afb6b7f9..d35a14c16479c0394ad29a743c248331bc73ab56 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -106,7 +106,7 @@ get_channel(const char *channel)
  * 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;
 
@@ -155,7 +155,7 @@ m_perform(char *parv[], unsigned int parc, const char *msg, const struct UserInf
  * 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;
@@ -177,7 +177,7 @@ m_ping(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *
  * 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;
 
@@ -202,11 +202,11 @@ m_invite(char *parv[], unsigned int parc, const char *msg, const struct UserInfo
  * 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
@@ -220,7 +220,7 @@ m_ctcp(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *
  * 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;
@@ -273,7 +273,7 @@ m_privmsg(char *parv[], unsigned int parc, const char *msg, const struct UserInf
  * 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];
@@ -359,7 +359,7 @@ m_notice(char *parv[], unsigned int parc, const char *msg, const struct UserInfo
  * 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;
@@ -376,7 +376,7 @@ m_userhost(char *parv[], unsigned int parc, const char *msg, const struct UserIn
  * 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;
 
@@ -402,7 +402,7 @@ m_cannot_join(char *parv[], unsigned int parc, const char *msg, const struct Use
  * 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();
@@ -419,66 +419,36 @@ m_kill(char *parv[], unsigned int parc, const char *msg, const struct UserInfo *
  * 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.
@@ -732,11 +702,7 @@ irc_parse(void)
   {
     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;
     }
   }
index eba28c4578a99a22a07f2ebc485b5616f888c904..2ed1bb4d124937d2f3e25381304fdb94d365de16 100644 (file)
--- a/src/irc.h
+++ b/src/irc.h
 #define MSGLENMAX 512 + 1
 
 
-struct UserInfo
-{
-  char *irc_nick;
-  char *irc_username;
-  char *irc_hostname;
-};
-
 struct CommandHash
 {
   const char *command;
-  void (*handler)(char *[], unsigned int, const char *, const struct UserInfo *);
+  void (*handler)(char *[], unsigned int, const char *, const char *);
 };
 
 extern void irc_send(const char *, ...);
index ed9e9c3477dfe9a52735daad19b9098119bc9faf..4fef20da3d00c6e5b7a9da4e856163ebe4c39451 100644 (file)
@@ -115,7 +115,7 @@ cmd_protocols(char *param, const struct ChannelConf *target)
  *    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));
@@ -165,8 +165,7 @@ command_free(struct Command *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[] =
@@ -181,7 +180,7 @@ command_parse(char *command, const struct ChannelConf *target,
 
   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)
@@ -223,14 +222,14 @@ command_parse(char *command, const struct ChannelConf *target,
     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
index f8d4a90150495a631b7bbb5d6801d4c7d4e806d5..622b3a847331edaf4506d7586a24634565f8be1c 100644 (file)
@@ -56,5 +56,5 @@ struct Command
 extern void command_init(void);
 extern void command_userhost(const char *);
 extern void command_timer(void);
-extern void command_parse(char *, const struct ChannelConf *, const struct UserInfo *);
+extern void command_parse(char *, const struct ChannelConf *, const char *);
 #endif