Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

MikeWalkerMRU May 21st, 2020 1,074 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.         puts(msg.prefix);
  46.     puts(msg.command);
  47.  
  48.     for (int i = 0; msg.params[i] != NULL; i++)
  49.         puts(msg.params[i]);
  50.  
  51.     return 0;
  52. }
  53.  
  54. // <message>  ::= [':' <prefix> <SPACE> ] <command> <params> <crlf>
  55. char *ParseMessage(char *str, IRC_MESSAGE_FIELDS *msg)
  56. {
  57.     msg->message = strdup(str);
  58.     char *head = strtok(str, ":");
  59.     char *tail = strtok(NULL, ":");
  60.  
  61.     if (str[0] == ':')
  62.     {
  63.         ParsePrefix(head, msg);
  64.     }
  65.     else // there was no prefix
  66.     {
  67.         msg->prefix = NULL;
  68.         ParseCommand(head, msg);
  69.     }
  70.     return NULL;
  71. }
  72.  
  73. // <prefix>   ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
  74. char *ParsePrefix(char *str, IRC_MESSAGE_FIELDS *msg)
  75. {
  76.     msg->prefix = strtok(str, " ");
  77.     ParseCommand(NULL, msg);
  78.     return NULL;
  79. }
  80.  
  81. // <command>  ::= <letter> { <letter> } | <number> <number> <number>
  82. char *ParseCommand(char *str, IRC_MESSAGE_FIELDS *msg)
  83. {
  84.     if (str == NULL)
  85.     {
  86.         msg->command = strtok(NULL, " ");
  87.     }
  88.     else // there was no prefix
  89.     {
  90.         msg->command = strtok(str, " ");
  91.         puts(msg->command);
  92.     }
  93.  
  94.     ParseParams(NULL, msg);
  95.  
  96.     return NULL;
  97. }
  98.  
  99. // <params>   ::= <SPACE> [ ':' <trailing> | <middle> <params> ]
  100. char *ParseParams(char *str, IRC_MESSAGE_FIELDS *msg)
  101. {
  102.     int i = -1;
  103.     do
  104.     {
  105.         i++;
  106.         msg->params[i] = strtok(NULL, " ");
  107.     } while (msg->params[i] != NULL);
  108.     return NULL;
  109. }
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