/*mln_set_worker_ipc_handler*/ void mln_set_worker_ipc_handler(mln_ipc_handler_t *ih) { mln_rbtree_node_t *rn = mln_rbtree_search(worker_ipc_tree, \ worker_ipc_tree->root, \ ih); if (rn->data != NULL) { mln_log(error, "IPC type '%d' already existed.\n", ih->type); abort(); } rn = mln_rbtree_new_node(worker_ipc_tree, ih); if (rn == NULL) { mln_log(error, "No memory.\n"); abort(); } mln_rbtree_insert(worker_ipc_tree, rn); }
static int _mln_conf_load(mln_conf_t *cf, mln_conf_domain_t *current) { mln_conf_lex_struct_t *fir, *next; mln_conf_cmd_t *cmd; mln_conf_domain_t *cd; mln_rbtree_node_t *rn; while ( 1 ) { fir = mln_conf_token(cf->lex); if (fir == NULL) { fprintf(stderr, "Get token error. %s\n", mln_lex_strerror(cf->lex)); return -1; } else if (fir->type == CONF_TK_EOF) { mln_conf_lex_free(fir); break; } else if (fir->type == CONF_TK_RBRACE) { if (mln_string_strcmp(current->domain_name, &default_domain)) { mln_conf_lex_free(fir); return 0; } CONF_ERR(cf->lex, fir, "Invalid right brace"); mln_conf_lex_free(fir); return -1; } else if (fir->type != CONF_TK_ID) { CONF_ERR(cf->lex, fir, "Unexpected token"); mln_conf_lex_free(fir); return -1; } next = mln_conf_token(cf->lex); if (next == NULL) { mln_conf_lex_free(fir); fprintf(stderr, "Get token error. %s\n", mln_lex_strerror(cf->lex)); return -1; } else if (next->type == CONF_TK_EOF) { CONF_ERR(cf->lex, next, "Invalid end of file"); mln_conf_lex_free(fir); mln_conf_lex_free(next); return -1; } /*as domain*/ if (next->type == CONF_TK_LBRACE) { mln_conf_lex_free(next); if (mln_string_strcmp(current->domain_name, &default_domain)) { CONF_ERR(cf->lex, fir, "Illegal domain"); mln_conf_lex_free(fir); return -1; } cd = mln_conf_domain_init(cf, fir->text); mln_conf_lex_free(fir); if (cd == NULL) { fprintf(stderr, "No memory.\n"); return -1; } if ((rn = mln_rbtree_new_node(cf->domain, cd)) == NULL) { fprintf(stderr, "No memory.\n"); mln_conf_domain_destroy(cd); return -1; } mln_rbtree_insert(cf->domain, rn); if (_mln_conf_load(cf, cd) < 0) return -1; continue; } /*as command*/ cmd = mln_conf_cmd_init(fir->text); mln_conf_lex_free(fir); if (cmd == NULL) { fprintf(stderr, "No memory.\n"); mln_conf_lex_free(next); return -1; } if ((rn = mln_rbtree_new_node(current->cmd, cmd)) == NULL) { fprintf(stderr, "No memory.\n"); mln_conf_cmd_destroy(cmd); mln_conf_lex_free(next); return -1; } mln_rbtree_insert(current->cmd, rn); if (mln_conf_item_recursive(cf, cmd, next, 0) < 0) return -1; /* * we don't need to free the pointer 'next' here, * because it has already freed in mln_conf_item_recursive(). */ } return 0; }
/*mln_conf_t*/ static inline mln_conf_t *mln_conf_init(void) { mln_conf_lex_lex_dup(NULL, NULL);/*nothing to do, just get rid of compiler's warnging*/ mln_conf_t *cf; mln_rbtree_node_t *rn; cf = (mln_conf_t *)malloc(sizeof(mln_conf_t)); if (cf == NULL) { fprintf(stderr, "No memory.\n"); return NULL; } cf->search = mln_conf_search_domain; struct mln_rbtree_attr rbattr; rbattr.cmp = mln_conf_domain_cmp; rbattr.data_free = mln_conf_domain_destroy; if ((cf->domain = mln_rbtree_init(&rbattr)) == NULL) { fprintf(stderr, "No memory.\n"); free(cf); return NULL; } mln_alloc_t *pool; mln_string_t path; char *conf_file_path; mln_size_t path_len = strlen(mln_path()); mln_lex_hooks_t hooks; struct mln_lex_attr lattr; if ((pool = mln_alloc_init()) == NULL) { fprintf(stderr, "No memory.\n"); mln_rbtree_destroy(cf->domain); free(cf); return NULL; } if ((conf_file_path = (char *)mln_alloc_m(pool, path_len + sizeof(conf_filename) + 1)) == NULL) { fprintf(stderr, "No memory.\n"); mln_alloc_destroy(pool); mln_rbtree_destroy(cf->domain); free(cf); return NULL; } memcpy(conf_file_path, mln_path(), path_len); conf_file_path[path_len] = '/'; memcpy(conf_file_path+path_len+1, conf_filename, sizeof(conf_filename)-1); mln_string_nSet(&path, conf_file_path, path_len + sizeof(conf_filename)); lattr.pool = pool; lattr.keywords = conf_keywords; memset(&hooks, 0, sizeof(hooks)); hooks.slash_handler = (lex_hook)mln_conf_lex_slash_handler; hooks.sglq_handler = (lex_hook)mln_conf_lex_sglq_handler; hooks.dblq_handler = (lex_hook)mln_conf_lex_dblq_handler; lattr.hooks = &hooks; lattr.preprocess = 1; lattr.type = M_INPUT_T_FILE; lattr.data = &path; mln_lex_initWithHooks(mln_conf_lex, cf->lex, &lattr); mln_alloc_free(conf_file_path); if (cf->lex == NULL) { fprintf(stderr, "No memory.\n"); mln_alloc_destroy(pool); mln_rbtree_destroy(cf->domain); free(cf); return NULL; } mln_conf_domain_t *cd = mln_conf_domain_init(cf, &default_domain); if (cd == NULL) { fprintf(stderr, "No memory.\n"); mln_conf_destroy(cf); return NULL; } if ((rn = mln_rbtree_new_node(cf->domain, cd)) == NULL) { fprintf(stderr, "No memory.\n"); mln_conf_domain_destroy((void *)cd); mln_conf_destroy(cf); return NULL; } mln_rbtree_insert(cf->domain, rn); return cf; }