static int _config_add(config_t *c, const char *key, const char *val) { if (!key || !val || !c || c->pairs >= CONFIG_MAX_KEYS) return -1; c->keys[c->pairs] = pool_strdup(c->pool, key, 0); c->vals[c->pairs] = pool_strdup(c->pool, val, 0); if (!c->keys[c->pairs] || !c->vals[c->pairs]) return -1; ++c->pairs; return 0; }
void ui_menu::item_append(const char *text, const char *subtext, UINT32 flags, void *ref) { ui_menu_item *pitem; int index; // only allow multiline as the first item if ((flags & MENU_FLAG_MULTILINE) != 0) assert(numitems == 1); // only allow a single multi-line item else if (numitems >= 2) assert((item[0].flags & MENU_FLAG_MULTILINE) == 0); // realloc the item array if necessary if (numitems >= allocitems) { int olditems = allocitems; allocitems += UI_MENU_ALLOC_ITEMS; ui_menu_item *newitems = auto_alloc_array(machine(), ui_menu_item, allocitems); for (int itemnum = 0; itemnum < olditems; itemnum++) newitems[itemnum] = item[itemnum]; auto_free(machine(), item); item = newitems; } index = numitems++; // copy the previous last item to the next one if (index != 0) { index--; item[index + 1] = item[index]; } // allocate a new item and populate it pitem = &item[index]; pitem->text = (text != nullptr) ? pool_strdup(text) : nullptr; pitem->subtext = (subtext != nullptr) ? pool_strdup(subtext) : nullptr; pitem->flags = flags; pitem->ref = ref; // update the selection if we need to if (resetpos == index || (resetref != nullptr && resetref == ref)) selected = index; if (resetpos == numitems - 1) selected = numitems - 1; }
char* pool_copy_str(pool_t *pool, char **dst, const char *str) { char *copy; copy = pool_strdup(pool, str); pool_free(pool, *dst); *dst = copy; return *dst; }
/** * Read a tag segment with sorting. * * @param[in] gtop #GTOP structure <br> * Output: @CODE{gtop->gtp_array} segment table <br> * Output: @CODE{gtop->gtp_count} segment table size <br> * Output: @CODE{gtop->gtp_index} segment table index (initial value = 0) <br> * Output: @CODE{gtop->cur_tagname} current tag name * * A segment is a set of tag records which have same tag name. <br> * This function read a segment from tag file, sort it and put it on segment table. <br> * This function can treat both of standard format and compact format. * * Sorting is done by three keys. * - 1st key: tag name * - 2nd key: file name * - 3rd key: line number * * Since all records in a segment have same tag name, you need not think about 1st key. */ void segment_read(GTOP *gtop) { const char *tagline, *fid, *path, *lineno; GTP *gtp; struct sh_entry *sh; /* * Save tag lines. */ gtop->cur_tagname[0] = '\0'; while ((tagline = dbop_next(gtop->dbop)) != NULL) { VIRTUAL_GRTAGS_GSYMS_PROCESSING(gtop); /* * get tag name and line number. * * tagline = <file id> <tag name> <line number> */ if (gtop->cur_tagname[0] == '\0') { strlimcpy(gtop->cur_tagname, gtop->dbop->lastkey, sizeof(gtop->cur_tagname)); } else if (strcmp(gtop->cur_tagname, gtop->dbop->lastkey) != 0) { /* * Dbop_next() wil read the same record again. */ dbop_unread(gtop->dbop); break; } gtp = varray_append(gtop->vb); gtp->tagline = pool_strdup(gtop->segment_pool, tagline, 0); gtp->tag = (const char *)gtop->cur_tagname; /* * convert fid into hashed path name to save memory. */ fid = (const char *)strmake(tagline, " "); path = gpath_fid2path(fid, NULL); if (path == NULL) die("gtags_first: path not found. (fid=%s)", fid); sh = strhash_assign(gtop->path_hash, path, 1); gtp->path = sh->name; lineno = seekto(gtp->tagline, SEEKTO_LINENO); if (lineno == NULL) die("illegal tag record.\n%s", tagline); gtp->lineno = atoi(lineno); } /* * Sort tag lines. */ gtop->gtp_array = varray_assign(gtop->vb, 0, 0); gtop->gtp_count = gtop->vb->length; gtop->gtp_index = 0; if (!(gtop->flags & GTOP_NOSORT)) qsort(gtop->gtp_array, gtop->gtp_count, sizeof(GTP), compare_tags); }
ui_menu_file_selector::file_selector_entry *ui_menu_file_selector::append_entry( file_selector_entry_type entry_type, const char *entry_basename, const char *entry_fullpath) { file_selector_entry *entry; file_selector_entry **entryptr; // allocate a new entry entry = (file_selector_entry *) m_pool_alloc(sizeof(*entry)); memset(entry, 0, sizeof(*entry)); entry->type = entry_type; entry->basename = (entry_basename != NULL) ? pool_strdup(entry_basename) : entry_basename; entry->fullpath = (entry_fullpath != NULL) ? pool_strdup(entry_fullpath) : entry_fullpath; // find the end of the list entryptr = &m_entrylist; while ((*entryptr != NULL) && (compare_entries(entry, *entryptr) >= 0)) entryptr = &(*entryptr)->next; // insert the entry entry->next = *entryptr; *entryptr = entry; return entry; }
menu_software_list::entry_info *menu_software_list::append_software_entry(const software_info &swinfo) { entry_info *entry = nullptr; entry_info **entryptr; bool entry_updated = FALSE; // check if at least one of the parts has the correct interface and add a menu entry only in this case for (const software_part &swpart : swinfo.parts()) { if (swpart.matches_interface(m_interface) && swpart.is_compatible(*m_swlist) == SOFTWARE_IS_COMPATIBLE) { entry_updated = TRUE; // allocate a new entry entry = (entry_info *) m_pool_alloc(sizeof(*entry)); memset(entry, 0, sizeof(*entry)); entry->short_name = pool_strdup(swinfo.shortname()); entry->long_name = pool_strdup(swinfo.longname()); break; } } // skip this if no new entry has been allocated (e.g. if the software has no matching interface for this image device) if (entry_updated) { // find the end of the list entryptr = &m_entrylist; while ((*entryptr != nullptr) && (compare_entries(entry, *entryptr, m_ordered_by_shortname) >= 0)) entryptr = &(*entryptr)->next; // insert the entry entry->next = *entryptr; *entryptr = entry; } return entry; }
int http_redirect_init(http_redirect_t *server, fdselect_t *fdselect, char *root_dir) { int err; do { memset(server, 0, sizeof(*server)); server->fdselect = fdselect; server->pool = pool_new(); assertb(server->pool); server->root_dir = pool_strdup(server->pool, root_dir); err = 0; } while(0); return 0; }
/** * gfind_open: start iterator using GPATH. * * @param[in] dbpath dbpath * @param[in] local local prefix, * if NULL specified, it assumes "./"; * @param[in] target GPATH_SOURCE: only source file, * GPATH_OTHER: only other file, * GPATH_BOTH: source file + other file * @param[in] flags GPATH_NEARSORT * @return GFIND structure */ GFIND * gfind_open(const char *dbpath, const char *local, int target, int flags) { GFIND *gfind = (GFIND *)check_calloc(sizeof(GFIND), 1); gfind->dbop = dbop_open(makepath(dbpath, dbname(GPATH), NULL), 0, 0, 0); if (gfind->dbop == NULL) die("GPATH not found."); gfind->path = NULL; gfind->prefix = check_strdup(local ? local : "./"); gfind->first = 1; gfind->eod = 0; gfind->target = target; gfind->type = GPATH_SOURCE; gfind->flags = flags; gfind->path_array = NULL; gfind->version = dbop_getversion(gfind->dbop); if (gfind->version > support_version) die("GPATH seems new format. Please install the latest GLOBAL."); else if (gfind->version < support_version) die("GPATH seems older format. Please remake tag files."); /* * Nearness sort. * In fact, this timing of sort is not good for performance. * Reconsideration is needed later. */ if (gfind->flags & GPATH_NEARSORT) { const char *path = NULL; VARRAY *varray = varray_open(sizeof(char *), 100); POOL *pool = pool_open(); while ((path = gfind_read(gfind)) != NULL) { char **a = varray_append(varray); *a = pool_strdup(pool, path, 0); } if ((nearbase = get_nearbase_path()) == NULL) die("cannot get nearbase path."); qsort(varray_assign(varray, 0, 0), varray->length, sizeof(char *), compare_nearpath); gfind->path_array = varray; gfind->pool = pool; gfind->index = 0; } return gfind; }
NSAPI_PUBLIC char* vs_translate_uri(const VirtualServer* vs, const char* uri) { PR_ASSERT(vs); if (!vs) return NULL; // Establish an environment suitable for invoking SAFs NSAPIEnvironment nsapi(vs, uri); if (!nsapi.isValid()) return NULL; // Call the NameTrans SAFs char* path = NULL; if (servact_objset_uri2path(nsapi.sn, nsapi.rq, nsapi.objset) == REQ_PROCEED) { path = pblock_findkeyval(pb_key_path, nsapi.rq->vars); if (path) path = pool_strdup(nsapi.poolCaller, path); } return path; }
char *Result::getPooledString(pool_handle_t *dst) const { if (type == RESULT_ERROR) return pool_strdup(dst, ""); // If the caller's pool is the pool the string was allocated from... if (dst == pool && pool != NULL) { // We're cool with giving the caller a non-const pointer into his own // pool. This eliminates an unnecessary copy. return (char *) s; } // The string is a constant or was allocated from some other pool. Create // a copy in the caller's pool. char *p = (char *) pool_malloc(dst, len + 1); if (p != NULL) { memcpy(p, s, len); p[len] = '\0'; } return p; }
/****************************************************************** * macho_stabs_def_cb * * Callback for stabs_parse. Collect symbol definitions. */ static void macho_stabs_def_cb(struct module* module, unsigned long load_offset, const char* name, unsigned long offset, BOOL is_public, BOOL is_global, unsigned char sectidx, struct symt_compiland* compiland, void* user) { struct macho_debug_info* mdi = user; struct symtab_elt* ste; TRACE("(%p, 0x%08lx, %s, 0x%08lx, %d, %d, %u, %p, %p/%p/%d)\n", module, load_offset, debugstr_a(name), offset, is_public, is_global, sectidx, compiland, mdi, mdi->fmap, mdi->fmap->fd); /* Defer the creation of new non-debugging symbols until after we've * finished parsing the stabs. */ ste = pool_alloc(&mdi->pool, sizeof(*ste)); ste->ht_elt.name = pool_strdup(&mdi->pool, name); ste->compiland = compiland; ste->addr = load_offset + offset; ste->is_code = !!macho_sect_is_code(mdi->fmap, sectidx); ste->is_public = !!is_public; ste->is_global = !!is_global; ste->used = 0; hash_table_add(&mdi->ht_symtab, &ste->ht_elt); }
NSAPI_PUBLIC char* vs_get_mime_type(const VirtualServer* vs, const char* uri) { PR_ASSERT(vs); if (!vs) return NULL; // Establish an environment suitable for invoking SAFs NSAPIEnvironment nsapi(vs, uri); if (!nsapi.isValid()) return NULL; // Call the NameTrans SAFs char* type = NULL; if (servact_objset_uri2path(nsapi.sn, nsapi.rq, nsapi.objset) == REQ_PROCEED) { // Call the ObjectType SAFs if (servact_fileinfo(nsapi.sn, nsapi.rq) == REQ_PROCEED) { type = pblock_findkeyval(pb_key_content_type, nsapi.rq->srvhdrs); if (type) type = pool_strdup(nsapi.poolCaller, type); } } return type; }
/* * strhash_assign: assign hash entry. * * i) sh STRHASH structure * i) name name * i) force if entry not found, create it. * r) pointer of the entry * * If specified entry is found then it is returned, else if the force == 1 * then new allocated entry is returned. * This procedure doesn't operate the contents of entry->value. */ struct sh_entry * strhash_assign(STRHASH *sh, const char *name, int force) { struct sh_head *head = &sh->htab[__hash_string(name) % sh->buckets]; struct sh_entry *entry; /* * Lookup the name's entry. */ SLIST_FOREACH(entry, head, ptr) if (strcmp(entry->name, name) == 0) break; /* * If not found, allocate an entry. */ if (entry == NULL && force) { entry = pool_malloc(sh->pool, sizeof(struct sh_entry)); entry->name = pool_strdup(sh->pool, name, 0); entry->value = NULL; SLIST_INSERT_HEAD(head, entry, ptr); sh->entries++; } return entry; }
/* LASDNSBuild * Builds a hash table of all the hostnames provided (plus their aliases * if aliasflg is true). Wildcards are only permitted in the leftmost * field. They're represented in the hash table by a leading period. * E.g. ".mcom.com". * * RETURNS Zero on success, else LAS_EVAL_INVALID */ int LASDnsBuild(NSErr_t *errp, char *attr_pattern, LASDnsContext_t *context, int aliasflg) { size_t delimiter; /* length of valid tokeni */ char token[256]; /* max length dns name */ int i; char **p; pool_handle_t *pool; PRStatus error=PR_SUCCESS; char buffer[PR_NETDB_BUF_SIZE]; #ifdef UTEST struct hostent *he, host; #else PRHostEnt *he, host; #endif char *end_attr_pattern; if (attr_pattern == NULL) { nserrGenerate(errp, ACLERRINVAL, ACLERR4770, ACL_Program, 1, XP_GetAdminStr(DBT_lasdnsbuildInvalidAttributePattern_)); return LAS_EVAL_INVALID; } context->Table = PR_NewHashTable(0, PR_HashCaseString, PR_CompareCaseStrings, PR_CompareValues, &ACLPermAllocOps, NULL); pool = pool_create(); context->pool = pool; if ((!context->Table) || (!context->pool)) { nserrGenerate(errp, ACLERRNOMEM, ACLERR4700, ACL_Program, 1, XP_GetAdminStr(DBT_lasdnsbuildUnableToAllocateHashT_)); return LAS_EVAL_INVALID; } end_attr_pattern = attr_pattern + strlen(attr_pattern); do { size_t maxsize = sizeof(token); /* Get a single hostname from the pattern string */ delimiter = strcspn(attr_pattern, ", \t"); if (delimiter >= maxsize) { delimiter = maxsize-1; } PL_strncpyz(token, attr_pattern, delimiter + 1); token[delimiter] = '\0'; /* Skip any white space after the token */ attr_pattern += delimiter; if (attr_pattern < end_attr_pattern) { attr_pattern += strspn(attr_pattern, ", \t"); } /* If there's a wildcard, strip it off but leave the "." * Can't have aliases for a wildcard pattern. * Treat "*" as a special case. If so, go ahead and hash it. */ if (token[0] == '*') { if (token[1] != '\0') { if (!PR_HashTableAdd(context->Table, pool_strdup(pool, &token[1]), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4710, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token); return LAS_EVAL_INVALID; } } else { if (!PR_HashTableAdd(context->Table, pool_strdup(pool, token), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4720, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token); return LAS_EVAL_INVALID; } } } else { /* This is a single hostname add it to the hash table */ if (!PR_HashTableAdd(context->Table, pool_strdup(pool, &token[0]), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4730, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token); return LAS_EVAL_INVALID; } if (aliasflg) { void *iter = NULL; int addrcnt = 0; PRNetAddr *netaddr = (PRNetAddr *)PERM_CALLOC(sizeof(PRNetAddr)); PRAddrInfo *infop = PR_GetAddrInfoByName(token, PR_AF_UNSPEC, (PR_AI_ADDRCONFIG|PR_AI_NOCANONNAME)); if (!netaddr) { if (infop) { PR_FreeAddrInfo(infop); } return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */ } if (!infop) { if (netaddr) { PERM_FREE(netaddr); } return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */ } /* need to count the address, first */ while ((iter = PR_EnumerateAddrInfo(iter, infop, 0, netaddr))) { addrcnt++; } if (0 == addrcnt) { PERM_FREE(netaddr); PR_FreeAddrInfo(infop); return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */ } iter = NULL; /* from the beginning */ memset(netaddr, 0, sizeof(PRNetAddr)); for (i = 0; i < addrcnt; i++) { iter = PR_EnumerateAddrInfo( iter, infop, 0, netaddr ); if (NULL == iter) { break; } error = PR_GetHostByAddr(netaddr, buffer, PR_NETDB_BUF_SIZE, &host); if (error == PR_SUCCESS) { he = &host; } else { continue; } if (he->h_name) { /* Add it to the hash table */ if (!PR_HashTableAdd(context->Table, pool_strdup(pool, he->h_name), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4750, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), he->h_name); PERM_FREE(netaddr); PR_FreeAddrInfo(infop); return LAS_EVAL_INVALID; } } if (he->h_aliases && he->h_aliases[0]) { for (p = he->h_aliases; *p; ++p) { /* Add it to the hash table */ if (!PR_HashTableAdd(context->Table, pool_strdup(pool, *p), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4760, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), *p); PERM_FREE(netaddr); PR_FreeAddrInfo(infop); return LAS_EVAL_INVALID; } } } } /* for (i = 0; i < addrcnt; i++) */ PERM_FREE(netaddr); PR_FreeAddrInfo(infop); } /* if aliasflg */ } /* else - single hostname */ } while ((attr_pattern != NULL) && (attr_pattern[0] != '\0') && (delimiter != 0)); return 0; }
/* * strhash_strdup: allocate memory and copy string. * * i) sh STRHASH structure * i) string string * i) size size of string * r) allocated string * */ char * strhash_strdup(STRHASH *sh, const char *string, int size) { return pool_strdup(sh->pool, string, size); }
/* flushing is only supported in iPlanet servers from version 6.1 on, make it conditional */ #if NSAPI_VERSION >= 302 if (net_flush(rc->sn->csd) < 0) { php_handle_aborted_connection(); } #endif } /* callback for zend_llist_apply on SAPI_HEADER_DELETE_ALL operation */ static int php_nsapi_remove_header(sapi_header_struct *sapi_header TSRMLS_DC) { char *header_name, *p; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); /* copy the header, because NSAPI needs reformatting and we do not want to change the parameter */ header_name = pool_strdup(rc->sn->pool, sapi_header->header); /* extract name, this works, if only the header without ':' is given, too */ if (p = strchr(header_name, ':')) { *p = 0; } /* header_name to lower case because NSAPI reformats the headers and wants lowercase */ for (p=header_name; *p; p++) { *p=tolower(*p); } /* remove the header */ param_free(pblock_remove(header_name, rc->rq->srvhdrs)); pool_free(rc->sn->pool, header_name);
NSAPI_PUBLIC int PListNameProp(PList_t plist, int pindex, const char *pname) { PListStruct_t *pl = (PListStruct_t *)plist; PLValueStruct_t *pv; PLSymbolTable_t *pt; int i; if (!plist) return ERRPLUNDEF; pt = pl->pl_symtab; /* Check for valid property index */ if ((pindex > 0) && (pindex <= pl->pl_initpi)) { /* Does the property exist? */ pv = ((PLValueStruct_t **)(pl->pl_ppval))[pindex - 1]; if (pv) { /* If it has a name already, unname it */ if (pv->pv_name) { PLValueStruct_t **pvp; /* Get hash bucket index */ i = PListHashName(pt, pv->pv_name); /* Seach hash collision list for this property */ for (pvp = &pt->pt_hash[i]; *pvp; pvp = &(*pvp)->pv_next) { if (*pvp == pv) { /* Remove it from the list */ *pvp = pv->pv_next; break; } } /* Free the current name string */ pool_free(pl->pl_mempool, (void *)(pv->pv_name)); } /* Got a new name? */ if (pname) { /* Yes, is there a hash table? */ if (!pt) { /* No, create one */ pt = (PLSymbolTable_t *)pool_calloc(pl->pl_mempool, 1, PLHASHSIZE(0)); if (!pt) { return ERRPLNOMEM; } pl->pl_symtab = pt; } else { /* Is it time to grow the hash table? */ i = PLSIZENDX(pt->pt_sizendx); /* cannot allow pt->pt_sizendx == PLMAXSIZENDX */ if (((size_t)(pt->pt_sizendx + 1) < PLMAXSIZENDX) && pt->pt_nsyms >= (i + i)) { PLSymbolTable_t *npt; /* Yes, allocate the new table */ npt = (PLSymbolTable_t *)pool_calloc(pl->pl_mempool, 1, PLHASHSIZE(pt->pt_sizendx+1)); if (npt) { PLValueStruct_t *opv; PLValueStruct_t *npv; int j; npt->pt_sizendx = pt->pt_sizendx + 1; npt->pt_nsyms = pt->pt_nsyms; /* Rehash all the names into the new table */ for (i = 0; i < PLSIZENDX(pt->pt_sizendx); ++i) { for (opv = pt->pt_hash[i]; opv; opv = npv) { npv = opv->pv_next; j = PListHashName(npt, opv->pv_name); opv->pv_next = npt->pt_hash[j]; npt->pt_hash[j] = opv; } } pl->pl_symtab = npt; /* Free the old symbol table */ pool_free(pl->pl_mempool, (void *)pt); pt = npt; } } } /* Duplicate the name string */ pv->pv_name = pool_strdup(pl->pl_mempool, (char *)pname); /* Add name to symbol table */ i = PListHashName(pt, pname); pv->pv_next = pt->pt_hash[i]; pt->pt_hash[i] = pv; } /* Successful return */ return pindex; } } /* Error - invalid property index or non-existent property */ return ERRPLINVPI; }
char *image_strdup(mess_image *image, const char *src) { assert(is_loaded(image) || image->is_loading); return pool_strdup(&image->mempool, src); }
/* * fcomp */ static int fcomp(sed_commands_t *commands, PRFileDesc *fin) { char *p, *op, *tp; sed_reptr_t *pt, *pt1; int i, ii; sed_label_t *lpt; char fnamebuf[PATH_MAX]; PRStatus status; sed_comp_args compargs; op = commands->lastre; if (!commands->linebuf) { commands->linebuf = (char *)pool_calloc(commands->pool, LBSIZE + 1, 1); } if (rline(commands, fin, commands->linebuf, (commands->linebuf + LBSIZE + 1)) < 0) return 0; if (*commands->linebuf == '#') { if (commands->linebuf[1] == 'n') commands->nflag = 1; } else { commands->cp = commands->linebuf; goto comploop; } for (;;) { if (rline(commands, fin, commands->linebuf, (commands->linebuf + LBSIZE + 1)) < 0) break; commands->cp = commands->linebuf; comploop: while (*commands->cp == ' ' || *commands->cp == '\t') commands->cp++; if (*commands->cp == '\0' || *commands->cp == '#') continue; if (*commands->cp == ';') { commands->cp++; goto comploop; } p = address(commands, commands->rep->ad1, &status); if (status != PR_SUCCESS) { command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf); return -1; } if (p == commands->rep->ad1) { if (op) commands->rep->ad1 = op; else { command_errf(commands, XP_GetAdminStr(DBT_NRMES)); return -1; } } else if (p == 0) { p = commands->rep->ad1; commands->rep->ad1 = 0; } else { op = commands->rep->ad1; if (*commands->cp == ',' || *commands->cp == ';') { commands->cp++; commands->rep->ad2 = p; p = address(commands, commands->rep->ad2, &status); if ((status != PR_SUCCESS) || (p == 0)) { command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf); return -1; } if (p == commands->rep->ad2) commands->rep->ad2 = op; else op = commands->rep->ad2; } else commands->rep->ad2 = 0; } if(p > &commands->respace[RESIZE-1]) { command_errf(commands, XP_GetAdminStr(DBT_TMMES)); return -1; } while (*commands->cp == ' ' || *commands->cp == '\t') commands->cp++; swit: switch(*commands->cp++) { default: command_errf(commands, XP_GetAdminStr(DBT_UCMES), commands->linebuf); return -1; case '!': commands->rep->negfl = 1; goto swit; case '{': commands->rep->command = BCOM; commands->rep->negfl = !(commands->rep->negfl); commands->cmpend[commands->depth++] = &commands->rep->lb1; commands->rep = alloc_reptr(commands); commands->rep->ad1 = p; if (*commands->cp == '\0') continue; goto comploop; case '}': if (commands->rep->ad1) { command_errf(commands, XP_GetAdminStr(DBT_AD0MES), commands->linebuf); return -1; } if (--commands->depth < 0) { command_errf(commands, XP_GetAdminStr(DBT_TMCMES)); return -1; } *commands->cmpend[commands->depth] = commands->rep; commands->rep->ad1 = p; continue; case '=': commands->rep->command = EQCOM; if (commands->rep->ad2) { command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf); return -1; } break; case ':': if (commands->rep->ad1) { command_errf(commands, XP_GetAdminStr(DBT_AD0MES), commands->linebuf); return -1; } while (*commands->cp++ == ' '); commands->cp--; tp = commands->lab->asc; while ((*tp++ = *commands->cp++)) { if (tp >= &(commands->lab->asc[8])) { command_errf(commands, XP_GetAdminStr(DBT_LTLMES), commands->linebuf); return -1; } } *--tp = '\0'; if ((lpt = search(commands)) != NULL) { if (lpt->address) { command_errf(commands, XP_GetAdminStr(DBT_DLMES), commands->linebuf); return -1; } dechain(lpt, commands->rep); } else { commands->lab->chain = 0; lpt = commands->lab; if (++commands->lab >= commands->labend) { command_errf(commands, XP_GetAdminStr(DBT_TMLMES), commands->linebuf); return -1; } } lpt->address = commands->rep; commands->rep->ad1 = p; continue; case 'a': commands->rep->command = ACOM; if (commands->rep->ad2) { command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf); return -1; } if (*commands->cp == '\\') commands->cp++; if (*commands->cp++ != '\n') { command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf); return -1; } commands->rep->re1 = p; p = text(commands, commands->rep->re1, commands->reend); if (p == NULL) return -1; break; case 'c': commands->rep->command = CCOM; if (*commands->cp == '\\') commands->cp++; if (*commands->cp++ != ('\n')) { command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf); return -1; } commands->rep->re1 = p; p = text(commands, commands->rep->re1, commands->reend); if (p == NULL) return -1; break; case 'i': commands->rep->command = ICOM; if (commands->rep->ad2) { command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf); return -1; } if (*commands->cp == '\\') commands->cp++; if (*commands->cp++ != ('\n')) { command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf); return -1; } commands->rep->re1 = p; p = text(commands, commands->rep->re1, commands->reend); if (p == NULL) return -1; break; case 'g': commands->rep->command = GCOM; break; case 'G': commands->rep->command = CGCOM; break; case 'h': commands->rep->command = HCOM; break; case 'H': commands->rep->command = CHCOM; break; case 't': commands->rep->command = TCOM; goto jtcommon; case 'b': commands->rep->command = BCOM; jtcommon: while (*commands->cp++ == ' '); commands->cp--; if (*commands->cp == '\0') { if ((pt = commands->labtab->chain) != NULL) { while ((pt1 = pt->lb1) != NULL) pt = pt1; pt->lb1 = commands->rep; } else commands->labtab->chain = commands->rep; break; } tp = commands->lab->asc; while ((*tp++ = *commands->cp++)) if (tp >= &(commands->lab->asc[8])) { command_errf(commands, XP_GetAdminStr(DBT_LTLMES), commands->linebuf); return -1; } commands->cp--; *--tp = '\0'; if ((lpt = search(commands)) != NULL) { if (lpt->address) { commands->rep->lb1 = lpt->address; } else { pt = lpt->chain; while ((pt1 = pt->lb1) != NULL) pt = pt1; pt->lb1 = commands->rep; } } else { commands->lab->chain = commands->rep; commands->lab->address = 0; if (++commands->lab >= commands->labend) { command_errf(commands, XP_GetAdminStr(DBT_TMLMES), commands->linebuf); return -1; } } break; case 'n': commands->rep->command = NCOM; break; case 'N': commands->rep->command = CNCOM; break; case 'p': commands->rep->command = PCOM; break; case 'P': commands->rep->command = CPCOM; break; case 'r': commands->rep->command = RCOM; if (commands->rep->ad2) { command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf); return -1; } if (*commands->cp++ != ' ') { command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf); return -1; } commands->rep->re1 = p; p = text(commands, commands->rep->re1, commands->reend); if (p == NULL) return -1; break; case 'd': commands->rep->command = DCOM; break; case 'D': commands->rep->command = CDCOM; commands->rep->lb1 = commands->ptrspace; break; case 'q': commands->rep->command = QCOM; if (commands->rep->ad2) { command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf); return -1; } break; case 'l': commands->rep->command = LCOM; break; case 's': commands->rep->command = SCOM; commands->sseof = *commands->cp++; commands->rep->re1 = p; p = comple(commands, &compargs, (char *) 0, commands->rep->re1, commands->reend, commands->sseof); if (p == NULL) return -1; if (p == commands->rep->re1) { if (op) commands->rep->re1 = op; else { command_errf(commands, XP_GetAdminStr(DBT_NRMES)); return -1; } } else op = commands->rep->re1; commands->rep->rhs = p; p = compsub(commands, &compargs, commands->rep->rhs); if ((p) == NULL) return -1; if (*commands->cp == 'g') { commands->cp++; commands->rep->gfl = 999; } else if (commands->gflag) commands->rep->gfl = 999; if (*commands->cp >= '1' && *commands->cp <= '9') { i = *commands->cp - '0'; commands->cp++; while (1) { ii = *commands->cp; if (ii < '0' || ii > '9') break; i = i*10 + ii - '0'; if (i > 512) { command_errf(commands, XP_GetAdminStr(DBT_TOOBIG), commands->linebuf); return -1; } commands->cp++; } commands->rep->gfl = i; } if (*commands->cp == 'p') { commands->cp++; commands->rep->pfl = 1; } if (*commands->cp == 'P') { commands->cp++; commands->rep->pfl = 2; } if (*commands->cp == 'w') { commands->cp++; if (*commands->cp++ != ' ') { command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf); return -1; } if (text(commands, fnamebuf, &fnamebuf[PATH_MAX]) == NULL) { command_errf(commands, XP_GetAdminStr(DBT_FNTL), commands->linebuf); return -1; } for (i = commands->nfiles - 1; i >= 0; i--) if (strcmp(fnamebuf,commands->fname[i]) == 0) { commands->rep->findex = i; goto done; } if (commands->nfiles >= NWFILES) { command_errf(commands, XP_GetAdminStr(DBT_TMWFMES)); return -1; } commands->fname[commands->nfiles] = (char *) pool_strdup(commands->pool, (const char *)fnamebuf); if (commands->fname[commands->nfiles] == NULL) { command_errf(commands, XP_GetAdminStr(DBT_OOMMES)); return -1; } commands->rep->findex = commands->nfiles++; } break; case 'w': commands->rep->command = WCOM; if (*commands->cp++ != ' ') { command_errf(commands, XP_GetAdminStr(DBT_SMMES), commands->linebuf); return -1; } if (text(commands, fnamebuf, &fnamebuf[PATH_MAX]) == NULL) { command_errf(commands, XP_GetAdminStr(DBT_FNTL), commands->linebuf); return -1; } for (i = commands->nfiles - 1; i >= 0; i--) if (strcmp(fnamebuf, commands->fname[i]) == 0) { commands->rep->findex = i; goto done; } if (commands->nfiles >= NWFILES) { command_errf(commands, XP_GetAdminStr(DBT_TMWFMES)); return -1; } if ((commands->fname[commands->nfiles] = (char *)pool_strdup(commands->pool, fnamebuf)) == NULL) { command_errf(commands, XP_GetAdminStr(DBT_OOMMES)); return -1; } commands->rep->findex = commands->nfiles++; break; case 'x': commands->rep->command = XCOM; break; case 'y': commands->rep->command = YCOM; commands->sseof = *commands->cp++; commands->rep->re1 = p; p = ycomp(commands, commands->rep->re1); if (p == NULL) return -1; break; } done: commands->rep = alloc_reptr(commands); commands->rep->ad1 = p; if (*commands->cp++ != '\0') { if (commands->cp[-1] == ';') goto comploop; command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf); return -1; } } commands->rep->command = 0; commands->lastre = op; return 0; }
char *imgtool_library_strdup(imgtool_library *library, const char *s) { return s ? pool_strdup(&library->pool, s) : NULL; }
char *image_strdup(mess_image *img, const char *src) { assert(img->status & (IMAGE_STATUS_ISLOADING | IMAGE_STATUS_ISLOADED)); return pool_strdup(&img->mempool, src); }
NSAPI_PUBLIC int PListNameProp(PList_t plist, int pindex, const char *pname) { PListStruct_t *pl = (PListStruct_t *)plist; PLValueStruct_t *pv; PLSymbolTable_t *pt; int i; if (!plist) return ERRPLUNDEF; pt = pl->pl_symtab; /* Check for valid property index */ if ((pindex > 0) && (pindex <= pl->pl_initpi)) { /* Does the property exist? */ pv = ((PLValueStruct_t **)(pl->pl_ppval))[pindex - 1]; if (pv) { /* If it has a name already, unname it */ if (pv->pv_name) { PLValueStruct_t **pvp; /* Get hash bucket index */ i = PListHashName(pt, pv->pv_name); /* Seach hash collision list for this property */ for (pvp = &pt->pt_hash[i]; *pvp; pvp = &(*pvp)->pv_next) { if (*pvp == pv) { /* Remove it from the list */ *pvp = pv->pv_next; pt->pt_nsyms--; break; } } /* Free the current name string */ pool_free(pv->pv_mempool, (void *)(pv->pv_name)); } /* Got a new name? */ if (pname) { /* Allocate/grow the symbol table as needed */ pt = PListSymbolTable(pl); if (!pt) { return ERRPLNOMEM; } /* Duplicate the name string */ pv->pv_name = pool_strdup(pv->pv_mempool, (char *)pname); /* Add name to symbol table */ i = PListHashName(pt, pname); pv->pv_next = pt->pt_hash[i]; pt->pt_hash[i] = pv; pt->pt_nsyms++; } /* Successful return */ return pindex; } } /* Error - invalid property index or non-existent property */ return ERRPLINVPI; }
NSAPI_PUBLIC char* vs_get_doc_root(const VirtualServer* vs) { PR_ASSERT(vs); if (!vs) return NULL; // Establish an environment suitable for invoking SAFs NSAPIEnvironment nsapi(vs, "/"); if (!nsapi.isValid()) return NULL; // Call the NameTrans SAFs char* docroot = NULL; if (servact_objset_uri2path(nsapi.sn, nsapi.rq, nsapi.objset) == REQ_PROCEED) { docroot = pblock_findkeyval(pb_key_ntrans_base, nsapi.rq->vars); if (!docroot) { // Nobody set ntrans-base; try stripping the filename off the path // variable instead char* path = pblock_findkeyval(pb_key_path, nsapi.rq->vars); if (path && file_is_path_abs(path)) { int len = strlen(path); while (len > 1 && path[len - 1] != '/') len--; docroot = (char*)MALLOC(len + 1); if (docroot) { memcpy(docroot, path, len); docroot[len] = '\0'; } } } } // XXX If NameTrans failed to return a document root (e.g. there's a // NameTrans fn=redirect url-prefix=/ directive), look for a NameTrans // fn=document-root directive in obj.conf if (!docroot) { httpd_objset *objset = nsapi.rq->os; if (!objset) objset = nsapi.objset; docroot = find_document_root_directive(objset); if (docroot) { char* t = vs_substitute_vars(vs, docroot); if (t) docroot = t; } } // Make a copy of the document root in the caller's MALLOC pool, stripping // any trailing slash if (docroot) { docroot = pool_strdup(nsapi.poolCaller, docroot); int len = strlen(docroot); if (len > 1 && docroot[len - 1] == '/') docroot[len - 1] = '\0'; return docroot; } // We couldn't find a document root using NSAPI, so use the <document-root> // value from server.xml. We treat this as a last resort because it // defaults to ../docs. return pool_strdup(nsapi.poolCaller, vs->getNormalizedDocumentRoot().data()); }