static void pageloadproc(void *v) { Page *p; char buf[BUFSIZE], *s; long n, l; int fd, i, ctype; threadsetname("pageloadproc"); rfork(RFFDG); p = v; addrefresh(p, "opening: %S...", p->url->src.r); fd = urlopen(p->url); if(fd < 0){ addrefresh(p, "%S: %r", p->url->src.r); Err: p->loading = FALSE; return; } if(runestrlen(p->url->ctype.r) == 0) /* assume .html when headers don't say anyting */ goto Html; snprint(buf, sizeof(buf), "%S", p->url->ctype.r); for(i=0; mimetab[i]!=nil; i++) if(cistrncmp(buf, mimetab[i], strlen(mimetab[i])) == 0) break; if(mimetab[i]){ Html: ctype = TextHtml; }else if(cistrncmp(buf, "text/", 5) == 0) ctype = TextPlain; else{ close(fd); addrefresh(p, "%S: unsupported mime type: '%S'", p->url->act.r, p->url->ctype.r); goto Err; } addrefresh(p, "loading: %S...", p->url->src.r); s = nil; l = 0; while((n=read(fd, buf, sizeof(buf))) > 0){ if(p->aborting){ if(s){ free(s); s = nil; } break; } s = erealloc(s, l+n+1); memmove(s+l, buf, n); l += n; s[l] = '\0'; } close(fd); n = l; if(s){ s = convert(p->url->ctype, s, &n); p->items = parsehtml((uchar *)s, n, p->url->act.r, ctype, UTF_8, &p->doc); free(s); fixtext(p); if(ctype==TextHtml && p->aborting==FALSE){ p->changed = TRUE; addrefresh(p, ""); if(p->doc->doctitle){ p->title.r = erunestrdup(p->doc->doctitle); p->title.nr = runestrlen(p->title.r); } p->loading = XXX; if(p->doc->kidinfo) loadchilds(p, p->doc->kidinfo); else if(p->doc->images) loadimages(p); } } p->changed = TRUE; p->loading = FALSE; addrefresh(p, ""); }
Document* initps(Biobuf *b, int argc, char **argv, uint8_t *buf, int nbuf) { Document *d; PSInfo *ps; char *p; char *q, *r; char eol; char *nargv[1]; char fdbuf[20]; char tmp[32]; int fd; int i; int incomments; int cantranslate; int trailer=0; int nesting=0; int dumb=0; int landscape=0; int32_t psoff; int32_t npage, mpage; Page *page; Rectangle bbox = Rect(0,0,0,0); if(argc > 1) { fprint(2, "can only view one ps file at a time\n"); return nil; } fprint(2, "reading through postscript...\n"); if(b == nil){ /* standard input; spool to disk (ouch) */ fd = spooltodisk(buf, nbuf, nil); sprint(fdbuf, "/fd/%d", fd); b = Bopen(fdbuf, OREAD); if(b == nil){ fprint(2, "cannot open disk spool file\n"); wexits("Bopen temp"); } nargv[0] = fdbuf; argv = nargv; } /* find %!, perhaps after PCL nonsense */ Bseek(b, 0, 0); psoff = 0; eol = 0; for(i=0; i<16; i++){ psoff = Boffset(b); if(!(p = Brdline(b, eol='\n')) && !(p = Brdline(b, eol='\r'))) { fprint(2, "cannot find end of first line\n"); wexits("initps"); } if(p[0]=='\x1B') p++, psoff++; if(p[0] == '%' && p[1] == '!') break; } if(i == 16){ werrstr("not ps"); return nil; } /* page counting */ npage = 0; mpage = 16; page = emalloc(mpage*sizeof(*page)); memset(page, 0, mpage*sizeof(*page)); cantranslate = goodps; incomments = 1; Keepreading: while(p = Brdline(b, eol)) { if(p[0] == '%') if(chatty > 1) fprint(2, "ps %.*s\n", utfnlen(p, Blinelen(b)-1), p); if(npage == mpage) { mpage *= 2; page = erealloc(page, mpage*sizeof(*page)); memset(&page[npage], 0, npage*sizeof(*page)); } if(p[0] != '%' || p[1] != '%') continue; if(prefix(p, "%%BeginDocument")) { nesting++; continue; } if(nesting > 0 && prefix(p, "%%EndDocument")) { nesting--; continue; } if(nesting) continue; if(prefix(p, "%%EndComment")) { incomments = 0; continue; } if(reverse == -1 && prefix(p, "%%PageOrder")) { /* glean whether we should reverse the viewing order */ p[Blinelen(b)-1] = 0; if(strstr(p, "Ascend")) reverse = 0; else if(strstr(p, "Descend")) reverse = 1; else if(strstr(p, "Special")) dumb = 1; p[Blinelen(b)-1] = '\n'; continue; } else if(prefix(p, "%%Trailer")) { incomments = 1; page[npage].offset = Boffset(b)-Blinelen(b); trailer = 1; continue; } else if(incomments && prefix(p, "%%Orientation")) { if(strstr(p, "Landscape")) landscape = 1; } else if(incomments && Dx(bbox)==0 && prefix(p, q="%%BoundingBox")) { bbox = rdbbox(p+strlen(q)+1); if(chatty) /* can't use %R because haven't initdraw() */ fprint(2, "document bbox [%d %d %d %d]\n", RECT(bbox)); continue; } /* * If they use the initgraphics command, we can't play our translation tricks. */ p[Blinelen(b)-1] = 0; if((q=strstr(p, "initgraphics")) && ((r=strchr(p, '%'))==nil || r > q)) cantranslate = 0; p[Blinelen(b)-1] = eol; if(!prefix(p, "%%Page:")) continue; /* * figure out of the %%Page: line contains a page number * or some other page description to use in the menu bar. * * lines look like %%Page: x y or %%Page: x * we prefer just x, and will generate our * own if necessary. */ p[Blinelen(b)-1] = 0; if(chatty) fprint(2, "page %s\n", p); r = p+7; while(*r == ' ' || *r == '\t') r++; q = r; while(*q && *q != ' ' && *q != '\t') q++; free(page[npage].name); if(*r) { if(*r == '"' && *q == '"') r++, q--; if(*q) *q = 0; page[npage].name = estrdup(r); *q = 'x'; } else { snprint(tmp, sizeof tmp, "p %ld", npage+1); page[npage].name = estrdup(tmp); } /* * store the offset info for later viewing */ trailer = 0; p[Blinelen(b)-1] = eol; page[npage++].offset = Boffset(b)-Blinelen(b); } if(Blinelen(b) > 0){ fprint(2, "page: linelen %d\n", Blinelen(b)); Bseek(b, Blinelen(b), 1); goto Keepreading; } if(Dx(bbox) == 0 || Dy(bbox) == 0) bbox = Rect(0,0,612,792); /* 8½×11 */ /* * if we didn't find any pages, assume the document * is one big page */ if(npage == 0) { dumb = 1; if(chatty) fprint(2, "don't know where pages are\n"); reverse = 0; goodps = 0; trailer = 0; page[npage].name = "p 1"; page[npage++].offset = 0; } if(npage+2 > mpage) { mpage += 2; page = erealloc(page, mpage*sizeof(*page)); memset(&page[mpage-2], 0, 2*sizeof(*page)); } if(!trailer) page[npage].offset = Boffset(b); Bseek(b, 0, 2); /* EOF */ page[npage+1].offset = Boffset(b); d = emalloc(sizeof(*d)); ps = emalloc(sizeof(*ps)); ps->page = page; ps->npage = npage; ps->bbox = bbox; ps->psoff = psoff; d->extra = ps; d->npage = ps->npage; d->b = b; d->drawpage = psdrawpage; d->pagename = pspagename; d->fwdonly = ps->clueless = dumb; d->docname = argv[0]; if(spawngs(ps, "-dSAFER") < 0) return nil; if(!cantranslate) bbox.min = ZP; setdim(ps, bbox, ppi, landscape); if(goodps){ /* * We want to only send the page (i.e. not header and trailer) information * for each page, so initialize the device by sending the header now. */ pswritepage(d, ps->gsfd, -1); waitgs(ps); } if(dumb) { fprint(ps->gsfd, "(%s) run\n", argv[0]); fprint(ps->gsfd, "(/fd/3) (w) file dup (THIS IS NOT A PLAN9 BITMAP 01234567890123456789012345678901234567890123456789\\n) writestring flushfile\n"); } ps->bbox = bbox; return d; }
void main(int argc, char **argv) { Biobuf bio; char *p, *f[10]; int bitmap, c, nf, resolution, n8, n16, hdr, nhdr, nlhdr, nleak, x, y, nb; ulong allocstart, allocend, len, u; Data *d, *ed; Block *b, *eb; bitmap = 0; resolution = 8; x = 512; ARGBEGIN{ case 'b': bitmap=1; break; case 'r': resolution = atoi(EARGF(sysfatal("usage"))); break; case 'x': x = atoi(EARGF(sysfatal("usage"))); break; }ARGEND n8 = n16 = 0; allocstart = allocend = 0; Binit(&bio, 0, OREAD); while(p=Brdline(&bio, '\n')) { p[Blinelen(&bio)-1] = '\0'; nf = tokenize(p, f, nelem(f)); if(nf >= 4 && strcmp(f[0], "data") == 0) { if(ndata%64==0) data = erealloc(data, (ndata+64)*sizeof(Data)); data[ndata].addr = strtoul(f[1], nil, 0); data[ndata].val = strtoul(f[2], nil, 0); data[ndata].type = f[3][0]; data[ndata].b = 0; ndata++; } if(nf >= 5 && (strcmp(f[0], "block") == 0 || strcmp(f[0], "free") == 0)) { if(nblock%64 == 0) block = erealloc(block, (nblock+64)*sizeof(Block)); block[nblock].addr = strtoul(f[1], nil, 0); block[nblock].size = strtoul(f[2], nil, 0); block[nblock].w0 = strtoul(f[3], nil, 0); block[nblock].w1 = strtoul(f[4], nil, 0); if (nf >= 7) { block[nblock].s0 = estrdup(f[5]); block[nblock].s1 = estrdup(f[6]); } else { block[nblock].s0 = ""; block[nblock].s1 = ""; } block[nblock].mark = 0; block[nblock].d = 0; block[nblock].free = strcmp(f[0], "free") == 0; nblock++; } if(nf >= 4 && strcmp(f[0], "range") == 0 && strcmp(f[1], "alloc") == 0) { allocstart = strtoul(f[2], 0, 0)&~15; allocend = strtoul(f[3], 0, 0); } } qsort(block, nblock, sizeof(Block), addrcmp); qsort(data, ndata, sizeof(Data), addrcmp); ed = edata = data+ndata; for(d=data; d<ed; d++) { if(d->type == 'a') continue; if(b = findblock(d->val-8)) // pool header 2 words n8 += markblock(d->addr, d->val, b); else if(b = findblock(d->val-8-8)) // sometimes malloc header 2 words n16 += markblock(d->addr, d->val, b); else {}//print("noblock %.8lux\n", d->val); } Binit(&bio, 1, OWRITE); if(bitmap){ if(n8 > n16) // guess size of header hdr = 8; else hdr = 16; for(d=data; d<ed; d++) if(d->type=='a') break; if(d==ed) sysfatal("no allocated data region"); len = (allocend-allocstart+resolution-1)/resolution; y = (len+x-1)/x; Bprint(&bio, "%11s %11d %11d %11d %11d ", "m8", 0, 0, x, y); //fprint(2, "alloc %lux %lux x %d y %d res %d\n", allocstart, allocend, x, y, resolution); b = block; eb = block+nblock; for(u = allocstart; u<allocend; u+=resolution){ //fprint(2, "u %lux %lux baddr %lux\n", u, u+resolution, b->addr); while(b->addr+b->size <= u && b < eb) //{ //fprint(2, "\tskip %lux %lux\n", b->addr, b->addr+b->size); b++; //} nhdr = 0; nleak = 0; nb = 0; nlhdr = 0; if(block < b && u < (b-1)->addr+(b-1)->size) b--; for(; b->addr < u+resolution && b < eb; b++){ //fprint(2, "\tblock %lux %lux %d\n", b->addr, b->addr+b->size, b->mark); if(rXr(b->addr, b->addr+hdr, u, u+resolution) || rXr(b->addr+b->size-8, b->addr+b->size, u, u+resolution)){ if(b->mark == 0 && !b->free) nlhdr++; else nhdr++; } if(b->mark == 0 && !b->free) nleak++; nb++; } if(nhdr) c = HdrColor; else if(nlhdr) c = LeakHdrColor; else if(nleak) c = LeakColor; else if(nb) c = AllocColor; else c = FreeColor; //fprint(2, "\t%d\n", c); Bputc(&bio, c); } allocend = allocstart+x*y*resolution; for(; u < allocend; u+=resolution) Bputc(&bio, NoColor); }else{ eb = block+nblock; for(b=block; b<eb; b++) if(b->mark == 0 && !b->free) Bprint(&bio, "block 0x%.8lux 0x%.8lux 0x%.8lux 0x%.8lux %s %s\n", b->addr, b->size, b->w0, b->w1, b->s0, b->s1); } Bterm(&bio); }
/* {{{ * Gets the value from ICU * common code shared by get_primary_language,get_script or get_region or get_variant * result = 0 if error, 1 if successful , -1 if no value */ static char* get_icu_value_internal( char* loc_name , char* tag_name, int* result , int fromParseLocale) { char* tag_value = NULL; int32_t tag_value_len = 512; int singletonPos = 0; char* mod_loc_name = NULL; int grOffset = 0; int32_t buflen = 512; UErrorCode status = U_ZERO_ERROR; if( tag_name != LOC_CANONICALIZE_TAG ){ /* Handle grandfathered languages */ grOffset = findOffset( LOC_GRANDFATHERED , loc_name ); if( grOffset >= 0 ){ if( strcmp(tag_name , LOC_LANG_TAG)==0 ){ tag_value = estrdup(loc_name); return tag_value; } else { /* Since Grandfathered , no value , do nothing , retutn NULL */ return NULL; } } if( fromParseLocale==1 ){ /* Handle singletons */ if( strcmp(tag_name , LOC_LANG_TAG)==0 ){ if( strlen(loc_name)>1 && (isIDPrefix(loc_name) ==1 ) ){ return loc_name; } } singletonPos = getSingletonPos( loc_name ); if( singletonPos == 0){ /* singleton at start of script, region , variant etc. * or invalid singleton at start of language */ return NULL; } else if( singletonPos > 0 ){ /* singleton at some position except at start * strip off the singleton and rest of the loc_name */ mod_loc_name = estrndup ( loc_name , singletonPos-1); } } /* end of if fromParse */ } /* end of if != LOC_CANONICAL_TAG */ if( mod_loc_name == NULL){ mod_loc_name = estrdup(loc_name ); } /* Proceed to ICU */ do{ tag_value = erealloc( tag_value , buflen ); tag_value_len = buflen; if( strcmp(tag_name , LOC_SCRIPT_TAG)==0 ){ buflen = uloc_getScript ( mod_loc_name ,tag_value , tag_value_len , &status); } if( strcmp(tag_name , LOC_LANG_TAG )==0 ){ buflen = uloc_getLanguage ( mod_loc_name ,tag_value , tag_value_len , &status); } if( strcmp(tag_name , LOC_REGION_TAG)==0 ){ buflen = uloc_getCountry ( mod_loc_name ,tag_value , tag_value_len , &status); } if( strcmp(tag_name , LOC_VARIANT_TAG)==0 ){ buflen = uloc_getVariant ( mod_loc_name ,tag_value , tag_value_len , &status); } if( strcmp(tag_name , LOC_CANONICALIZE_TAG)==0 ){ buflen = uloc_canonicalize ( mod_loc_name ,tag_value , tag_value_len , &status); } if( U_FAILURE( status ) ) { if( status == U_BUFFER_OVERFLOW_ERROR ) { status = U_ZERO_ERROR; continue; } /* Error in retriving data */ *result = 0; if( tag_value ){ efree( tag_value ); } if( mod_loc_name ){ efree( mod_loc_name); } return NULL; } } while( buflen > tag_value_len ); if( buflen ==0 ){ /* No value found */ *result = -1; if( tag_value ){ efree( tag_value ); } if( mod_loc_name ){ efree( mod_loc_name); } return NULL; } else { *result = 1; } if( mod_loc_name ){ efree( mod_loc_name); } return tag_value; }
// Call this to get the tokens. // The number of returned tokens is returned in *plen. Token* _gettoks(uint8_t* data, int datalen, int chset, int mtype, int* plen) { TokenSource* ts; Token* a; int alen; int ai; int starti; int c; int tag; if(!lexinited) lexinit(); ts = newtokensource(data, datalen, chset, mtype); if(dbglex) fprint(2, "_gettoks starts, ts.i=%d, ts.edata=%d\n", ts->i, ts->edata); alen = 0; ai = 0; a = 0; if(ts->mtype == TextHtml) { for(;;) { if(alen - ai < ToksChunk/32) { alen += ToksChunk; a = erealloc(a, alen*sizeof *a); } starti = ts->i; c = getchar(ts); if(c < 0) break; if(c == '<') { tag = gettag(ts, starti, a, &ai); if(tag == Tscript || tag == Tstyle) { // special rules for getting Data after.... starti = ts->i; c = getchar(ts); tag = getscriptdata(ts, c, starti, a, &ai, tag); } } else tag = getdata(ts, c, starti, a, &ai); if(tag == -1) break; else if(dbglex > 1 && tag != Comment) fprint(2, "lex: got token %T\n", &a[ai-1]); } } else { // plain text (non-html) tokens for(;;) { if(alen - ai < ToksChunk/32) { alen += ToksChunk; a = erealloc(a, alen*sizeof *a); } tag = getplaindata(ts, a, &ai); if(tag == -1) break; if(dbglex > 1) fprint(2, "lex: got token %T\n", &a[ai]); } } free(ts); if(dbglex) fprint(2, "lex: returning %d tokens\n", ai); *plen = ai; if(ai == 0){ free(a); a = 0; } return a; }
zval *val; if (zend_hash_find(constants, Z_STRVAL_P(name), Z_STRLEN_P(name)+1, (void**)&val) == SUCCESS) { *value = *val; zval_copy_ctor(value); return 1; } return 0; } #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv TSRMLS_DC) { int i = op_array->last_literal; op_array->last_literal++; op_array->literals = (zend_literal*)erealloc(op_array->literals, op_array->last_literal * sizeof(zend_literal)); op_array->literals[i].constant = *zv; op_array->literals[i].hash_value = 0; op_array->literals[i].cache_slot = -1; Z_SET_REFCOUNT(op_array->literals[i].constant, 2); Z_SET_ISREF(op_array->literals[i].constant); return i; } # define LITERAL_LONG(op, val) do { \ zval _c; \ ZVAL_LONG(&_c, val); \ op.constant = zend_optimizer_add_literal(op_array, &_c TSRMLS_CC); \ } while (0) # define LITERAL_BOOL(op, val) do { \
static void *php_xml_realloc_wrapper(void *ptr, size_t sz) { return erealloc(ptr, sz); }
ZEND_API void zend_ast_dynamic_shrink(zend_ast **ast) { *ast = erealloc(*ast, sizeof(zend_ast) + sizeof(zend_ast*) * ((*ast)->children - 1)); }
int main(int argc, char **argv) { int c; char *ep, *tab; char *line; size_t len; unsigned long i; setprogname(argv[0]); while ((c = getopt(argc, argv, "at:")) != -1) { switch (c) { case 'a': if (nstops) usage(); all++; break; case 't': if (all) usage(); while ((tab = strsep(&optarg, ", \t")) != NULL) { if (*tab == '\0') continue; errno = 0; i = strtoul(tab, &ep, 0); if (*ep || (errno == ERANGE && i == ULONG_MAX)) errx(EXIT_FAILURE, "Invalid tabstop `%s'", tab); if (nstops >= maxstops) { maxstops += 20; tabstops = erealloc(tabstops, maxstops); } if (nstops && tabstops[nstops - 1] >= (size_t)i) errx(EXIT_FAILURE, "Bad tabstop spec `%s', must be " "greater than the previous `%zu'", tab, tabstops[nstops - 1]); tabstops[nstops++] = i; } break; case '?': default: usage(); } } argc -= optind; argv += optind; for (i = 0; i < nstops; i++) fprintf(stderr, "%lu %zu\n", i, tabstops[i]); do { if (argc > 0) { if (freopen(argv[0], "r", stdin) == NULL) err(EXIT_FAILURE, "Cannot open `%s'", argv[0]); argc--, argv++; } while ((line = fgetln(stdin, &len)) != NULL) tabify(line, len); } while (argc > 0); return EXIT_SUCCESS; }
tree_cell* nasl_str_replace(lex_ctxt * lexic) { char *a, *b, *r, *s, *c; int sz_a, sz_b, sz_r, count; int i1, i2, sz2, n, l; tree_cell *retc = NULL; a = get_str_local_var_by_name(lexic, "string"); b = get_str_local_var_by_name(lexic, "find"); r = get_str_local_var_by_name(lexic, "replace"); sz_a = get_local_var_size_by_name(lexic, "string"); sz_b = get_local_var_size_by_name(lexic, "find"); sz_r = get_local_var_size_by_name(lexic, "replace"); count = get_int_local_var_by_name(lexic, "count", 0); if (a == NULL || b == NULL) { nasl_perror(lexic, "Missing argument: str_replace(string: s, find: f, replace: r [,count: c])\n"); return NULL; } if (sz_b == 0) { nasl_perror(lexic, "str_replace: illegal 'find' argument value\n"); return NULL; } if (r == NULL) { r = ""; sz_r = 0; } retc = alloc_typed_cell(CONST_DATA); s = emalloc(1); sz2 = 0; n = 0; for (i1 = i2 = 0; i1 < sz_a - sz_b; ) { c = (char*)memmem(a + i1, sz_a - i1, b, sz_b); if(c == NULL) break; l = (c - a) - i1; sz2 += sz_r + l; s = erealloc(s, sz2+1); s[sz2] = '\0'; if (c - a > i1) { memcpy(s + i2, a + i1, l); i2 += l; } if (sz_r > 0) { memcpy(s + i2, r, sz_r); i2 += sz_r; } i1 += l + sz_b; n ++; if (count > 0 && n >= count) break; } if (i1 < sz_a) { sz2 += (sz_a - i1); s = erealloc(s, sz2+1); s[sz2] = '\0'; memcpy(s + i2, a + i1, sz_a - i1); } retc->x.str_val = s; retc->size = sz2; return retc; }
tree_cell* nasl_string(lex_ctxt* lexic) { tree_cell *retc; int vi, vn, newlen; int sz, typ; const char *s, *p1; char *p2; retc = alloc_tree_cell(0, NULL); retc->type = CONST_DATA; retc->size = 0; retc->x.str_val = emalloc(0); vn = array_max_index(&lexic->ctx_vars); for (vi = 0; vi < vn; vi ++) { if ((typ = get_var_type_by_num(lexic, vi)) == VAR2_UNDEF) continue; s = get_str_var_by_num(lexic, vi); sz = get_var_size_by_num(lexic, vi); if (sz <= 0) sz = strlen(s); newlen = retc->size + sz; retc->x.str_val = erealloc(retc->x.str_val, newlen + 1); p2 = retc->x.str_val + retc->size; p1 = s; retc->size = newlen; if (typ != VAR2_STRING) { memcpy(p2, p1, sz); p2[sz] = '\0'; } else while (*p1 != '\0') { if(*p1 == '\\' && p1[1] != '\0') { switch (p1[1]) { case 'n': *p2 ++ = '\n'; break; case 't': *p2 ++ = '\t'; break; case 'r': *p2++ = '\r'; break; case '\\': *p2++ = '\\'; break; case 'x': if (isxdigit(p1[2]) && isxdigit(p1[3])) { *p2++ = 16 * (isdigit(p1[2]) ? p1[2]-'0' : 10+tolower(p1[2])-'a') + (isdigit(p1[3]) ? p1[3]-'0' : 10+tolower(p1[3])-'a'); p1 += 2; retc->size -= 2; } else { nasl_perror(lexic, "Buggy hex value '\\x%c%c' skipped\n", isprint(p1[2]) ? p1[2] : '.', isprint(p1[3]) ? p1[3] : '.' ); /* We do not increment p1 by 4, we may miss the end of the string */ } break; default: nasl_perror(lexic, "Unknown%d escape sequence '\\%c'\n", getpid(), isprint(p1[1]) ? p1[1] : '.' ); retc->size --; break; } p1 += 2; retc->size --; } else *p2++ = *p1++; } } retc->x.str_val[retc->size] = '\0'; return retc; }
/* {{{ * common code shared by display_xyz functions to get the value from ICU }}} */ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS) { const char* loc_name = NULL; size_t loc_name_len = 0; const char* disp_loc_name = NULL; size_t disp_loc_name_len = 0; int free_loc_name = 0; UChar* disp_name = NULL; int32_t disp_name_len = 0; char* mod_loc_name = NULL; int32_t buflen = 512; UErrorCode status = U_ZERO_ERROR; zend_string* u8str; char* msg = NULL; int grOffset = 0; intl_error_reset( NULL ); if(zend_parse_parameters( ZEND_NUM_ARGS(), "s|s", &loc_name, &loc_name_len , &disp_loc_name ,&disp_loc_name_len ) == FAILURE) { spprintf(&msg , 0, "locale_get_display_%s : unable to parse input params", tag_name ); intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, msg , 1 ); efree(msg); RETURN_FALSE; } if(loc_name_len > ULOC_FULLNAME_CAPACITY) { /* See bug 67397: overlong locale names cause trouble in uloc_getDisplayName */ spprintf(&msg , 0, "locale_get_display_%s : name too long", tag_name ); intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, msg , 1 ); efree(msg); RETURN_FALSE; } if(loc_name_len == 0) { loc_name = intl_locale_get_default(); } if( strcmp(tag_name, DISP_NAME) != 0 ){ /* Handle grandfathered languages */ grOffset = findOffset( LOC_GRANDFATHERED , loc_name ); if( grOffset >= 0 ){ if( strcmp(tag_name , LOC_LANG_TAG)==0 ){ mod_loc_name = getPreferredTag( loc_name ); } else { /* Since Grandfathered, no value, do nothing, retutn NULL */ RETURN_FALSE; } } } /* end of if != LOC_CANONICAL_TAG */ if( mod_loc_name==NULL ){ mod_loc_name = estrdup( loc_name ); } /* Check if disp_loc_name passed , if not use default locale */ if( !disp_loc_name){ disp_loc_name = estrdup(intl_locale_get_default()); free_loc_name = 1; } /* Get the disp_value for the given locale */ do{ disp_name = erealloc( disp_name , buflen * sizeof(UChar) ); disp_name_len = buflen; if( strcmp(tag_name , LOC_LANG_TAG)==0 ){ buflen = uloc_getDisplayLanguage ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } else if( strcmp(tag_name , LOC_SCRIPT_TAG)==0 ){ buflen = uloc_getDisplayScript ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } else if( strcmp(tag_name , LOC_REGION_TAG)==0 ){ buflen = uloc_getDisplayCountry ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } else if( strcmp(tag_name , LOC_VARIANT_TAG)==0 ){ buflen = uloc_getDisplayVariant ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } else if( strcmp(tag_name , DISP_NAME)==0 ){ buflen = uloc_getDisplayName ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } /* U_STRING_NOT_TERMINATED_WARNING is admissible here; don't look for it */ if( U_FAILURE( status ) ) { if( status == U_BUFFER_OVERFLOW_ERROR ) { status = U_ZERO_ERROR; continue; } spprintf(&msg, 0, "locale_get_display_%s : unable to get locale %s", tag_name , tag_name ); intl_error_set( NULL, status, msg , 1 ); efree(msg); if( disp_name){ efree( disp_name ); } if( mod_loc_name){ efree( mod_loc_name ); } if (free_loc_name) { efree((void *)disp_loc_name); disp_loc_name = NULL; } RETURN_FALSE; } } while( buflen > disp_name_len ); if( mod_loc_name){ efree( mod_loc_name ); } if (free_loc_name) { efree((void *)disp_loc_name); disp_loc_name = NULL; } /* Convert display locale name from UTF-16 to UTF-8. */ u8str = intl_convert_utf16_to_utf8(disp_name, buflen, &status ); efree( disp_name ); if( !u8str ) { spprintf(&msg, 0, "locale_get_display_%s :error converting display name for %s to UTF-8", tag_name , tag_name ); intl_error_set( NULL, status, msg , 1 ); efree(msg); RETURN_FALSE; } RETVAL_NEW_STR( u8str ); }
/* * If type==0, only last line of output is returned (exec) * If type==1, all lines will be printed and last lined returned (system) * If type==2, all lines will be saved to given array (exec with &$array) * If type==3, output will be printed binary, no lines will be saved or returned (passthru) * */ int php_Exec(int type, char *cmd, pval *array, pval *return_value) { FILE *fp; char *buf, *tmp=NULL; int buflen = 0; int t, l, output=1; int overflow_limit, lcmd, ldir; int rsrc_id; char *b, *c, *d=NULL; #if PHP_SIGCHILD void (*sig_handler)(); #endif PLS_FETCH(); FLS_FETCH(); buf = (char*) emalloc(EXEC_INPUT_BUF); if (!buf) { php_error(E_WARNING, "Unable to emalloc %d bytes for exec buffer", EXEC_INPUT_BUF); return -1; } buflen = EXEC_INPUT_BUF; if (PG(safe_mode)) { lcmd = strlen(cmd); ldir = strlen(PG(safe_mode_exec_dir)); l = lcmd + ldir + 2; overflow_limit = l; c = strchr(cmd, ' '); if (c) *c = '\0'; if (strstr(cmd, "..")) { php_error(E_WARNING, "No '..' components allowed in path"); efree(buf); return -1; } d = emalloc(l); strcpy(d, PG(safe_mode_exec_dir)); overflow_limit -= ldir; b = strrchr(cmd, PHP_DIR_SEPARATOR); if (b) { strcat(d, b); overflow_limit -= strlen(b); } else { strcat(d, "/"); strcat(d, cmd); overflow_limit-=(strlen(cmd)+1); } if (c) { *c = ' '; strncat(d, c, overflow_limit); } tmp = php_escape_shell_cmd(d); efree(d); d = tmp; #if PHP_SIGCHILD sig_handler = signal (SIGCHLD, SIG_DFL); #endif #ifdef PHP_WIN32 fp = VCWD_POPEN(d, "rb"); #else fp = VCWD_POPEN(d, "r"); #endif if (!fp) { php_error(E_WARNING, "Unable to fork [%s]", d); efree(d); efree(buf); #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif return -1; } } else { /* not safe_mode */ #if PHP_SIGCHILD sig_handler = signal (SIGCHLD, SIG_DFL); #endif #ifdef PHP_WIN32 fp = VCWD_POPEN(cmd, "rb"); #else fp = VCWD_POPEN(cmd, "r"); #endif if (!fp) { php_error(E_WARNING, "Unable to fork [%s]", cmd); efree(buf); #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif return -1; } } buf[0] = '\0'; if (type==2) { if (Z_TYPE_P(array) != IS_ARRAY) { pval_destructor(array); array_init(array); } } /* we register the resource so that case of an aborted connection the * fd gets pclosed */ rsrc_id = ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_popen()); if (type != 3) { l=0; while ( !feof(fp) || l != 0 ) { l = 0; /* Read a line or fill the buffer, whichever comes first */ do { if ( buflen <= (l+1) ) { buf = erealloc(buf, buflen + EXEC_INPUT_BUF); if ( buf == NULL ) { php_error(E_WARNING, "Unable to erealloc %d bytes for exec buffer", buflen + EXEC_INPUT_BUF); #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif return -1; } buflen += EXEC_INPUT_BUF; } if ( fgets(&(buf[l]), buflen - l, fp) == NULL ) { /* eof */ break; } l += strlen(&(buf[l])); } while ( (l > 0) && (buf[l-1] != '\n') ); if ( feof(fp) && (l == 0) ) { break; } if (type == 1) { if (output) PUTS(buf); sapi_flush(); } else if (type == 2) { /* strip trailing whitespaces */ l = strlen(buf); t = l; while (l-- && isspace((int)buf[l])); if (l < t) { buf[l + 1] = '\0'; } add_next_index_string(array, buf, 1); } } /* strip trailing spaces */ l = strlen(buf); t = l; while (l && isspace((int)buf[l - 1])) { l--; } if (l < t) buf[l] = '\0'; /* Return last line from the shell command */ if (PG(magic_quotes_runtime)) { int len; tmp = php_addslashes(buf, 0, &len, 0); RETVAL_STRINGL(tmp,len,0); } else { RETVAL_STRINGL(buf,l,1); } } else { int b, i; while ((b = fread(buf, 1, buflen, fp)) > 0) { for (i = 0; i < b; i++) if (output) (void)PUTC(buf[i]); } } /* the zend_list_delete will pclose our popen'ed process */ zend_list_delete(rsrc_id); #if HAVE_SYS_WAIT_H if (WIFEXITED(FG(pclose_ret))) { FG(pclose_ret) = WEXITSTATUS(FG(pclose_ret)); } #endif #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif if (d) { efree(d); } efree(buf); return FG(pclose_ret); }
void ExecuteCycle(VM* vm) { if(vm->pc == -1) return; if(vm->debug) printf("pc %i: ", vm->pc); if(vm->stackSize < vm->numGlobals) printf("Global(s) were removed from the stack!\n"); switch(vm->program[vm->pc]) { case OP_PUSH_NULL: { if(vm->debug) printf("push_null\n"); ++vm->pc; PushObject(vm, &NullObject); } break; case OP_PUSH_NUMBER: { if(vm->debug) printf("push_number\n"); ++vm->pc; int index = ReadInteger(vm); PushNumber(vm, vm->numberConstants[index]); } break; case OP_PUSH_STRING: { if(vm->debug) printf("push_string\n"); ++vm->pc; int index = ReadInteger(vm); PushString(vm, vm->stringConstants[index]); } break; case OP_PUSH_FUNC: { if(vm->debug) printf("push_func\n"); Word hasEllipsis = vm->program[++vm->pc]; Word isExtern = vm->program[++vm->pc]; Word numArgs = vm->program[++vm->pc]; ++vm->pc; int index = ReadInteger(vm); PushFunc(vm, index, hasEllipsis, isExtern, numArgs); } break; case OP_PUSH_DICT: { if(vm->debug) printf("push_dict\n"); ++vm->pc; PushDict(vm); } break; case OP_CREATE_DICT_BLOCK: { if(vm->debug) printf("create_dict_block\n"); ++vm->pc; int length = ReadInteger(vm); Object* obj = PushDict(vm); if(length > 0) { // stack (before dict) is filled with key-value pairs (backwards, key is higher on stack) for(int i = 0; i < length * 2; i += 2) DictPut(&obj->dict, vm->stack[vm->stackSize - i - 2]->string.raw, vm->stack[vm->stackSize - i - 3]); vm->stackSize -= length * 2; vm->stack[vm->stackSize - 1] = obj; } } break; case OP_CREATE_ARRAY: { if(vm->debug) printf("create_array\n"); ++vm->pc; int length = (int)PopNumber(vm); PushArray(vm, length); } break; case OP_CREATE_ARRAY_BLOCK: { if(vm->debug) printf("create_array_block\n"); ++vm->pc; int length = ReadInteger(vm); Object* obj = PushArray(vm, length); if(length > 0) { for(int i = 0; i < length; ++i) obj->array.members[length - i - 1] = vm->stack[vm->stackSize - 2 - i]; vm->stackSize -= length; vm->stack[vm->stackSize - 1] = obj; } } break; case OP_LENGTH: { if(vm->debug) printf("length\n"); ++vm->pc; Object* obj = PopObject(vm); if(obj->type == OBJ_STRING) PushNumber(vm, strlen(obj->string.raw)); else if(obj->type == OBJ_ARRAY) PushNumber(vm, obj->array.length); else { fprintf(stderr, "Attempted to get length of %s\n", ObjectTypeNames[obj->type]); exit(1); } } break; case OP_ARRAY_PUSH: { if(vm->debug) printf("array_push\n"); ++vm->pc; Object* obj = PopArrayObject(vm); Object* value = PopObject(vm); while(obj->array.length + 1 >= obj->array.capacity) { obj->array.capacity *= 2; obj->array.members = erealloc(obj->array.members, obj->array.capacity * sizeof(Object*)); } obj->array.members[obj->array.length++] = value; } break; case OP_ARRAY_POP: { if(vm->debug) printf("array_pop\n"); ++vm->pc; Object* obj = PopArrayObject(vm); if(obj->array.length <= 0) { fprintf(stderr, "Cannot pop from empty array\n"); exit(1); } PushObject(vm, obj->array.members[--obj->array.length]); } break; case OP_ARRAY_CLEAR: { if(vm->debug) printf("array_clear\n"); ++vm->pc; Object* obj = PopArrayObject(vm); obj->array.length = 0; } break; case OP_DICT_SET: { if(vm->debug) printf("dict_set\n"); ++vm->pc; Object* obj = PopDict(vm); const char* key = PopString(vm); Object* value = PopObject(vm); DictPut(&obj->dict, key, value); } break; case OP_DICT_GET: { if(vm->debug) printf("dict_get\n"); ++vm->pc; Object* obj = PopDict(vm); const char* key = PopString(vm); Object* value = DictGet(&obj->dict, key); if(value) PushObject(vm, value); else PushObject(vm, &NullObject); } break; case OP_DICT_PAIRS: { if(vm->debug) printf("dict_pairs\n"); ++vm->pc; Object* obj = PopDict(vm); Object* aobj = PushArray(vm, obj->dict.numEntries); int len = 0; for(int i = 0; i <= obj->dict.capacity; ++i) { DictNode* node = obj->dict.buckets[i]; while(node) { Object* pair = PushArray(vm, 2); Object* key = NewObject(vm, OBJ_STRING); key->string.raw = estrdup(node->key); pair->array.members[0] = key; pair->array.members[1] = node->value; aobj->array.members[len++] = PopObject(vm); node = node->next; } } } break; #define BIN_OP_TYPE(op, operator, type) case OP_##op: { if(vm->debug) printf("%s\n", #op); Object* val2 = PopObject(vm); Object* val1 = PopObject(vm); PushNumber(vm, (type)val1->number operator (type)val2->number); ++vm->pc; } break; #define BIN_OP(op, operator) BIN_OP_TYPE(op, operator, double) BIN_OP(ADD, +) BIN_OP(SUB, -) BIN_OP(MUL, *) BIN_OP(DIV, /) BIN_OP_TYPE(MOD, %, int) BIN_OP_TYPE(OR, |, int) BIN_OP_TYPE(AND, &, int) BIN_OP(LT, <) BIN_OP(LTE, <=) BIN_OP(GT, >) BIN_OP(GTE, >=) BIN_OP_TYPE(LOGICAL_AND, &&, int) BIN_OP_TYPE(LOGICAL_OR, ||, int) #define CBIN_OP(op, operator) case OP_##op: { ++vm->pc; if(vm->debug) printf("%s\n", #op); Object* b = PopObject(vm); Object* a = PopObject(vm); a->number operator b->number; } break; CBIN_OP(CADD, +=) CBIN_OP(CSUB, -=) CBIN_OP(CMUL, *=) CBIN_OP(CDIV, /=) case OP_EQU: { ++vm->pc; Object* o2 = PopObject(vm); Object* o1 = PopObject(vm); if(o1->type != o2->type) PushNumber(vm, 0); else { if(o1->type == OBJ_STRING) { PushNumber(vm, strcmp(o1->string.raw, o2->string.raw) == 0); } else if(o1->type == OBJ_NUMBER) { PushNumber(vm, o1->number == o2->number); } else PushNumber(vm, o1 == o2); } } break; case OP_NEQU: { ++vm->pc; Object* o2 = PopObject(vm); Object* o1 = PopObject(vm); if(o1->type != o2->type) PushNumber(vm, 1); else { if(o1->type == OBJ_STRING) { PushNumber(vm, strcmp(o1->string.raw, o2->string.raw) != 0); } else if(o1->type == OBJ_NUMBER) { PushNumber(vm, o1->number != o2->number); } else PushNumber(vm, o1 != o2); } } break; case OP_NEG: { if(vm->debug) printf("neg\n"); ++vm->pc; Object* obj = PopObject(vm); PushNumber(vm, -obj->number); } break; case OP_LOGICAL_NOT: { if(vm->debug) printf("not\n"); ++vm->pc; Object* obj = PopObject(vm); PushNumber(vm, !obj->number); } break; case OP_SETINDEX: { ++vm->pc; Object* obj = PopObject(vm); Object* indexObj = PopObject(vm); Object* value = PopObject(vm); if(vm->debug) printf("setindex\n"); if(obj->type == OBJ_ARRAY) { if(indexObj->type != OBJ_NUMBER) { fprintf(stderr, "Attempted to index array with a %s (expected number)\n", ObjectTypeNames[indexObj->type]); exit(1); } int index = (int)indexObj->number; int arrayLength = obj->array.length; Object** members = obj->array.members; if(index >= 0 && index < arrayLength) members[index] = value; else { fprintf(stderr, "Invalid array index %i\n", index); exit(1); } } else if(obj->type == OBJ_STRING) { if(indexObj->type != OBJ_NUMBER) { fprintf(stderr, "Attempted to index string with a %s (expected number)\n", ObjectTypeNames[indexObj->type]); exit(1); } if(value->type != OBJ_NUMBER) { fprintf(stderr, "Attempted to assign a %s to an index of a string '%s' (expected number/character)\n", ObjectTypeNames[value->type], obj->string.raw); exit(1); } obj->string.raw[(int)indexObj->number] = (char)value->number; } else if(obj->type == OBJ_DICT) { if(indexObj->type != OBJ_STRING) { fprintf(stderr, "Attempted to index dict with a %s (expected string)\n", ObjectTypeNames[indexObj->type]); exit(1); } DictPut(&obj->dict, indexObj->string.raw, value); } else { fprintf(stderr, "Attempted to index a %s\n", ObjectTypeNames[obj->type]); exit(1); } } break; case OP_GETINDEX: { ++vm->pc; Object* obj = PopObject(vm); Object* indexObj = PopObject(vm); if(obj->type == OBJ_ARRAY) { if(indexObj->type != OBJ_NUMBER) { fprintf(stderr, "Attempted to index array with a %s (expected number)\n", ObjectTypeNames[indexObj->type]); exit(1); } int index = (int)indexObj->number; int arrayLength = obj->array.length; Object** members = obj->array.members; if(index >= 0 && index < arrayLength) { if(members[index]) PushObject(vm, members[index]); else { fprintf(stderr, "attempted to index non-existent value in array\n"); exit(1); } if(vm->debug) printf("getindex %i\n", index); } else { fprintf(stderr, "Invalid array index %i\n", index); exit(1); } } else if(obj->type == OBJ_STRING) { if(indexObj->type != OBJ_NUMBER) { fprintf(stderr, "Attempted to index string with a %s (expected number)\n", ObjectTypeNames[indexObj->type]); exit(1); } PushNumber(vm, obj->string.raw[(int)indexObj->number]); } else if(obj->type == OBJ_DICT) { if(indexObj->type != OBJ_STRING) { fprintf(stderr, "Attempted to index dict with a %s (expected string)\n", ObjectTypeNames[indexObj->type]); exit(1); } Object* val = (Object*)DictGet(&obj->dict, indexObj->string.raw); if(val) PushObject(vm, val); else PushObject(vm, &NullObject); } else { fprintf(stderr, "Attempted to index a %s\n", ObjectTypeNames[obj->type]); exit(1); } } break; case OP_SET: { ++vm->pc; int index = ReadInteger(vm); Object* top = PopObject(vm); vm->stack[index] = top; if(vm->debug) { if(top->type == OBJ_NUMBER) printf("set %i to %g\n", index, top->number); else if(top->type == OBJ_STRING) printf("set %i to %s\n", index, top->string); } } break; case OP_GET: { ++vm->pc; int index = ReadInteger(vm); if(vm->stack[index]) PushObject(vm, (vm->stack[index])); else PushObject(vm, &NullObject); if(vm->debug) printf("get %i\n", index); } break; case OP_WRITE: { if(vm->debug) printf("write\n"); Object* top = PopObject(vm); WriteObject(vm, top); printf("\n"); ++vm->pc; } break; case OP_READ: { if(vm->debug) printf("read\n"); char* string = ReadStringFromStdin(); PushString(vm, string); free(string); ++vm->pc; } break; case OP_GOTO: { ++vm->pc; int pc = ReadInteger(vm); vm->pc = pc; if(vm->debug) printf("goto %i\n", vm->pc); } break; case OP_GOTOZ: { ++vm->pc; int pc = ReadInteger(vm); Object* top = PopObject(vm); if(top->number == 0) { vm->pc = pc; if(vm->debug) printf("gotoz %i\n", vm->pc); } } break; case OP_CALL: { Word nargs = vm->program[++vm->pc]; ++vm->pc; int index = ReadInteger(vm); if(vm->debug) printf("call %s\n", vm->functionNames[index]); PushIndir(vm, nargs); vm->pc = vm->functionPcs[index]; } break; case OP_CALLP: { Word hasEllipsis, isExtern, numArgs; Word nargs = vm->program[++vm->pc]; ++vm->pc; int id = PopFunc(vm, &hasEllipsis, &isExtern, &numArgs); if(vm->debug) printf("callp %s%s\n", isExtern ? "extern " : "", isExtern ? vm->externNames[id] : vm->functionNames[id]); if(isExtern) vm->externs[id](vm); else { if(!hasEllipsis) { if(nargs != numArgs) { fprintf(stderr, "Function '%s' expected %i args but recieved %i args\n", vm->functionNames[id], numArgs, nargs); exit(1); } } else { if(nargs < numArgs) { fprintf(stderr, "Function '%s' expected at least %i args but recieved %i args\n", vm->functionNames[id], numArgs, nargs); exit(1); } } if(!hasEllipsis) PushIndir(vm, nargs); else { // runtime collapsing of arguments: // the concrete arguments (known during compilation) are on the top of // the stack. We create an array (by pushing it and then decrementing the // stack pointer) and fill it up with the ellipsed arguments (behind the // concrete arguments). We then place this array just before the concrete // arguments in the stack so that it can be accessed as an argument "args". // The indirection info is pushed onto the indirection stack (the concrete and // non-concrete [aside from the one that the 'args' array replaces] are still // present on the stack, so all of the arguments are to be removed) /*printf("args:\n"); for(int i = 0; i < nargs; ++i) { WriteObject(vm, vm->stack[vm->stackSize - i - 1]); printf("\n"); } printf("end\n");*/ //printf("members:\n"); Object* obj = PushArray(vm, nargs - numArgs); vm->stackSize -= 1; for(int i = 0; i < obj->array.length; ++i) { obj->array.members[i] = vm->stack[vm->stackSize - numArgs - 1 - i]; /*WriteObject(vm, obj->array.members[i]); printf("\n");*/ } //printf("end\n"); vm->stack[vm->stackSize - numArgs - 1] = obj; /*printf("final args:\n"); for(int i = 0; i < numArgs + 1; ++i) { WriteObject(vm, vm->stack[vm->stackSize - i - 1]); printf("\n"); } printf("end\n");*/ PushIndir(vm, nargs); } vm->pc = vm->functionPcs[id]; } } break; case OP_RETURN: { if(vm->debug) printf("ret\n"); PopIndir(vm); } break; case OP_RETURN_VALUE: { if(vm->debug) printf("retval\n"); Object* returnValue = PopObject(vm); PopIndir(vm); PushObject(vm, returnValue); } break; case OP_CALLF: { ++vm->pc; int index = ReadInteger(vm); if(vm->debug) printf("callf %s\n", vm->externNames[index]); vm->externs[index](vm); } break; case OP_GETLOCAL: { ++vm->pc; int index = ReadInteger(vm); PushObject(vm, GetLocal(vm, index)); if(vm->debug) printf("getlocal %i (fp: %i, stack size: %i)\n", index, vm->fp, vm->stackSize); } break; case OP_SETLOCAL: { if(vm->debug) printf("setlocal\n"); ++vm->pc; int index = ReadInteger(vm); SetLocal(vm, index, PopObject(vm)); } break; case OP_HALT: { if(vm->debug) printf("halt\n"); vm->pc = -1; } break; default: printf("Invalid instruction %i\n", vm->program[vm->pc]); break; } }
int php_tmpl_parse(zval** dest, t_template* tmpl, zval* path, HashPosition* pos, zval** data) { uint tag_num; int i; zval **ztag; t_tmpl_tag *tag, *ctx; char *buf; ulong buf_alloc; zval *new_path; zval **tag_data; HashPosition cur_pos, saved_pos, dup_tag_pos; uint offset; unsigned short need_skip; zval **iteration; char *key_tag_key; uint key_tag_len; ulong key_tag_index; /* Initialize variables */ buf_alloc = TMPL_MAX_TAG_LEN; buf = (char*)emalloc(buf_alloc); MAKE_STD_ZVAL(new_path); ZVAL_STRINGL(new_path, buf, 0, 0); dup_tag_pos = NULL; /* Get the context's info from tags array */ if(!pos) { /* This is not a recursion call. Look for the context's last non-empty iteration */ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tmpl->tags), &cur_pos); i = 0; /* we'll set this flag when found the context */ do { if(HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(Z_ARRVAL_P(tmpl->tags), &key_tag_key, &key_tag_len, &key_tag_index, 0, &cur_pos)) break; if(SUCCESS != zend_hash_get_current_data_ex(Z_ARRVAL_P(tmpl->tags), (void**)&ztag, &cur_pos)) break; tag = ctx = (t_tmpl_tag*)Z_STRVAL_PP(ztag); if(TMPL_CONTEXT != ctx->typ) continue; /* get out of the loop if we're inside of the context we need */ if((uint)ZL(path) == key_tag_len-1 && !memcmp(ZV(path), key_tag_key, ZL(path))) { i = 1; break; } } while(SUCCESS == zend_hash_move_forward_ex(Z_ARRVAL_P(tmpl->tags), &cur_pos)); if(!i) { TMPL_PARSE_CLEANUP; return FAILURE; } tag_data = php_tmpl_get_iteration(tmpl, path, TMPL_ITERATION_PARENT); } else { cur_pos = *pos; tag = ctx = (t_tmpl_tag*)Z_STRVAL_PP((zval**)(cur_pos->pData)); tag_data = data; } saved_pos = cur_pos; /* Check all iterations in the opened context */ zend_hash_internal_pointer_reset(Z_ARRVAL_PP(tag_data)); do { if(FAILURE == zend_hash_get_current_data(Z_ARRVAL_PP(tag_data), (void*)&iteration)) break; /* Uncomment the following line to avoid parsing of empty iterations */ /* if(pos && !zend_hash_num_elements(Z_ARRVAL_PP(iteration))) break; */ /* Initialize the offset from the template's content begining */ offset = (1 == ZL(ctx->name) && '/' == ZV(ctx->name)[0]) ? 0 : ctx->loff + ZL(tmpl->ctx_ol) + ZL(ctx->name) + ZL(tmpl->ctx_or); /* We only need tags which are inside of the context */ cur_pos = saved_pos; for(tag_num = 0; tag_num < ctx->tag_num; tag_num++) { if(FAILURE == zend_hash_move_forward_ex(Z_ARRVAL_P(tmpl->tags), &cur_pos)) break; if(FAILURE == zend_hash_get_current_data_ex(Z_ARRVAL_P(tmpl->tags), (void**)&ztag, &cur_pos)) break; tag = (t_tmpl_tag*)Z_STRVAL_PP(ztag); if(NULL == dup_tag_pos && zend_hash_num_elements(Z_ARRVAL_P(tmpl->dup_tag))) { zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tmpl->dup_tag), &dup_tag_pos); do { if(FAILURE == zend_hash_get_current_data_ex(Z_ARRVAL_P(tmpl->dup_tag), (void**)&ztag, &dup_tag_pos)) break; } while(Z_TMPL_TAG(ztag)->loff < offset && SUCCESS == zend_hash_move_forward_ex(Z_ARRVAL_P(tmpl->dup_tag), &dup_tag_pos)); } php_tmpl_parse_check_memory(tmpl, &dup_tag_pos, tag, TMPL_TAG, iteration, dest, &offset); TMPL_PARSE_DEST_ADD(offset, tag->loff - offset); offset = tag->roff; need_skip = (FAILURE == zend_hash_find(Z_ARRVAL_PP(iteration), ZV(tag->name), ZL(tag->name)+1, (void*)&ztag)); if(!need_skip) { if(TMPL_CONTEXT == tag->typ && IS_ARRAY == Z_TYPE_PP(ztag)) { /* Processing a context */ /* Make a recursive call */ if(buf_alloc <= (unsigned)(ZL(path)+1+ZL(tag->name)+1)) { while(buf_alloc <= (unsigned)(ZL(path)+1+ZL(tag->name)+1)) buf_alloc <<= 1; (char*)ZV(new_path) = erealloc(ZV(new_path), buf_alloc); } sprintf(ZV(new_path), (1 == ZL(path) && '/' == ZV(path)[0]) ? "%s%s" : "%s/%s", ZV(path), ZV(tag->name)); ZL(new_path) = ZL(path) + ZL(tag->name) + ((1 == ZL(path) && '/' == ZV(path)[0]) ? 0 : 1); php_tmpl_parse(dest, tmpl, new_path, &cur_pos, ztag); } else { /* Processing a tag */ TMPL_PARSE_DEST_ADD(Z_STRVAL_PP(ztag)-Z_STRVAL_P(tmpl->original), Z_STRLEN_PP(ztag)); if(TMPL_CONTEXT == tag->typ) need_skip = 1; } } if(need_skip && TMPL_CONTEXT == tag->typ) { for(i=0; i < (int)tag->tag_num; i++) { if(FAILURE == zend_hash_move_forward_ex(Z_ARRVAL_P(tmpl->tags), &cur_pos)) break; if(FAILURE == zend_hash_get_current_data_ex(Z_ARRVAL_P(tmpl->tags), (void**)&ztag, &cur_pos)) break; i -= (TMPL_CONTEXT == Z_TMPL_TAG(ztag)->typ) ? Z_TMPL_TAG(ztag)->tag_num : 0; } } } php_tmpl_parse_check_memory(tmpl, &dup_tag_pos, ctx, TMPL_CONTEXT, iteration, dest, &offset); if(1 != ZL(path) || '/' != ZV(path)[0]) { TMPL_PARSE_DEST_ADD(offset, ctx->roff - offset - ZL(tmpl->ctx_cl) - ZL(ctx->name)*(ZL(tmpl->ctx_cr)?1:0) - ZL(tmpl->ctx_cr)); } else { TMPL_PARSE_DEST_ADD(offset, ZL(tmpl->original)-offset); } } while(SUCCESS == zend_hash_move_forward(Z_ARRVAL_PP(tag_data))); if(pos) *pos = cur_pos; TMPL_PARSE_CLEANUP; return SUCCESS; }
/* ArchiveReader::getNextEntry {{{ * */ ZEND_METHOD(ArchiveReader, getNextEntry) { zval *this = getThis(); archive_file_t *arch; int result, error_num, resource_id; const char *error_string; zend_bool fetch_entry_data = 0; archive_entry_t *entry; struct archive_entry *current_entry; size_t len; off_t offset; char *buf; zend_error_handling error_handling; zend_replace_error_handling(EH_THROW, ce_ArchiveException, &error_handling TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &fetch_entry_data) == FAILURE) { zend_restore_error_handling(&error_handling TSRMLS_CC); return; } if (!_archive_get_fd(this, &arch TSRMLS_CC)) { zend_restore_error_handling(&error_handling TSRMLS_CC); return; } if (arch->struct_state == ARCHIVE_OK) { result = archive_read_next_header(arch->arch, ¤t_entry); arch->struct_state = result; entry = (archive_entry_t *) emalloc(sizeof(archive_entry_t)); entry->entry = current_entry; entry->data = NULL; entry->filename = NULL; entry->resolved_filename = NULL; entry->data_len = 0; arch->current_entry = entry; } else { zend_restore_error_handling(&error_handling TSRMLS_CC); RETURN_FALSE; } if (result && result != ARCHIVE_EOF) { arch->current_entry = NULL; error_num = archive_errno(arch->arch); error_string = archive_error_string(arch->arch); efree(entry); if (error_num && error_string) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read file %s: error #%d, %s", arch->filename, error_num, error_string); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read file %s: unknown error %d", arch->filename, result); } zend_restore_error_handling(&error_handling TSRMLS_CC); return; } if (result == ARCHIVE_EOF) { arch->current_entry = NULL; efree(entry); zend_restore_error_handling(&error_handling TSRMLS_CC); RETURN_FALSE; } object_init_ex(return_value, ce_ArchiveEntry); if (fetch_entry_data) { while ((result = archive_read_data_block(arch->arch, (const void **)&buf, &len, &offset)) == ARCHIVE_OK) { entry->data = erealloc(entry->data, entry->data_len + len + 1); memcpy(entry->data + entry->data_len, buf, len); entry->data_len += len; } if (result && result != ARCHIVE_EOF) { error_num = archive_errno(arch->arch); error_string = archive_error_string(arch->arch); efree(entry); if (error_num && error_string) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read file %s: error #%d, %s", arch->filename, error_num, error_string); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read file %s: unknown error %d", arch->filename, result); } zend_restore_error_handling(&error_handling TSRMLS_CC); return; } } if (entry->entry) { resource_id = zend_list_insert(entry,le_archive_entry); add_property_resource(return_value, "entry", resource_id); } zend_restore_error_handling(&error_handling TSRMLS_CC); }
int push_variogram_model(VARIOGRAM *v, VGM_MODEL part) { int i, max_id, where = -1; /* * add the part submodel to v (if part.id < 0) or else * modify the appropriate part of v, having the id of part.id. * do a lot of checks, and set .fn and .da_fn functions. */ if (v->n_models == v->max_n_models) { v->part = (VGM_MODEL *) erealloc(v->part, (v->max_n_models + INIT_N_VGMM) * sizeof(VGM_MODEL)); for (i = v->max_n_models; i < v->max_n_models + INIT_N_VGMM; i++) init_variogram_part(&(v->part[i])); v->max_n_models += INIT_N_VGMM; } /* * check some things: */ if (part.model == NOT_SP) ErrMsg(ER_IMPOSVAL, "model NSP not allowed in variogram structure"); if (part.range[0] < 0.0) ErrMsg(ER_RANGE, "variogram range cannot be negative"); if (part.model == LINEAR) { if (part.range[0] == 0.0) part.fit_range = 0; } else if (part.model == NUGGET || part.model == INTERCEPT || part.model == MERROR) { part.fit_range = 0; if (part.range[0] > 0.0) ErrMsg(ER_RANGE, "range must be zero"); } else if (part.range[0] == 0.0) ErrMsg(ER_RANGE, "range must be positive"); if (part.model == POWER && part.range[0] > 2.0) ErrMsg(ER_RANGE, "power model range (parameter) cannot exceed 2.0"); if (part.model == EXCLASS && part.range[1] > 2.0) ErrMsg(ER_RANGE, "exponentical class model shape parameter cannot exceed 2.0"); if (part.id < 0) { where = v->n_models; v->n_models++; for (i = max_id = 0; i < v->n_models; i++) max_id = MAX(v->part[i].id, max_id); part.id = max_id + 1; } else { /* search in list: */ for (i = 0; where < 0 && i < v->n_models; i++) if (v->part[i].id == part.id) where = i; assert(where >= 0); /* i.e., it should really be in the list */ } if (v->isotropic) v->isotropic = (part.tm_range == NULL); /* * check that the .fn and .da_fn functions in v_models * will indeed be the correct ones: */ assert(part.model == v_models[part.model].model); v->part[where] = part; v->part[where].fnct = v_models[part.model].fn; v->part[where].da_fnct = v_models[part.model].da_fn; return part.id; }
/* Also: The contents of both buffers is monitored in order to check if they got overflowed during the MUX call. If so, the executation is aborted. */ int runExtension(char ** const command , const char * const line , char ** const newargs) { int clen, llen, xlen, nlen; struct REGPACK r, r2; char *muxCmd, *muxArg, *muxBuf, *p; assert(command); assert(*command); assert(line); assert(newargs); if((clen = strlen(*command)) >= BUFFER_SIZE_MUX_AE || (llen = strlen(line)) >= BUFFER_SIZE_MUX_AE || llen + clen >= BUFFER_SIZE_MUX_AE) { error_long_mux_line(); return 0; } /* Duplicate & fill in the length bytes. */ /* Both buffers must be located in the same segment */ if((muxBuf = emalloc(2 * (BUFFER_SIZE_MUX_AE + 4))) == 0) return 0; /* fill everything with magic values */ memset(muxBuf, (char)BUFFER_SIZE_MUX_AE, 2 * (BUFFER_SIZE_MUX_AE + 4)); muxCmd = muxBuf + 2; muxArg = muxBuf + BUFFER_SIZE_MUX_AE + 4 + 2; memcpy(muxCmd, *command, clen); muxCmd[-1] = (char)clen; memcpy(muxArg, muxCmd, clen); memcpy(muxArg + clen, line, llen); muxArg[-1] = (char)(xlen = llen + clen); /* muxCmd[-2] = muxArg[-2] = (char)BUFFER_SIZE_MUX_AE; see above memset() */ assert(xlen <= 255); /* 4dos v4 compatible space padding */ memset(muxCmd + clen, ' ', BUFFER_SIZE_MUX_AE - clen); /* The command line is \xd terminated, for savety reasons an \0 is added too */ strcpy(muxArg + xlen, "\xd"); muxCmd[BUFFER_SIZE_MUX_AE] /* Make sure the buffers is terminated */ = muxArg[BUFFER_SIZE_MUX_AE] = '\0'; /* Both strings have been prepared now; the MUX call is going to happen */ r.r_ax = 0xae00; /* Installable Commands check for extension */ r.r_dx = 0xffff; /* Magic value */ r.r_cx = xlen | 0xff00; /* length of command line tail (4dos v4) */ r.r_ds = r.r_es = FP_SEG(muxBuf); r.r_bx = FP_OFF(muxArg); r.r_si = FP_OFF(muxCmd); r.r_di = 0; /* Magic value 4dos v4 */ memcpy(&r2, &r, sizeof(r2)); intr(0x2f, &r); if((byte)muxCmd[-2] != BUFFER_SIZE_MUX_AE #if BUFFER_SIZE_MUX_AE < 255 || (byte)muxCmd[-1] > BUFFER_SIZE_MUX_AE #endif || muxCmd[BUFFER_SIZE_MUX_AE] || (byte)muxArg[-2] != BUFFER_SIZE_MUX_AE #if BUFFER_SIZE_MUX_AE < 255 || (byte)muxArg[-1] > BUFFER_SIZE_MUX_AE #endif || muxArg[BUFFER_SIZE_MUX_AE]) { /* Yiek! That looks very much like an overflow!! */ dprintf( ("[Memory corrupted during Installable Commands handler]\n") ); longjmp(jmp_beginning, E_CorruptMemory); } switch(r.r_ax & 0xFF) { case 0x00: /* No appropriate extension found */ break; default: /* Invalid response */ dprintf( ("[Invalid response from Installable Commands handler: 0x%02x]\n", r.r_ax & 0xFF) ); break; case 0xFF: /* Is an extension -> execute the Installable Command */ r2.r_ax = 0xae01; r2.r_cx = clen; intr(0x2f, &r2); if((byte)muxCmd[-2] != BUFFER_SIZE_MUX_AE #if BUFFER_SIZE_MUX_AE < 255 || (byte)muxCmd[-1] > BUFFER_SIZE_MUX_AE #endif || muxCmd[BUFFER_SIZE_MUX_AE] || (byte)muxArg[-2] != BUFFER_SIZE_MUX_AE #if BUFFER_SIZE_MUX_AE < 255 || (byte)muxArg[-1] > BUFFER_SIZE_MUX_AE #endif || muxArg[BUFFER_SIZE_MUX_AE]) { /* Yiek! That looks very much like an overflow!! */ dprintf( ("[Memory corrupted during Installable Commands handler]\n") ); longjmp(jmp_beginning, E_CorruptMemory); } if(muxCmd[-1] == 0) { /* The command had been processed */ myfree(muxBuf); return 1; /* Stop interpreting the command */ } break; } /* Cleanup: Adjust buffers and check for overflow */ /* Check command and transform it back into C-style string */ p = muxCmd + (byte)muxCmd[-1]; while(--p >= muxCmd && isspace(*p)); *++p = 0; if(*muxCmd) { if((p = erealloc(*command, (nlen = p - muxCmd) + 1)) == 0) { myfree(muxBuf); return 0; } StrFUpr(muxCmd); /* make sure it's still uppercased */ memcpy(*command = p, muxCmd, nlen + 1); } else { chkPtr(*command); StrFree(*command); nlen = 0; } /* Check the command line and transform it into a C-style string */ /* Must terminate as line[BUFFER_SIZE] == 0 */ p = muxArg + (byte)muxArg[-1]; while(--p >= muxArg && *p == '\xd'); *++p = 0; if((p - muxArg) >= nlen && ((p - muxArg) - nlen != llen || strcmp(&muxArg[nlen], line) != 0)) { /* new arguments */ /* Should never trigger, because the buffer for the command has the same size as the buffer for the argument itself. Because of the spurious length bytes: &muxArg[nlen] - muxBuf > BUFFER_SIZE_MUX_AE and because: strlen(&muxArg[nlen]) <= BUFFER_SIZE_MUX_AE both memory areas cannot overlap. */ assert(&muxArg[nlen] - muxBuf > BUFFER_SIZE_MUX_AE); assert(strlen(&muxArg[nlen]) < BUFFER_SIZE_MUX_AE); strcpy(muxBuf, &muxArg[nlen]); *newargs = StrTrim(muxBuf); return 0; } myfree(muxBuf); return 0; /* Proceed command processing as usual */ }
static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type) /* {{{ */ { pdo_oci_stmt *S = (pdo_oci_stmt*)stmt->driver_data; /* we're only interested in parameters for prepared SQL right now */ if (param->is_param) { pdo_oci_bound_param *P; sb4 value_sz = -1; P = (pdo_oci_bound_param*)param->driver_data; switch (event_type) { case PDO_PARAM_EVT_FETCH_PRE: case PDO_PARAM_EVT_FETCH_POST: case PDO_PARAM_EVT_NORMALIZE: /* Do nothing */ break; case PDO_PARAM_EVT_FREE: P = param->driver_data; if (P) { efree(P); } break; case PDO_PARAM_EVT_ALLOC: P = (pdo_oci_bound_param*)ecalloc(1, sizeof(pdo_oci_bound_param)); param->driver_data = P; /* figure out what we're doing */ switch (PDO_PARAM_TYPE(param->param_type)) { case PDO_PARAM_STMT: return 0; case PDO_PARAM_LOB: /* P->thing is now an OCILobLocator * */ P->oci_type = SQLT_BLOB; value_sz = sizeof(OCILobLocator*); break; case PDO_PARAM_STR: default: P->oci_type = SQLT_CHR; value_sz = param->max_value_len; if (param->max_value_len == 0) { value_sz = 1332; /* maximum size before value is interpreted as a LONG value */ } } if (param->name) { STMT_CALL(OCIBindByName, (S->stmt, &P->bind, S->err, (text*)param->name, param->namelen, 0, value_sz, P->oci_type, &P->indicator, 0, &P->retcode, 0, 0, OCI_DATA_AT_EXEC)); } else { STMT_CALL(OCIBindByPos, (S->stmt, &P->bind, S->err, param->paramno+1, 0, value_sz, P->oci_type, &P->indicator, 0, &P->retcode, 0, 0, OCI_DATA_AT_EXEC)); } STMT_CALL(OCIBindDynamic, (P->bind, S->err, param, oci_bind_input_cb, param, oci_bind_output_cb)); return 1; case PDO_PARAM_EVT_EXEC_PRE: P->indicator = 0; P->used_for_output = 0; if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) { ub4 empty = 0; STMT_CALL(OCIDescriptorAlloc, (S->H->env, &P->thing, OCI_DTYPE_LOB, 0, NULL)); STMT_CALL(OCIAttrSet, (P->thing, OCI_DTYPE_LOB, &empty, 0, OCI_ATTR_LOBEMPTY, S->err)); S->have_blobs = 1; } return 1; case PDO_PARAM_EVT_EXEC_POST: /* fixup stuff set in motion in oci_bind_output_cb */ if (P->used_for_output) { if (P->indicator == -1) { /* set up a NULL value */ if (Z_TYPE_P(param->parameter) == IS_STRING #if ZEND_EXTENSION_API_NO < 220040718 && Z_STRVAL_P(param->parameter) != empty_string #endif ) { /* OCI likes to stick non-terminated strings in things */ *Z_STRVAL_P(param->parameter) = '\0'; } zval_dtor(param->parameter); ZVAL_NULL(param->parameter); } else if (Z_TYPE_P(param->parameter) == IS_STRING #if ZEND_EXTENSION_API_NO < 220040718 && Z_STRVAL_P(param->parameter) != empty_string #endif ) { Z_STRLEN_P(param->parameter) = P->actual_len; Z_STRVAL_P(param->parameter) = erealloc(Z_STRVAL_P(param->parameter), P->actual_len+1); Z_STRVAL_P(param->parameter)[P->actual_len] = '\0'; } } else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB && P->thing) { php_stream *stm; if (Z_TYPE_P(param->parameter) == IS_NULL) { /* if the param is NULL, then we assume that they * wanted to bind a lob locator into it from the query * */ stm = oci_create_lob_stream(stmt, (OCILobLocator*)P->thing); if (stm) { OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE); php_stream_to_zval(stm, param->parameter); P->thing = NULL; } } else { /* we're a LOB being used for insert; transfer the data now */ size_t n; ub4 amt, offset = 1; char *consume; php_stream_from_zval_no_verify(stm, ¶m->parameter); if (stm) { OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE); do { char buf[8192]; n = php_stream_read(stm, buf, sizeof(buf)); if ((int)n <= 0) { break; } consume = buf; do { amt = n; OCILobWrite(S->H->svc, S->err, (OCILobLocator*)P->thing, &amt, offset, consume, n, OCI_ONE_PIECE, NULL, NULL, 0, SQLCS_IMPLICIT); offset += amt; n -= amt; consume += amt; } while (n); } while (1); OCILobClose(S->H->svc, S->err, (OCILobLocator*)P->thing); OCILobFlushBuffer(S->H->svc, S->err, (OCILobLocator*)P->thing, 0); } else if (Z_TYPE_P(param->parameter) == IS_STRING) { /* stick the string into the LOB */ consume = Z_STRVAL_P(param->parameter); n = Z_STRLEN_P(param->parameter); if (n) { OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE); while (n) { amt = n; OCILobWrite(S->H->svc, S->err, (OCILobLocator*)P->thing, &amt, offset, consume, n, OCI_ONE_PIECE, NULL, NULL, 0, SQLCS_IMPLICIT); consume += amt; n -= amt; } OCILobClose(S->H->svc, S->err, (OCILobLocator*)P->thing); } } OCIDescriptorFree(P->thing, OCI_DTYPE_LOB); P->thing = NULL; } } return 1; } } return 1; } /* }}} */
void zephir_concat_vvsv(zval **result, zval *op1, zval *op2, const char *op3, zend_uint op3_len, zval *op4, int self_var TSRMLS_DC){ zval result_copy, op1_copy, op2_copy, op4_copy; int use_copy = 0, use_copy1 = 0, use_copy2 = 0, use_copy4 = 0; uint offset = 0, length; if (Z_TYPE_P(op1) != IS_STRING) { zend_make_printable_zval(op1, &op1_copy, &use_copy1); if (use_copy1) { op1 = &op1_copy; } } if (Z_TYPE_P(op2) != IS_STRING) { zend_make_printable_zval(op2, &op2_copy, &use_copy2); if (use_copy2) { op2 = &op2_copy; } } if (Z_TYPE_P(op4) != IS_STRING) { zend_make_printable_zval(op4, &op4_copy, &use_copy4); if (use_copy4) { op4 = &op4_copy; } } length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4); if (self_var) { if (Z_TYPE_PP(result) != IS_STRING) { zend_make_printable_zval(*result, &result_copy, &use_copy); if (use_copy) { ZEPHIR_CPY_WRT_CTOR(*result, (&result_copy)); } } offset = Z_STRLEN_PP(result); length += offset; Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1); } else { Z_STRVAL_PP(result) = (char *) emalloc(length + 1); } memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1)); memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2)); memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), op3, op3_len); memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + op3_len, Z_STRVAL_P(op4), Z_STRLEN_P(op4)); Z_STRVAL_PP(result)[length] = 0; Z_TYPE_PP(result) = IS_STRING; Z_STRLEN_PP(result) = length; if (use_copy1) { zval_dtor(op1); } if (use_copy2) { zval_dtor(op2); } if (use_copy4) { zval_dtor(op4); } if (use_copy) { zval_dtor(&result_copy); } }
static void litespeed_php_import_environment_variables(zval *array_ptr) { char buf[128]; char **env, *p, *t = buf; size_t alloc_size = sizeof(buf); unsigned long nlen; /* ptrdiff_t is not portable */ #if PHP_MAJOR_VERSION >= 7 if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY && Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) && zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0 ) { zval_dtor(array_ptr); ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]); return; } else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) && zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0 ) { zval_dtor(array_ptr); ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]); return; } #else if (PG(http_globals)[TRACK_VARS_ENV] && array_ptr != PG(http_globals)[TRACK_VARS_ENV] && Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0 ) { zval_dtor(array_ptr); *array_ptr = *PG(http_globals)[TRACK_VARS_ENV]; INIT_PZVAL(array_ptr); zval_copy_ctor(array_ptr); return; } else if (PG(http_globals)[TRACK_VARS_SERVER] && array_ptr != PG(http_globals)[TRACK_VARS_SERVER] && Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0 ) { zval_dtor(array_ptr); *array_ptr = *PG(http_globals)[TRACK_VARS_SERVER]; INIT_PZVAL(array_ptr); zval_copy_ctor(array_ptr); return; } #endif for (env = environ; env != NULL && *env != NULL; env++) { p = strchr(*env, '='); if (!p) { /* malformed entry? */ continue; } nlen = p - *env; if (nlen >= alloc_size) { alloc_size = nlen + 64; t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size)); } memcpy(t, *env, nlen); t[nlen] = '\0'; add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr); } if (t != buf && t != NULL) { efree(t); } }
// // check for new messages on imap4 server // download new messages, mark deleted messages // static char* imap4read(Imap *imap, Mailbox *mb, int doplumb) { char *s; int i, ignore, nnew, t; Message *m, *next, **l; imap4cmd(imap, "STATUS %Z (MESSAGES UIDVALIDITY)", imap->mbox); if(!isokay(s = imap4resp(imap))) return s; imap->nuid = 0; imap->uid = erealloc(imap->uid, imap->nmsg*sizeof(imap->uid[0])); imap->muid = imap->nmsg; if(imap->nmsg > 0) { imap4cmd(imap, "UID FETCH 1:* UID"); if(!isokay(s = imap4resp(imap))) return s; } l = &mb->root->part; for(i=0; i<imap->nuid; i++) { ignore = 0; while(*l != nil) { if((*l)->imapuid == imap->uid[i]) { ignore = 1; l = &(*l)->next; break; } else { // old mail, we don't have it anymore if(doplumb) mailplumb(mb, *l, 1); (*l)->inmbox = 0; (*l)->deleted = 1; l = &(*l)->next; } } if(ignore) continue; // new message m = newmessage(mb->root); m->mallocd = 1; m->inmbox = 1; m->imapuid = imap->uid[i]; // add to chain, will download soon *l = m; l = &m->next; } // whatever is left at the end of the chain is gone while(*l != nil) { if(doplumb) mailplumb(mb, *l, 1); (*l)->inmbox = 0; (*l)->deleted = 1; l = &(*l)->next; } // download new messages t = imap->tag; if(pipeline) switch(rfork(RFPROC|RFMEM)) { case -1: sysfatal("rfork: %r"); default: break; case 0: for(m = mb->root->part; m != nil; m = m->next) { if(m->start != nil) continue; if(imap->debug) fprint(2, "9X%d UID FETCH %lud (UID RFC822.SIZE BODY[])\r\n", t, (ulong)m->imapuid); Bprint(&imap->bout, "9X%d UID FETCH %lud (UID RFC822.SIZE BODY[])\r\n", t++, (ulong)m->imapuid); } Bflush(&imap->bout); _exits(nil); } nnew = 0; for(m=mb->root->part; m!=nil; m=next) { next = m->next; if(m->start != nil) continue; if(!pipeline) { Bprint(&imap->bout, "9X%lud UID FETCH %lud (UID RFC822.SIZE BODY[])\r\n", (ulong)imap->tag, (ulong)m->imapuid); Bflush(&imap->bout); } if(s = imap4fetch(mb, m)) { // message disappeared? unchain fprint(2, "download %lud: %s\n", (ulong)m->imapuid, s); delmessage(mb, m); mb->root->subname--; continue; } nnew++; if(doplumb) mailplumb(mb, m, 0); } if(pipeline) waitpid(); if(nnew || mb->vers == 0) { mb->vers++; henter(PATH(0, Qtop), mb->name, (Qid) { PATH(mb->id, Qmbox), mb->vers, QTDIR }, nil, mb); } return nil; }
/* {{{ * common code shared by display_xyz functions to get the value from ICU }}} */ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS) { char* loc_name = NULL; int loc_name_len = 0; char* disp_loc_name = NULL; int disp_loc_name_len = 0; UChar* disp_name = NULL; int32_t disp_name_len = 0; char* mod_loc_name = NULL; int32_t buflen = 512; UErrorCode status = U_ZERO_ERROR; char* utf8value = NULL; int utf8value_len = 0; char* msg = NULL; int grOffset = 0; intl_error_reset( NULL TSRMLS_CC ); if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &loc_name, &loc_name_len , &disp_loc_name ,&disp_loc_name_len ) == FAILURE) { spprintf(&msg , 0, "locale_get_display_%s : unable to parse input params", tag_name ); intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, msg , 1 TSRMLS_CC ); efree(msg); RETURN_FALSE; } if(loc_name_len == 0) { loc_name = INTL_G(default_locale); } if( tag_name != DISP_NAME ){ /* Handle grandfathered languages */ grOffset = findOffset( LOC_GRANDFATHERED , loc_name ); if( grOffset >= 0 ){ if( strcmp(tag_name , LOC_LANG_TAG)==0 ){ mod_loc_name = getPreferredTag( loc_name ); } else { /* Since Grandfathered, no value, do nothing, retutn NULL */ RETURN_FALSE; } } } /* end of if != LOC_CANONICAL_TAG */ if( mod_loc_name==NULL ){ mod_loc_name = estrdup( loc_name ); } /* Get the disp_value for the given locale */ do{ disp_name = erealloc( disp_name , buflen ); disp_name_len = buflen; /* Check if disp_loc_name passed , if not use default locale */ if( !disp_loc_name){ disp_loc_name = estrdup(INTL_G(default_locale)); } if( strcmp(tag_name , LOC_LANG_TAG)==0 ){ buflen = uloc_getDisplayLanguage ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } else if( strcmp(tag_name , LOC_SCRIPT_TAG)==0 ){ buflen = uloc_getDisplayScript ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } else if( strcmp(tag_name , LOC_REGION_TAG)==0 ){ buflen = uloc_getDisplayCountry ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } else if( strcmp(tag_name , LOC_VARIANT_TAG)==0 ){ buflen = uloc_getDisplayVariant ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } else if( strcmp(tag_name , DISP_NAME)==0 ){ buflen = uloc_getDisplayName ( mod_loc_name , disp_loc_name , disp_name , disp_name_len , &status); } if( U_FAILURE( status ) ) { if( status == U_BUFFER_OVERFLOW_ERROR ) { status = U_ZERO_ERROR; continue; } spprintf(&msg, 0, "locale_get_display_%s : unable to get locale %s", tag_name , tag_name ); intl_error_set( NULL, status, msg , 1 TSRMLS_CC ); efree(msg); if( disp_name){ efree( disp_name ); } if( mod_loc_name){ efree( mod_loc_name ); } RETURN_FALSE; } } while( buflen > disp_name_len ); if( mod_loc_name){ efree( mod_loc_name ); } /* Convert display locale name from UTF-16 to UTF-8. */ intl_convert_utf16_to_utf8( &utf8value, &utf8value_len, disp_name, buflen, &status ); efree( disp_name ); if( U_FAILURE( status ) ) { spprintf(&msg, 0, "locale_get_display_%s :error converting display name for %s to UTF-8", tag_name , tag_name ); intl_error_set( NULL, status, msg , 1 TSRMLS_CC ); efree(msg); RETURN_FALSE; } RETVAL_STRINGL( utf8value, utf8value_len , FALSE); }
// // download a single message // static char* pop3download(Pop *pop, Message *m) { char *s, *f[3], *wp, *ep; char sdigest[SHA1dlen*2+1]; int i, l, sz; if(!pop->pipeline) pop3cmd(pop, "LIST %d", m->mesgno); if(!isokay(s = pop3resp(pop))) return s; if(tokenize(s, f, 3) != 3) return "syntax error in LIST response"; if(atoi(f[1]) != m->mesgno) return "out of sync with pop3 server"; sz = atoi(f[2])+200; /* 200 because the plan9 pop3 server lies */ if(sz == 0) return "invalid size in LIST response"; m->start = wp = emalloc(sz+1); ep = wp+sz; if(!pop->pipeline) pop3cmd(pop, "RETR %d", m->mesgno); if(!isokay(s = pop3resp(pop))) { m->start = nil; free(wp); return s; } s = nil; while(wp <= ep) { s = pop3resp(pop); if(strcmp(s, "unexpected eof") == 0) { free(m->start); m->start = nil; return "unexpected end of conversation"; } if(strcmp(s, ".") == 0) break; l = strlen(s)+1; if(s[0] == '.') { s++; l--; } /* * grow by 10%/200bytes - some servers * lie about message sizes */ if(wp+l > ep) { int pos = wp - m->start; sz += ((sz / 10) < 200)? 200: sz/10; m->start = erealloc(m->start, sz+1); wp = m->start+pos; ep = m->start+sz; } memmove(wp, s, l-1); wp[l-1] = '\n'; wp += l; } if(s == nil || strcmp(s, ".") != 0) return "out of sync with pop3 server"; m->end = wp; // make sure there's a trailing null // (helps in body searches) *m->end = 0; m->bend = m->rbend = m->end; m->header = m->start; // digest message sha1((uchar*)m->start, m->end - m->start, m->digest, nil); for(i = 0; i < SHA1dlen; i++) sprint(sdigest+2*i, "%2.2ux", m->digest[i]); m->sdigest = s_copy(sdigest); return nil; }
static void* TIDY_CALL php_tidy_realloc(void *buf, size_t len) { return erealloc(buf, len); }
/* {{{ gmp_erealloc */ static void *gmp_erealloc(void *ptr, size_t old_size, size_t new_size) { return erealloc(ptr, new_size); }
char *optctos(char c) { char *s = erealloc(NULL, 3); s[0] = '-', s[1] = c, s[2] = '\0'; return s; }
short int php_tmpl_pre_parse(t_template* tmpl) { ulong_pair *point; register uchar *p; uchar *buf; uint buf_len, buf_alloc, buf_this; uint i, j, len, close_idx; t_tmpl_tag *tag, *context; zval **ztag; if(FAILURE == php_tmpl_pre_parse_config(tmpl)) return FAILURE; /* Initialize variables */ PAIR_INIT(point); buf_alloc = TMPL_MAX_TAG_LEN+4; buf = (uchar*)emalloc(buf_alloc); /* Searching algorythm will require larger buffer */ (char*)ZV(tmpl->original) = erealloc(ZV(tmpl->original), ZL(tmpl->original) + MAX( ZL(tmpl->tag_left), MAX( ZL(tmpl->tag_right), MAX( ZL(tmpl->ctx_ol), MAX( ZL(tmpl->ctx_or), MAX( ZL(tmpl->ctx_cl), ZL(tmpl->ctx_cr) ) ) ) ) ) ); /* Obtain positions of all tags and contexts */ php_tmpl_pre_parse_search(tmpl, &point, TMPL_TAG, ZV(tmpl->tag_left), ZL(tmpl->tag_left)); php_tmpl_pre_parse_search(tmpl, &point, TMPL_TAG_END, ZV(tmpl->tag_right), ZL(tmpl->tag_right)); php_tmpl_pre_parse_search(tmpl, &point, TMPL_CONTEXT_OPEN_LEFT, ZV(tmpl->ctx_ol), ZL(tmpl->ctx_ol)); php_tmpl_pre_parse_search(tmpl, &point, TMPL_CONTEXT_OPEN_RIGHT, ZV(tmpl->ctx_or), ZL(tmpl->ctx_or)); php_tmpl_pre_parse_search(tmpl, &point, TMPL_CONTEXT_CLOSE_LEFT, ZV(tmpl->ctx_cl), ZL(tmpl->ctx_cl)); if(ZL(tmpl->ctx_cr)) php_tmpl_pre_parse_search(tmpl, &point, TMPL_CONTEXT_CLOSE_RIGHT, ZV(tmpl->ctx_cr), ZL(tmpl->ctx_cr)); if(0 == point[0].r) { TMPL_PRE_PARSE_CLEANUP; return SUCCESS; } qsort(&point[1], point[0].r, sizeof(ulong_pair), ULONG_PAIR_COMPARE); strcpy(buf, "/"); buf_len = buf_this = 1; /* Add root context */ TAG_INIT(tag); tag->loff = 0; tag->roff = ZL(tmpl->original); tag->typ = TMPL_CONTEXT; ZVAL_STRINGL(tag->name, "/", 1, 1); add_assoc_stringl(tmpl->tags, buf, (char*)tag, sizeof(t_tmpl_tag), 0); context = tag; context->size = ZL(tmpl->original); /* Pre parse template */ for(i=1; i <= point[0].r; i++) { switch(point[i].r) { case TMPL_TAG: p = ZV(tmpl->original) + point[i].l + ZL(tmpl->tag_left); TMPL_PRE_PARSE_GET_LEN(TMPL_TAG_END, ZL(tmpl->tag_left)); if(buf_alloc < buf_len+len+1) { while(buf_alloc < buf_len+len+1) buf_alloc += TMPL_MAX_TAG_LEN; buf = (char*)erealloc(buf, buf_alloc); } if(buf_len > 1) buf[buf_len++] = '/'; for(j=0; j < len; j++) buf[buf_len++] = tolower(*(p-len+j)); buf[buf_len] = 0; TAG_INIT(tag); tag->loff = point[i].l; tag->roff = point[close_idx].l + ZL(tmpl->tag_right); tag->size = (tag->roff - tag->loff); tag->typ = TMPL_TAG; tag->tag_num = 1; tag->ctx = context; ZVAL_STRINGL(tag->name, buf+buf_len-len, len, 1); if(FAILURE == zend_hash_find(Z_ARRVAL_P(tmpl->tags), buf, buf_len+1, (void*)&ztag)) { /* There's no the tag defined in the current context. Creating one */ add_assoc_stringl(tmpl->tags, buf, (char*)tag, sizeof(t_tmpl_tag), 0); context->tag_num++; } else { /* add another instance of the tag in the same context */ (Z_TMPL_TAG(ztag)->tag_num)++; add_next_index_stringl(tmpl->dup_tag, (char*)tag, sizeof(t_tmpl_tag), 0); } context->size -= tag->size; while(buf_len > 1 && buf[buf_len-1] != '/') buf[--buf_len] = 0; if(buf_len > 1) buf[--buf_len] = 0; i = close_idx; break; case TMPL_CONTEXT_OPEN_LEFT: p = ZV(tmpl->original) + point[i].l + ZL(tmpl->ctx_ol); TMPL_PRE_PARSE_GET_LEN(TMPL_CONTEXT_OPEN_RIGHT, ZL(tmpl->ctx_ol)); if(buf_alloc < buf_len+len+1) { while(buf_alloc < buf_len+len+1) buf_alloc += TMPL_MAX_TAG_LEN; buf = (char*)erealloc(buf, buf_alloc); } if(buf_len > 1) buf[buf_len++] = '/'; buf_this = buf_len; for(j=0; j < len; j++) buf[buf_len++] = tolower(*(p-len+j)); buf[buf_len] = 0; if(SUCCESS == zend_hash_find(Z_ARRVAL_P(tmpl->tags), buf, buf_len+1, (void*)&ztag)) { php_error(E_ERROR, "Duplicate context \"%s\" in template (line: %d)", buf, php_tmpl_line_num(tmpl, p)); TMPL_PRE_PARSE_CLEANUP; return FAILURE; } TAG_INIT(tag); tag->loff = point[i].l; tag->typ = TMPL_CONTEXT; tag->ctx = context; ZVAL_STRINGL(tag->name, buf+buf_len-len, len, 1); add_assoc_stringl(tmpl->tags, buf, (char*)tag, sizeof(t_tmpl_tag), 0); context->tag_num++; context = tag; i = close_idx; break; case TMPL_CONTEXT_CLOSE_LEFT: p = ZV(tmpl->original) + point[i].l + ZL(tmpl->ctx_cl); if(ZL(tmpl->ctx_cr)) { TMPL_PRE_PARSE_GET_LEN(TMPL_CONTEXT_CLOSE_RIGHT, ZL(tmpl->ctx_cl)); for(j=0; j < len; j++) if(buf[buf_this+j] != tolower(*(p-len+j))) break; if(j < len) continue; } tag = context; tag->roff = ZL(tmpl->ctx_cr) ? point[close_idx].l + ZL(tmpl->ctx_cr) : point[i].l + ZL(tmpl->ctx_cl); tag->size += (tag->roff - tag->loff); while(buf_len > 1 && buf[buf_len-1] != '/') buf[--buf_len] = 0; if(buf_len > 1) buf[--buf_len] = 0; buf_this = buf_len; while(buf_this > 1 && buf[buf_this-1] != '/') --buf_this; if(FAILURE == zend_hash_find(Z_ARRVAL_P(tmpl->tags), buf, buf_len+1, (void*)&ztag)) { php_error(E_ERROR, "Can't find parent context in template. You should not see this message"); TMPL_PRE_PARSE_CLEANUP; return FAILURE; } context = (t_tmpl_tag*)Z_STRVAL_PP(ztag); context->size -= tag->size; if(ZL(tmpl->ctx_cr)) i = close_idx; break; } } if(buf_len != 1) { php_error(E_ERROR, "Can't continue with an unterminated context \"%s\" in template (line:%d)", buf, php_tmpl_line_num(tmpl, ZV(tmpl->original) + context->loff)); TMPL_PRE_PARSE_CLEANUP; return FAILURE; } tmpl->size = context->size; TMPL_PRE_PARSE_CLEANUP; return SUCCESS; }
static Type* parsedefn(char *p, Type *t, char **pp) { char c, *name; int ischar, namelen, n, wid, offset, bits, sign; long val; Type *tt; if(*p == '(' || isdigit((uchar)*p)){ t->ty = Defer; t->sub = parseinfo(p, pp); return t; } switch(c = *p){ case '-': /* builtin */ n = strtol(p+1, &p, 10); if(n >= nelem(baseints) || n < 0) n = 0; t->ty = Base; t->xsizeof = baseints[n].size; t->printfmt = baseints[n].fmt; break; case 'b': /* builtin */ p++; if(*p != 'u' && *p != 's') oops(); sign = (*p == 's'); p++; ischar = 0; if(*p == 'c'){ ischar = 1; p++; } wid = parseint(&p); semi(&p); offset = parseint(&p); semi(&p); bits = parseint(&p); semi(&p); t->ty = Base; t->xsizeof = wid; if(sign == 1) t->printfmt = 'd'; else t->printfmt = 'x'; USED(bits); USED(ischar); break; case 'R': /* fp type */ n = parseint(&p); semi(&p); wid = parseint(&p); semi(&p); t->ty = Base; t->xsizeof = wid; if(n < 0 || n >= nelem(basefloats)) n = 0; t->xsizeof = basefloats[n].size; t->printfmt = basefloats[n].fmt; break; case 'r': /* subrange */ t->ty = Range; t->sub = parseinfo(p+1, &p); if(*(p-1) == ';' && *p != ';') p--; semi(&p); t->lo = parsebound(&p); semi(&p); t->hi = parsebound(&p); semi(&p); break; case 'B': /* volatile */ case 'k': /* const */ t->ty = Defer; t->sub = parseinfo(p+1, &p); break; case '*': /* pointer */ case 'A': /* open array */ case '&': /* reference */ /* guess - C++? (rob) */ t->ty = Pointer; t->sub = parseinfo(p+1, &p); break; case 'a': /* array */ case 'P': /* packed array */ t->ty = Pointer; tt = newtype(); parsedefn(p+1, tt, &p); /* index type */ if(*p == ';') p++; tt = newtype(); t->sub = tt; parsedefn(p, tt, &p); /* element type */ break; case 'e': /* enum listing */ p++; t->sue = 'e'; t->ty = Enum; while(*p != ';'){ name = p; p = findcolon(p)+1; namelen = (p-name)-1; val = parsebigint(&p); comma(&p); if(t->n%32 == 0){ t->tname = erealloc(t->tname, (t->n+32)*sizeof(t->tname[0])); t->val = erealloc(t->val, (t->n+32)*sizeof(t->val[0])); } t->tname[t->n] = estrndup(name, namelen); t->val[t->n] = val; t->n++; } semi(&p); break; case 's': /* struct */ case 'u': /* union */ p++; t->sue = c; t->ty = Aggr; n = parseint(&p); while(*p != ';'){ name = p; p = findcolon(p)+1; namelen = (p-name)-1; tt = parseinfo(p, &p); comma(&p); offset = parseint(&p); comma(&p); bits = parseint(&p); semi(&p); if(t->n%32 == 0){ t->tname = erealloc(t->tname, (t->n+32)*sizeof(t->tname[0])); t->val = erealloc(t->val, (t->n+32)*sizeof(t->val[0])); t->t = erealloc(t->t, (t->n+32)*sizeof(t->t[0])); } t->tname[t->n] = estrndup(name, namelen); t->val[t->n] = offset; t->t[t->n] = tt; t->n++; } semi(&p); break; case 'x': /* struct, union, enum reference */ p++; t->ty = Defer; if(*p != 's' && *p != 'u' && *p != 'e') oops(); c = *p; name = p+1; p = findcolon(p+1); name = estrndup(name, p-name); t->sub = typebysue(c, name); p++; break; #if 0 /* AIX */ case 'f': /* function */ case 'p': /* procedure */ case 'F': /* Pascal function */ /* case 'R': /* Pascal procedure */ /* * Even though we don't use the info, we have * to parse it in case it is embedded in other descriptions. */ t->ty = Function; p++; if(c == 'f' || c == 'F'){ t->sub = parseinfo(p, &p); if(*p != ','){ if(*p == ';') p++; break; } comma(&p); } n = parseint(&p); /* number of params */ semi(&p); while(*p != ';'){ if(c == 'F' || c == 'R'){ name = p; /* parameter name */ p = findcolon(p)+1; } parseinfo(p, &p); /* param type */ comma(&p); parseint(&p); /* bool: passed by value? */ semi(&p); } semi(&p); break; #endif case 'f': /* static function */ case 'F': /* global function */ t->ty = Function; p++; t->sub = parseinfo(p, &p); break; /* * We'll never see any of this stuff. * When we do, we can worry about it. */ case 'D': /* n-dimensional array */ case 'E': /* subarray of n-dimensional array */ case 'M': /* fortran multiple instance type */ case 'N': /* pascal string ptr */ case 'S': /* set */ case 'c': /* aix complex */ case 'd': /* file of */ case 'g': /* aix float */ case 'n': /* max length string */ case 'w': /* aix wide char */ case 'z': /* another max length string */ default: fprint(2, "unsupported type char %c (%d)\n", *p, *p); oops(); } *pp = p; return t; }
int kswitch(struct kswitch_options *opt, int argc, char **argv) { krb5_error_code ret; krb5_ccache id = NULL; if (opt->cache_string && opt->principal_string) krb5_errx(kcc_context, 1, N_("Both --cache and --principal given, choose one", "")); if (opt->interactive_flag) { krb5_cc_cache_cursor cursor; krb5_ccache *ids = NULL; size_t i, len = 0; char *name; rtbl_t ct; ct = rtbl_create(); rtbl_add_column_by_id(ct, 0, "#", 0); rtbl_add_column_by_id(ct, 1, "Principal", 0); rtbl_set_column_affix_by_id(ct, 1, " ", ""); rtbl_add_column_by_id(ct, 2, "Type", 0); rtbl_set_column_affix_by_id(ct, 2, " ", ""); ret = krb5_cc_cache_get_first(kcc_context, NULL, &cursor); if (ret) krb5_err(kcc_context, 1, ret, "krb5_cc_cache_get_first"); while (krb5_cc_cache_next(kcc_context, cursor, &id) == 0) { krb5_principal p; char num[10]; ret = krb5_cc_get_principal(kcc_context, id, &p); if (ret) continue; ret = krb5_unparse_name(kcc_context, p, &name); krb5_free_principal(kcc_context, p); snprintf(num, sizeof(num), "%d", (int)(len + 1)); rtbl_add_column_entry_by_id(ct, 0, num); rtbl_add_column_entry_by_id(ct, 1, name); rtbl_add_column_entry_by_id(ct, 2, krb5_cc_get_type(kcc_context, id)); free(name); ids = erealloc(ids, (len + 1) * sizeof(ids[0])); ids[len] = id; len++; } krb5_cc_cache_end_seq_get(kcc_context, cursor); rtbl_format(ct, stdout); rtbl_destroy(ct); name = readline("Select number: "); if (name) { i = atoi(name); if (i == 0) krb5_errx(kcc_context, 1, "Cache number '%s' is invalid", name); if (i > len) krb5_errx(kcc_context, 1, "Cache number '%s' is too large", name); id = ids[i - 1]; ids[i - 1] = NULL; } else krb5_errx(kcc_context, 1, "No cache selected"); for (i = 0; i < len; i++) if (ids[i]) krb5_cc_close(kcc_context, ids[i]); } else if (opt->principal_string) { krb5_principal p; ret = krb5_parse_name(kcc_context, opt->principal_string, &p); if (ret) krb5_err(kcc_context, 1, ret, "krb5_parse_name: %s", opt->principal_string); ret = krb5_cc_cache_match(kcc_context, p, &id); if (ret) krb5_err(kcc_context, 1, ret, N_("Did not find principal: %s", ""), opt->principal_string); krb5_free_principal(kcc_context, p); } else if (opt->cache_string) { const krb5_cc_ops *ops; char *str; ops = krb5_cc_get_prefix_ops(kcc_context, opt->type_string); if (ops == NULL) krb5_err(kcc_context, 1, 0, "krb5_cc_get_prefix_ops"); asprintf(&str, "%s:%s", ops->prefix, opt->cache_string); if (str == NULL) krb5_errx(kcc_context, 1, N_("out of memory", "")); ret = krb5_cc_resolve(kcc_context, str, &id); if (ret) krb5_err(kcc_context, 1, ret, "krb5_cc_resolve: %s", str); free(str); } else { krb5_errx(kcc_context, 1, "missing option for kswitch"); } ret = krb5_cc_switch(kcc_context, id); if (ret) krb5_err(kcc_context, 1, ret, "krb5_cc_switch"); return 0; }