bool get_arguments(int sockfd, const char *cmd, std::string &out_zone, int &need_write_xml) { char buf[ODS_SE_MAXLINE]; const char *argv[16]; const int NARGV = sizeof(argv)/sizeof(char*); int argc; // Use buf as an intermediate buffer for the command. strncpy(buf,cmd,sizeof(buf)); buf[sizeof(buf)-1] = '\0'; // separate the arguments argc = ods_str_explode(buf,NARGV,argv); if (argc > NARGV) { ods_log_error_and_printf(sockfd,module_str,"too many arguments"); return false; } const char *zone = NULL; (void)ods_find_arg_and_param(&argc,argv,"zone","z",&zone); int del_all = 0; if (ods_find_arg(&argc, argv, "all", "a") != -1) del_all = 1; if (ods_find_arg(&argc, argv, "xml", "u") >= 0) need_write_xml = 1; if (argc) { ods_log_error_and_printf(sockfd,module_str,"unknown arguments"); return false; } if (zone && del_all) { ods_log_error_and_printf(sockfd,module_str, "expected either --zone <zone> or --all, found both "); return false; } if (!zone) { if (!del_all) { ods_log_error_and_printf(sockfd,module_str, "expected option --zone <zone> or --all "); return false; } } else out_zone = zone; return true; }
int handled_keystate_list_cmd(int sockfd, engine_type* engine, const char *cmd, ssize_t n) { char buf[ODS_SE_MAXLINE]; const char *argv[8]; const int NARGV = sizeof(argv)/sizeof(char*); int argc; const char *scmd = "key list"; cmd = ods_check_command(cmd,n,scmd); if (!cmd) return 0; // not handled ods_log_debug("[%s] %s command", module_str, scmd); // Use buf as an intermediate buffer for the command. strncpy(buf,cmd,sizeof(buf)); buf[sizeof(buf)-1] = '\0'; // separate the arguments argc = ods_str_explode(buf,NARGV,argv); if (argc > NARGV) { ods_log_warning("[%s] too many arguments for %s command", module_str,scmd); ods_printf(sockfd,"too many arguments\n"); help_keystate_list_cmd(sockfd); return 1; // errors, but handled } bool bVerbose = ods_find_arg(&argc,argv,"verbose","v") != -1; bool bDebug = ods_find_arg(&argc,argv,"debug","d") != -1; if (argc) { ods_log_warning("[%s] unknown arguments for %s command", module_str,scmd); ods_printf(sockfd,"unknown arguments\n"); help_keystate_list_cmd(sockfd); return 1; // errors, but handled } time_t tstart = time(NULL); perform_keystate_list(sockfd, engine->config, bVerbose, bDebug); ods_printf(sockfd,"%s completed in %ld seconds.\n",scmd,time(NULL)-tstart); return 1; }
bool get_arguments(int sockfd, const char *cmd, std::string &out_zone) { char buf[ODS_SE_MAXLINE]; const char *argv[16]; const int NARGV = sizeof(argv)/sizeof(char*); int argc; // Use buf as an intermediate buffer for the command. strncpy(buf,cmd,sizeof(buf)); buf[sizeof(buf)-1] = '\0'; // separate the arguments argc = ods_str_explode(buf,NARGV,argv); if (argc > NARGV) { ods_log_error_and_printf(sockfd,module_str,"too many arguments"); return false; } const char *zone = NULL; (void)ods_find_arg_and_param(&argc,argv,"zone","z",&zone); bool bforce = ods_find_arg(&argc,argv,"force","f")!=-1; if (argc) { ods_log_error_and_printf(sockfd,module_str,"unknown arguments"); return false; } if (!zone) { ods_log_error_and_printf(sockfd,module_str, "expected option --zone <zone>"); return false; } out_zone = zone; if (!bforce) { ods_log_error_and_printf(sockfd,module_str, "expected option --force"); return false; } return true; }
static int run(int sockfd, engine_type* engine, const char *cmd, ssize_t n, db_connection_t *dbconn) { char buf[ODS_SE_MAXLINE]; #define NARGV 12 const char *argv[NARGV]; int success, argIndex; int argc, bVerbose, bDebug, bParsable, bAll; char* keytypeParam; char* keystateParam; const char* filterZone; /* NULL if no filtering on zone, otherwise zone to match */ char** filterKeytype; /* NULL if no filtering on key type, NULL terminated list of key types to filter */ char** filterKeystate; /* NULL if no filtering on key state, NULL terminated list of key states to filter */ (void) engine; ods_log_debug("[%s] %s command", module_str, key_list_funcblock()->cmdname); cmd = ods_check_command(cmd, n, key_list_funcblock()->cmdname); /* Use buf as an intermediate buffer for the command. */ strncpy(buf, cmd, sizeof (buf)); buf[sizeof (buf) - 1] = '\0'; /* separate the arguments */ argc = ods_str_explode(buf, NARGV, argv); if (argc > NARGV) { ods_log_warning("[%s] too many arguments for %s command", module_str, key_list_funcblock()->cmdname); client_printf(sockfd, "too many arguments\n"); return -1; } bVerbose = ods_find_arg(&argc, argv, "verbose", "v") != -1; bDebug = ods_find_arg(&argc, argv, "debug", "d") != -1; bParsable = ods_find_arg(&argc, argv, "parsable", "p") != -1; if ((argIndex = ods_find_arg_and_param(&argc, argv, "zone", "z", &filterZone)) == -1) { filterZone = NULL; } if (ods_find_arg_and_param(&argc, argv, "keytype", "k", (const char **)&keytypeParam) == -1) { keytypeParam = NULL; } if (ods_find_arg_and_param(&argc, argv, "keystate", "e", (const char **)&keystateParam) == -1) { keystateParam = NULL; } bAll = (ods_find_arg(&argc, argv, "all", "a") != -1); if (keystateParam != NULL && bAll) { client_printf(sockfd, "Error: --keystate and --all option cannot be given together\n"); return -1; } if (argc) { ods_log_warning("[%s] unknown arguments for %s command", module_str, key_list_funcblock()->cmdname); client_printf(sockfd, "unknown arguments\n"); return -1; } if (keytypeParam) filterKeytype = tokenizeparam(keytypeParam); else filterKeytype = NULL; if (keystateParam) { filterKeystate = tokenizeparam(keystateParam); } else filterKeystate = NULL; if (bAll) { if (filterKeystate != NULL) { free(filterKeystate); } filterKeystate = NULL; } else if(filterKeystate == NULL) { if ((filterKeystate = malloc(sizeof (char*) * 6))) { filterKeystate[0] = (char *)"publish"; filterKeystate[1] = (char *)"ready"; filterKeystate[2] = (char *)"active"; filterKeystate[3] = (char *)"retire"; filterKeystate[4] = (char *)"mixed"; filterKeystate[5] = NULL; } /* else emit error */ } if (bDebug) { if (bParsable) { success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, NULL, &printdebugparsablekey); } else { success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printdebugheader, &printdebugkey); } } else if (bVerbose) { if (bParsable) { success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, NULL, &printverboseparsablekey); } else { success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printverboseheader, &printverbosekey); } } else { success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printcompatheader, &printcompatkey); } if (filterKeytype) free(filterKeytype); if (filterKeystate) free(filterKeystate); return success; }