Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

MikeWalkerMRU May 21st, 2020 1,063 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX_PARAMS 15
  5. #define MAX_MESSAGE 512
  6.  
  7. char *g_messages[] = {
  8.     "NOTICE AUTH :*** Processing connection to irc.servercentral.net\r\n"
  9.     "PING :irc.servercentral.net \r\n",
  10.     ":irc.servercentral.net 372 {manpage} :- -  \r\n",
  11.     ":irc.servercentral.net 376 {manpage} :End of /MOTD command.\r\n",
  12.     ":{manpage}!~bot@d23-16-195-6.bchsia.telus.net JOIN :#c-test\r\n",
  13.     ":irc.servercentral.net 353 {manpage} = #c-test :{manpage} tofu1\r\n",
  14.     ":irc.servercentral.net 366 {manpage} #c-test :End of /NAMES list.\r\n",
  15.     ":tofu1!~tofu@rootstorm.com PRIVMSG #c-test :test\r\n",
  16.     ":tofu1!~tofu@rootstorm.com PRIVMSG {manpage} :message test\r\n",
  17.     ":tofu1!~tofu@rootstorm.com PRIVMSG {manpage} :PING 1590092030 937335\r\n",
  18.     ":tofu1!~tofu@rootstorm.com PRIVMSG {manpage} :VERSION\r\n",
  19.     NULL,
  20. };
  21.  
  22. typedef struct _IRC_MESSAGE_FIELDS
  23. {
  24.     char *message;
  25.     char *trailing;
  26.     char *prefix;
  27.     char *command;
  28.     char *params[MAX_PARAMS + 1];
  29. } IRC_MESSAGE_FIELDS;
  30.  
  31. void *ParseMessage(char *str, IRC_MESSAGE_FIELDS *msg);
  32. void *ParsePrefix(char *str, IRC_MESSAGE_FIELDS *msg);
  33. void *ParseCommand(char *str, IRC_MESSAGE_FIELDS *msg);
  34. void *ParseParams(char *str, IRC_MESSAGE_FIELDS *msg);
  35.  
  36. int main(int argc, char **argv)
  37. {
  38.     IRC_MESSAGE_FIELDS msg;
  39.     char *no_prefix = strdup("PING :irc.servercentral.net \r\n");
  40.     char *prefix = strdup("::dude\\!~man@fe80::2 PRIVMSG {manpage} :message test\r\n");
  41.  
  42.     // ParseMessage(no_prefix, &msg);
  43.     ParseMessage(prefix, &msg);
  44.  
  45.     puts(msg.message);
  46.     if (msg.prefix != NULL)
  47.         printf("prefix: %s\n", msg.prefix);
  48.     else
  49.         printf("prefix: NULL\n");
  50.     printf("command: %s\n", msg.command);
  51.  
  52.     printf("params: {\n");
  53.     for (int i = 0; msg.params[i] != NULL; i++)
  54.         printf("\t%s\n", msg.params[i]);
  55.     printf("\t NULL\n }\n");
  56.  
  57.     printf("trailing: %s\n", msg.trailing);
  58.     return 0;
  59. }
  60.  
  61. // <message>  ::= [':' <prefix> <SPACE> ] <command> <params> <crlf>
  62. void *ParseMessage(char *str, IRC_MESSAGE_FIELDS *msg)
  63. {
  64.     msg->message = strdup(str);
  65.  
  66.     if (str[0] == ':')
  67.     {
  68.         ParsePrefix(str, msg);
  69.     }
  70.     else // there was no prefix
  71.     {
  72.         msg->prefix = NULL;
  73.         ParseCommand(str, msg);
  74.     }
  75. }
  76.  
  77. // <prefix>   ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
  78. void *ParsePrefix(char *str, IRC_MESSAGE_FIELDS *msg)
  79. {
  80.     msg->prefix = strtok(str, " ") + 1; // truncate :
  81.     ParseCommand(NULL, msg);
  82. }
  83.  
  84. // <command>  ::= <letter> { <letter> } | <number> <number> <number>
  85. void *ParseCommand(char *str, IRC_MESSAGE_FIELDS *msg)
  86. {
  87.     if (str == NULL)
  88.     {
  89.         msg->command = strtok(NULL, " ");
  90.     }
  91.     else // there was no prefix
  92.     {
  93.         msg->command = strtok(str, " ");
  94.     }
  95.  
  96.     ParseParams(str, msg);
  97. }
  98.  
  99. // <params>   ::= <SPACE> [ ':' <trailing> | <middle> <params> ]
  100. void *ParseParams(char *str, IRC_MESSAGE_FIELDS *msg)
  101. {
  102.     int i = -1;
  103.  
  104.     do
  105.     {
  106.         i++;
  107.         msg->params[i] = strtok(NULL, " ");
  108.         char *contains_colon = strstr(msg->params[i], ":");
  109.         if (contains_colon)
  110.         {
  111.             msg->params[i] = NULL;
  112.             msg->trailing = (strstr(msg->message, contains_colon)) + 1; // truncate :
  113.             break;
  114.         }
  115.  
  116.     } while (msg->params[i] != NULL);
  117. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top