src/parse.c
changeset 48 34094173351c
parent 45 535478a0f482
child 61 fb2cfcee38bd
equal deleted inserted replaced
47:a689b6a8e6ed 48:34094173351c
    83      * make sure that parseable data is available
    83      * make sure that parseable data is available
    84      * this prevents a possible segmentation fault
    84      * this prevents a possible segmentation fault
    85      */
    85      */
    86     if (message->user == NULL)
    86     if (message->user == NULL)
    87         message->user = "error";
    87         message->user = "error";
    88     if (message->email == NULL)
    88     if (message->domain == NULL)
    89         message->email = "server.err";
    89         message->domain = "server.err";
    90 
    90 
    91     /*
    91     /*
    92      * default message
    92      * default message
    93      */
    93      */
    94     snprintf (msg, sizeof (msg), "PRIVMSG %s :%s.\r\n", message->channel, gettext ("Request cannot be performed"));
    94     snprintf (msg, sizeof (msg), "PRIVMSG %s :%s.\r\n", message->channel, gettext ("Request cannot be performed"));
   121                 return msg;
   121                 return msg;
   122 
   122 
   123             case JOIN:
   123             case JOIN:
   124                 if ((token = strtok (NULL, "\r\n")))
   124                 if ((token = strtok (NULL, "\r\n")))
   125                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   125                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   126                         if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   126                         if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain")))
   127                             snprintf (msg, sizeof (msg), "JOIN %s\r\n", token);
   127                             snprintf (msg, sizeof (msg), "JOIN %s\r\n", token);
   128                     }
   128                     }
   129                 return msg;
   129                 return msg;
   130 
   130 
   131             case LEAVE:
   131             case LEAVE:
   132                 if (*message->channel != '#')
   132                 if (*message->channel != '#')
   133                     return NULL;
   133                     return NULL;
   134                 if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   134                 if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   135                     if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   135                     if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain")))
   136                         snprintf (msg, sizeof (msg), "PART %s :Leaving.\r\n", message->channel);
   136                         snprintf (msg, sizeof (msg), "PART %s :Leaving.\r\n", message->channel);
   137                 }
   137                 }
   138                 return msg;
   138                 return msg;
   139 
   139 
   140             case ADD:
   140             case ADD:
   207                 snprintf (msg, sizeof (msg), "PRIVMSG %s :%s %s.\r\n", message->user,
   207                 snprintf (msg, sizeof (msg), "PRIVMSG %s :%s %s.\r\n", message->user,
   208                           gettext ("Autolearn disabled for channel"), message->channel);
   208                           gettext ("Autolearn disabled for channel"), message->channel);
   209                 return msg;
   209                 return msg;
   210 
   210 
   211             case DEBUG:
   211             case DEBUG:
   212                 snprintf (msg, sizeof (msg), "PRIVMSG %s :USER: %s EMAIL: %s CHANNEL: %s LINE: %s\r\n",
   212                 snprintf (msg, sizeof (msg), "PRIVMSG %s :USER: %s domain: %s CHANNEL: %s LINE: %s\r\n",
   213                           message->channel, message->user, message->email, message->channel, message->line);
   213                           message->channel, message->user, message->domain, message->channel, message->line);
   214                 return msg;
   214                 return msg;
   215 
   215 
   216             case VACCUUM:
   216             case VACCUUM:
   217                 snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE));
   217                 snprintf (msg, sizeof (msg), "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE));
   218                 return msg;
   218                 return msg;
   219 
   219 
   220             case LOGOUT:
   220             case LOGOUT:
   221                 if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   221                 if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   222                     if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) {
   222                     if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain"))) {
   223                         snprintf (msg, sizeof (msg), "PRIVMSG %s :%s!\r\nQUIT\r\n", message->channel,
   223                         snprintf (msg, sizeof (msg), "PRIVMSG %s :%s!\r\nQUIT\r\n", message->channel,
   224                                   gettext ("Bye, have a nice day!"));
   224                                   gettext ("Bye, have a nice day!"));
   225                     }
   225                     }
   226                 }
   226                 }
   227                 /*
   227                 /*
   264                 return msg;
   264                 return msg;
   265 
   265 
   266             case OP:
   266             case OP:
   267                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   267                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   268                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   268                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   269                         if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   269                         if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain")))
   270                             snprintf (msg, sizeof (msg), "MODE %s +o %s\r\n", message->channel, token);
   270                             snprintf (msg, sizeof (msg), "MODE %s +o %s\r\n", message->channel, token);
   271                     }
   271                     }
   272                 }
   272                 }
   273                 return msg;
   273                 return msg;
   274 
   274 
   275             case DEOP:
   275             case DEOP:
   276                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   276                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   277                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   277                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   278                         if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   278                         if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain")))
   279                             snprintf (msg, sizeof (msg), "MODE %s -o %s\r\n", message->channel, token);
   279                             snprintf (msg, sizeof (msg), "MODE %s -o %s\r\n", message->channel, token);
   280                     }
   280                     }
   281                 }
   281                 }
   282                 return msg;
   282                 return msg;
   283 
   283 
   284             case KICK:
   284             case KICK:
   285                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   285                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   286                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   286                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   287                         if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   287                         if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain")))
   288                             snprintf (msg, sizeof (msg), "KICK %s %s\r\n", message->channel, token);
   288                             snprintf (msg, sizeof (msg), "KICK %s %s\r\n", message->channel, token);
   289                     }
   289                     }
   290                 }
   290                 }
   291                 return msg;
   291                 return msg;
   292 
   292 
   293             case BAN:
   293             case BAN:
   294                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   294                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   295                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   295                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   296                         if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   296                         if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain")))
   297                             snprintf (msg, sizeof (msg), "MODE %s +b %s\r\n", message->channel, token);
   297                             snprintf (msg, sizeof (msg), "MODE %s +b %s\r\n", message->channel, token);
   298                     }
   298                     }
   299                 }
   299                 }
   300                 return msg;
   300                 return msg;
   301 
   301 
   302             case UNBAN:
   302             case UNBAN:
   303                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   303                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   304                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   304                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   305                         if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   305                         if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain")))
   306                             snprintf (msg, sizeof (msg), "MODE %s -b %s\r\n", message->channel, token);
   306                             snprintf (msg, sizeof (msg), "MODE %s -b %s\r\n", message->channel, token);
   307                     }
   307                     }
   308                 }
   308                 }
   309                 return msg;
   309                 return msg;
   310 
   310 
   311             case KICKBAN:
   311             case KICKBAN:
   312                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   312                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   313                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   313                     if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   314                         if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   314                         if (strstr (message->domain, db_lookup (DATABASE_FILE, "mcbot.domain")))
   315                             snprintf (msg, sizeof (msg), "MODE %s +b %s\r\nKICK %s %s\r\n", message->channel, token,
   315                             snprintf (msg, sizeof (msg), "MODE %s +b %s\r\nKICK %s %s\r\n", message->channel, token,
   316                                       message->channel, token);
   316                                       message->channel, token);
   317                     }
   317                     }
   318                 }
   318                 }
   319                 return msg;
   319                 return msg;