Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

MikeWalkerMRU May 21st, 2020 1,148 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.  
  6. char *g_messages[] = {
  7.     "NOTICE AUTH :*** Processing connection to irc.servercentral.net\r\n"
  8.     "PING :irc.servercentral.net \r\n",
  9.     ":irc.servercentral.net 372 {manpage} :- -  \r\n",
  10.     ":irc.servercentral.net 376 {manpage} :End of /MOTD command.\r\n",
  11.     ":{manpage}!~bot@d23-16-195-6.bchsia.telus.net JOIN :#c-test\r\n",
  12.     ":irc.servercentral.net 353 {manpage} = #c-test :{manpage} tofu1\r\n",
  13.     ":irc.servercentral.net 366 {manpage} #c-test :End of /NAMES list.\r\n",
  14.     ":tofu1!~tofu@rootstorm.com PRIVMSG #c-test :test\r\n",
  15.     ":tofu1!~tofu@rootstorm.com PRIVMSG {manpage} :message test\r\n",
  16.     ":tofu1!~tofu@rootstorm.com PRIVMSG {manpage} :PING 1590092030 937335\r\n",
  17.     ":tofu1!~tofu@rootstorm.com PRIVMSG {manpage} :VERSION\r\n",
  18.     NULL,
  19. };
  20.  
  21. typedef struct _IRC_MESSAGE_FIELDS
  22. {
  23.     char *message;
  24.     char *prefix;
  25.     char *command;
  26.     char *params[MAX_PARAMS + 1];
  27. } IRC_MESSAGE_FIELDS;
  28.  
  29. char *ParseMessage(char *str, IRC_MESSAGE_FIELDS *msg);
  30. char *ParsePrefix(char *str, IRC_MESSAGE_FIELDS *msg);
  31. char *ParseCommand(char *str, IRC_MESSAGE_FIELDS *msg);
  32. char *ParseParams(char *str, IRC_MESSAGE_FIELDS *msg);
  33.  
  34. int main(int argc, char **argv)
  35. {
  36.     IRC_MESSAGE_FIELDS msg;
  37.     char *no_prefix = strdup("PING :irc.servercentral.net \r\n");
  38.     char *prefix = strdup(":tofu1!~tofu@rootstorm.com PRIVMSG {manpage} :message test\r\n");
  39.  
  40.     // ParseMessage(no_prefix, &msg);
  41.     ParseMessage(prefix, &msg);
  42.  
  43.     puts(msg.message);
  44.     if (msg.prefix != NULL)
  45.         printf("prefix: %s\n", msg.prefix);
  46.     else
  47.         printf("prefix: NULL\n");
  48.     printf("command: %s\n", msg.command);
  49.  
  50.     printf("params: {\n");
  51.     for (int i = 0; msg.params[i] != NULL; i++)
  52.         puts(msg.params[i]);
  53.     printf("}\n");
  54.  
  55.     return 0;
  56. }
  57.  
  58. // <message>  ::= [':' <prefix> <SPACE> ] <command> <params> <crlf>
  59. char *ParseMessage(char *str, IRC_MESSAGE_FIELDS *msg)
  60. {
  61.     msg->message = strdup(str);
  62.     char *head = strtok(str, ":");
  63.     char *tail = strtok(NULL, ":");
  64.  
  65.     if (str[0] == ':')
  66.     {
  67.         ParsePrefix(head, msg);
  68.     }
  69.     else // there was no prefix
  70.     {
  71.         msg->prefix = NULL;
  72.         ParseCommand(head, msg);
  73.     }
  74.     return NULL;
  75. }
  76.  
  77. // <prefix>   ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
  78. char *ParsePrefix(char *str, IRC_MESSAGE_FIELDS *msg)
  79. {
  80.     msg->prefix = strtok(str, " ");
  81.     ParseCommand(NULL, msg);
  82.     return NULL;
  83. }
  84.  
  85. // <command>  ::= <letter> { <letter> } | <number> <number> <number>
  86. char *ParseCommand(char *str, IRC_MESSAGE_FIELDS *msg)
  87. {
  88.     if (str == NULL)
  89.     {
  90.         msg->command = strtok(NULL, " ");
  91.     }
  92.     else // there was no prefix
  93.     {
  94.         msg->command = strtok(str, " ");
  95.         puts(msg->command);
  96.     }
  97.  
  98.     ParseParams(NULL, msg);
  99.  
  100.     return NULL;
  101. }
  102.  
  103. // <params>   ::= <SPACE> [ ':' <trailing> | <middle> <params> ]
  104. char *ParseParams(char *str, IRC_MESSAGE_FIELDS *msg)
  105. {
  106.     int i = -1;
  107.     do
  108.     {
  109.         i++;
  110.         msg->params[i] = strtok(NULL, " ");
  111.     } while (msg->params[i] != NULL);
  112.     return NULL;
  113. }
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