int exec_builtin(t_group *grp, char *order) { int active; active = 0; order = ft_strtrim(order); if (ft_strcmp(grp->cmd[0], "env") == 0) { active++; if (manage_opt(grp) < 0) return (active); (grp->options->on[u] == true || (grp->define_cmd[namenv] > 0 && grp->define_cmd[utils] == false) || grp->cmd[1] == NULL) ? exec_env(grp, 1) : exec_env(grp, 0); } else if (ft_strcmp(grp->cmd[0], "cd") == 0) (active += 1) ? manage_cd(grp) : 0; else if (ft_strcmp(grp->cmd[0], "setenv") == 0) (active += 1) ? ft_setenv(grp) : 0; else if (ft_strcmp(grp->cmd[0], "unsetenv") == 0) (active += 1) ? ft_unsetenv(grp) : 0; else if (ft_strcmp(grp->cmd[0], "exit") == 0) grp->cmd[1] ? exit(ft_atoi(grp->cmd[1])) : exit(0); return (active); }
int arg_loop(int i, t_group *grp, int argc, char **argv) { DIR *directory; struct stat buf; int ret; int dir_opened; dir_opened = 0; while (++i < argc) { if (*argv[i] == '-' && grp->diropen == 0) manage_opt(grp, argv[i]); else { if (!(directory = opendir(argv[i])) || grp->options[d] == true) { if ((ret = lstat(argv[i], &buf)) < 0) is_error(argv[i], "is not an available files"); else define_status(grp, argv[i], buf); } else dir_opened = arg_dir(grp, buf, directory, argv[i]); grp->diropen += 1; } } return (dir_opened); }
void uwsgi_endElement(void *userData, const char *name) { if (current_xmlnode && !current_xmlnode_has_arg) { manage_opt(current_xmlnode, NULL); } else if (current_xmlnode_has_arg) { if (!current_xmlnode_text_len) { fprintf(stderr,"option %s requires an argument\n", name); exit(1); } // HACK: use the first char of closing tag for nulling string current_xmlnode_text[current_xmlnode_text_len] = 0; manage_opt(current_xmlnode, current_xmlnode_text); } current_xmlnode = 0 ; current_xmlnode_has_arg = 0 ; current_xmlnode_text = NULL ; current_xmlnode_text_len = 0 ; }
void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options) { xmlDoc *doc = NULL; xmlNode *element = NULL; xmlNode *node = NULL; xmlNode *node2 = NULL; xmlChar *xml_uwsgi_mountpoint = NULL; xmlChar *xml_uwsgi_script = NULL; struct option *lopt, *aopt; doc = xmlReadFile(uwsgi.xml_config, NULL, 0); if (doc == NULL) { fprintf(stderr, "[uWSGI] could not parse file %s.\n", uwsgi.xml_config); exit(1); } if (long_options) { fprintf(stderr, "[uWSGI] parsing config file %s\n", uwsgi.xml_config); } element = xmlDocGetRootElement(doc); if (element == NULL) { fprintf(stderr, "[uWSGI] invalid xml config file.\n"); exit(1); } if (strcmp((char *) element->name, "uwsgi")) { fprintf(stderr, "[uWSGI] invalid xml root element, <uwsgi> expected.\n"); exit(1); } if (long_options) { // first check for pythonpath for (node = element->children; node; node = node->next) { if (node->type == XML_ELEMENT_NODE) { lopt = long_options; while ((aopt = lopt)) { if (!aopt->name) break; if (!strcmp((char *) node->name, aopt->name)) { if (!node->children && aopt->has_arg) { fprintf(stderr, "[uWSGI] %s option need a value. skip.\n", aopt->name); exit(1); } if (node->children) { if (!node->children->content && aopt->has_arg) { fprintf(stderr, "[uWSGI] %s option need a value. skip.\n", aopt->name); exit(1); } } if (aopt->flag) { *aopt->flag = aopt->val; } else { if (node->children) { manage_opt(aopt->val, (char *) node->children->content); } else { manage_opt(aopt->val, NULL); } } } lopt++; } } } } else { // ... then for wsgi apps for (node = element->children; node; node = node->next) { if (node->type == XML_ELEMENT_NODE) { if (!strcmp((char *) node->name, "app")) { xml_uwsgi_mountpoint = xmlGetProp(node, (const xmlChar *) "mountpoint"); if (xml_uwsgi_mountpoint == NULL) { fprintf(stderr, "no mountpoint defined for app. skip.\n"); continue; } wsgi_req->script_name = (char *) xml_uwsgi_mountpoint; wsgi_req->script_name_len = strlen(wsgi_req->script_name); for (node2 = node->children; node2; node2 = node2->next) { if (node2->type == XML_ELEMENT_NODE) { if (!strcmp((char *) node2->name, "script")) { if (!node2->children) { fprintf(stderr, "no wsgi script defined. skip.\n"); continue; } xml_uwsgi_script = node2->children->content; if (xml_uwsgi_script == NULL) { fprintf(stderr, "no wsgi script defined. skip.\n"); continue; } wsgi_req->wsgi_script = (char *) xml_uwsgi_script; wsgi_req->wsgi_script_len = strlen(wsgi_req->wsgi_script); init_uwsgi_app(NULL, NULL); } } } } } } } /* We cannot free xml resources on the first round as the string pointer must be valid for all the server lifecycle */ if (!long_options) { xmlFreeDoc (doc); xmlCleanupParser (); } }