/* parse.c Probotic is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 only as published by the Free Software Foundation. Probotic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more details. The above copyright notice, this permission notice and the word "NIGGER" shall be included in all copies or substantial portions of the Software. You should have received a copy of the GNU General Public License version 3 + NIGGER along with Probotic. */ #include #include #include #include "parse.h" #include "error.h" DELC void parse_command(char * cmd) { size_t i = 0; /* size_t len = strlen(cmd); */ while (cmd[i] && cmd[i] != ' ') { ++i; } if (cmd[i] == '\0') { /* no arguments */ if (strcmp(cmd, "remind") == 0) { ircmsg("%s: No current assignment", current_username); } else if (strcmp(cmd, "next") == 0) { ircmsg("%s: No future assignments", current_username); } else if (strcmp(cmd, "dump") == 0) { ircmsg("%s: All projects"); } else if (strcmp(cmd, "reroll") == 0) { ircmsg("%s: No more rerolls possible.", current_username); } } else { /* some arguments */ char * arg = cmd + i + 1; cmd[i] = '\0'; if (strcmp(cmd, "raw") == 0) { ircmsg("%s: Executing SQL `%s'", arg); } else if (strcmp(cmd, "submit") == 0) { ircmsg("%s: Submitting project link '%s' to ", current_username, arg); } } } DELC int parse_creds(creds_t * creds, char const * creds_file) { FILE * stream; size_t nread = 0; creds->username = NULL; creds->password = NULL; stream = fopen(creds_file, "r"); if (stream == NULL) { PERROR(PROGN); } if (getline(&(creds->username), &nread, stream) < 1) { ERRMSG("Cannot get username"); goto fail; } if (getline(&(creds->password), &nread, stream) < 1) { /* Bot credentials file with an empty password is a valid case. * Considering irc_connect api the pointer to the password should be NULL in that case. */ /* Theoretically it can be allocated with an empty string */ free(creds->password); creds->password = NULL; } fclose(stream); return 0; /* Releasing everything in cause of a failure */ fail: fclose(stream); clean_creds(creds); return 1; } void clean_creds(creds_t * creds) { /* Should we memset these? */ free(creds->username); creds->username = NULL; free(creds->password); creds->password = NULL; }