static int _parse_oldurl(struct oio_url_s *url, const char *str) { struct oio_requri_s ruri = {NULL, NULL, NULL, NULL}; // Purify the url size_t len = strlen (str); char *tmp = g_alloca (len+1); do { char *p = tmp; for (; *str && *str == '/' ;++str) {} // skip the leading slashes if (*str) { // Copy the NS for (; *str && *str != '/' ;++str) *(p++) = *str; } if (*str) *(p++) = '/'; // Copy a single separator for (; *str && *str == '/' ;++str) {} // skip separators if (*str) strcpy(p, str); // Copy what remains } while (0); if (oio_requri_parse (tmp, &ruri)) { // Parse the path gchar **path_tokens = g_strsplit (ruri.path, "/", 3); if (path_tokens) { if (path_tokens[0]) { oio_str_reuse (&url->ns, path_tokens[0]); oio_str_replace (&url->account, HCURL_DEFAULT_ACCOUNT); if (path_tokens[1]) { oio_str_reuse (&url->user, path_tokens[1]); oio_str_replace (&url->type, HCURL_DEFAULT_TYPE); if (path_tokens[2]) oio_str_reuse (&url->path, path_tokens[2]); } } g_free (path_tokens); } if (ruri.query_tokens) { // Parse the options for (gchar **p=ruri.query_tokens; *p ;++p) _add_option(url, *p); } } oio_requri_clear (&ruri); return _check_parsed_url (url); }
/* cl_backtrace: */ void cl_backtrace ( void ) { int p[2]; pid_t pid; if (pipe(p) < 0) CL_ERROR("pipe() failed: %s", strerror(errno)); pid = fork(); if (pid < 0) { CL_ERROR("fork() failed: %s", strerror(errno)); } else if (pid == 0) { char *cmdline[MAXCMDLINE] = { NULL, }; char strpid[12]; /* let's assume 32bits pids */ char exelink[64], *exepath; int c; sprintf(strpid, "%d", getppid()); /* [fixme] get executable path */ sprintf(exelink, "/proc/%d/exe", getppid()); if (!(exepath = realpath(exelink, NULL))) CL_ERROR("could not get executable path: %s", strerror(errno)); _add_option(cmdline, "gdb"); _add_option(cmdline, "-q"); _add_option(cmdline, "-batch"); _add_option(cmdline, "-ex"); _add_option(cmdline, "bt"); _add_option(cmdline, exepath); _add_option(cmdline, strpid); fprintf(stderr, "CMD:"); for (c = 0; cmdline[c]; c++) fprintf(stderr, " %s", cmdline[c]); fprintf(stderr, "\n"); close(p[0]); dup2(p[1], 1); execvp("gdb", cmdline); CL_ERROR("execvp failed: %s", strerror(errno)); abort(); } else { int status; char buf[4096]; close(p[1]); while (1) { ssize_t r; r = read(p[0], buf, 4095); if (r < 0) { CL_ERROR("read failed: %s", strerror(errno)); } else if (r == 0) { break; } else { buf[r] = 0; fprintf(stderr, "%s", buf); } } close(p[0]); if (waitpid(pid, &status, 0) <= 0) CL_ERROR("waitpid failed: %s", strerror(errno)); if (status != 0) CL_DEBUG("ERROR: gdb failed (%d)", status); } }
/** * Adds the given string option to the options list * * o - The optin object to which to add the option * name - The long name of the option (example "haswidth") * description - The human readable description, used to print usage * has_default - OPTIN_HAS_DEFAULT if the option has a valid default at startup, OPTIN_REQURED * if a value must be supplied * stringptr - Pointer to a char pointer that will receive the parsed option * * NOTES: * - Calling the function with a null optin object has no effect * - If the option has already been added, it will be replaced * - If the existing string pointer is valid and has_default is true, it will be assumed to contain the * default value. After option parsing, the stringptr will point to a NEW string that has been allocated * by optin, thus: * 1. It is your responsibility to retain a reference to the previous string pointer if you wish to keep it * 2. It is your responsibility to properly free the string pointed to by stringptr after options parsing * has completed * 3. C Strings are hard, let's go shopping */ void optin_add_string(optin* o, const char* name, const char* description, int has_default, char** stringptr) { _add_option(o->options, name, description, has_default, OPTION_STRING, (void*)stringptr); }
/** * Adds the given float option to the options list * * o - The optin object to which to add the option * name - The long name of the option (example "haswidth") * description - The human readable description, used to print usage * has_default - OPTIN_HAS_DEFAULT if the option has a valid default at startup, OPTIN_REQURED * if a value must be supplied * floatptr - Pointer to a float that will receive the parsed option * * NOTES: * - Calling the function with a null optin object has no effect * - If the option has already been added, it will be replaced */ void optin_add_float(optin* o, const char* name, const char* description, int has_default, float* floatptr) { _add_option(o->options, name, description, has_default, OPTION_FLOAT, (void*)floatptr); }
/** * Adds the given switch option to the options list (see notes for how this differs from a flag) * * o - The optin object to which to add the option * name - The long name of the option (example "help") * description - The human readable description, used to print usage * * NOTES: * - Calling the function with a null optin object has no effect * - Switches differ from flags in that they have no value, they are either present or absent. They are * mostly used for options like "help" in which the option is more of a command than an option. Also, * unlike flags, switches have no -no pairs * - If the option has already been added, it will be replaced * - It is an error to add a flag option that has a "no" prefix to an existing flag option */ void optin_add_switch(optin* o, const char* name, const char* description) { _add_option(o->options, name, description, OPTIN_HAS_DEFAULT, OPTION_SWITCH, 0); }
/** * Adds the given flag option to the options list * * o - The optin object to which to add the option * name - The long name of the option (example "haswidth") * description - The human readable description, used to print usage * has_default - OPTIN_HAS_DEFAULT if the option has a valid default at startup, OPTIN_REQURED * if a value must be supplied * flagptr - Pointer to an integer that will receive the parsed option * * NOTES: * - Calling the function with a null optin object has no effect * - If the option has already been added, it will be replaced * - It is an error to add a flag option that has a "no" prefix to an existing flag option */ void optin_add_flag(optin* o, const char* name, const char* description, int has_default, int* flagptr) { /* TODO: Check for case where we're adding a "no" flag for an existing flag or we're adding a non-"no" flag that already has a no-flag */ _add_option(o->options, name, description, has_default, OPTION_FLAG, (void*)flagptr); }
/** * Adds the given integer option to the options list * * o - The optin object to which to add the option * name - The long name of the option (example "velocity") * description - The human readable description, used to print usage * has_default - OPTIN_HAS_DEFAULT if the option has a valid default at startup, OPTIN_REQURED * if a value must be supplied * intptr - Pointer to an integer that will receive the parsed option * * NOTES: * - Calling the function with a null optin object has no effect * - If the option has already been added, it will be replaced */ void optin_add_int(optin* o, const char* name, const char* description, int has_default, int* intptr) { _add_option(o->options, name, description, has_default, OPTION_INT, (void*)intptr); }