static int parsing(parse_engine* engine, json_object *pos_parse) { wchar_t c = next_token(engine); switch (c) { case 0: engine->message = (wchar_t *)L"Unexpected end"; return 1; case '[': { pos_parse->type = ARRAY; pos_parse->value.item = 0; if (next_token(engine) == ']') return 0; --engine->pos; while (1) { json_object *item = insert_item(pos_parse, 0); if (next_token(engine) == ',') { --engine->pos; } else { --engine->pos; if (parsing(engine, item)) return 1; } switch (next_token(engine)) { case ',': if (next_token(engine) == ']') return 0; --engine->pos; break; case ']': return 0; default: engine->message = (wchar_t *)L":Expected a ',' or ']'"; return 1; } } } case '{': { pos_parse->type = TABLE; pos_parse->value.item = 0; if (next_token(engine) == '}') return 0; --engine->pos; while (1) { json_object key; if (parsing(engine, &key) || key.type != TEXT) { json_object_free(&key); engine->message = (wchar_t *)L"Illegal key of pair"; return 1; } if (next_token(engine) != ':') { engine->message = (wchar_t *)L"Expected a ':'"; return 1; } json_object* item=insert_item(pos_parse, key.value.text); json_object_free(&key); if (parsing(engine, item)) { return 1; } switch (next_token(engine)) { case ';': case ',': if (next_token(engine) == '}') return 0; --engine->pos; break; case '}': return 0; default: engine->message = (wchar_t *)L"Expected a ',' or '}'"; return 1; } } } case '\'': case '"': { pos_parse->type = TEXT; pos_parse->value.text = 0; strlist str = { 0 }; while (1) { wchar_t ch = *engine->pos++; switch (ch) { case '\n': case '\r': strlist_free(&str); engine->message = (wchar_t *)L"Unterminated string"; return 1; case '\\': ch = *engine->pos++; switch (ch) { case 'b': strlist_append(&str, L"\b", 1); break; case 't': strlist_append(&str, L"\t", 1); break; case 'n': strlist_append(&str, L"\n", 1); break; case 'f': strlist_append(&str, L"\f", 1); break; case 'r': strlist_append(&str, L"\r", 1); break; case '"': case '\'': case '\\': case '/': strlist_append(&str, &ch, 1); break; case 'u': { wchar_t num = 0; for (int i = 0; i < 4; ++i) { wchar_t tmp = *engine->pos++; if (tmp >= '0'&&tmp <= '9') tmp = tmp - '0'; else if (tmp >= 'A'&&tmp <= 'F') tmp = tmp - ('A' - 10); else if (tmp >= 'a'&&tmp <= 'f') tmp = tmp - ('a' - 10); num = num << 4 | tmp; } strlist_append(&str, &num, 1); break; } default: strlist_free(&str); engine->message = (wchar_t *)L"Illegal escape"; return 1; } break; default: if (ch == c) { pos_parse->value.text = strlist_to_string(&str); strlist_free(&str); return 0; } strlist_append(&str, &ch, 1); break; } } break; } } int length = 0; char buffer[32] = { 0 }; while (c >= ' ') { if(strchr(",:]}/\\\"[{;=#", c)) break; if(length<sizeof(buffer)&&strchr("0123456789+-.AEFLNRSTUaeflnrstu",c)) { buffer[length++]=(char)c; c = *engine->pos++; } else{ engine->message=(wchar_t *)L"Illegal Value"; return 1; } } --engine->pos; if (!length) { pos_parse->type = TEXT; pos_parse->value.text = (wchar_t *)malloc(sizeof(wchar_t)); pos_parse->value.text[0] = 0; return 0; } else { if (!strcmp(buffer, "TRUE") || !strcmp(buffer, "true")) { pos_parse->type = BOOLEAN; pos_parse->value.boolean = true; return 0; } else if (!strcmp(buffer, "FALSE") || !strcmp(buffer, "false")) { pos_parse->type = BOOLEAN; pos_parse->value.boolean = false; return 0; } else if (!strcmp(buffer, "NULL") || !strcmp(buffer, "null")) { pos_parse->type = NONE; return 0; } pos_parse->type = (strstr(buffer, ".") || strstr(buffer, "e") || strstr(buffer, "E")) ? DECIMAL : INTEGER; const char *format = pos_parse->type == INTEGER ? "%lld" : "%lf"; if (sscanf(buffer, format, &pos_parse->value)) return 0; engine->message = (wchar_t *)L"Unexpected end"; return 1; } }
static int fit_config_get_data(void *fit, int conf_noffset, int noffset, struct image_region **regionp, int *region_countp, char **region_propp, int *region_proplen) { char * const exc_prop[] = {"data"}; struct strlist node_inc; struct image_region *region; struct fdt_region fdt_regions[100]; const char *conf_name, *sig_name; char path[200]; int count, i; char *region_prop; int ret, len; conf_name = fit_get_name(fit, conf_noffset, NULL); sig_name = fit_get_name(fit, conf_noffset, NULL); debug("%s: conf='%s', sig='%s'\n", __func__, conf_name, sig_name); /* Get a list of nodes we want to hash */ ret = fit_config_get_hash_list(fit, conf_noffset, noffset, &node_inc); if (ret) return ret; /* Get a list of regions to hash */ count = fdt_find_regions(fit, node_inc.strings, node_inc.count, exc_prop, ARRAY_SIZE(exc_prop), fdt_regions, ARRAY_SIZE(fdt_regions), path, sizeof(path), 1); if (count < 0) { printf("Failed to hash configuration '%s/%s': %s\n", conf_name, sig_name, fdt_strerror(ret)); return -EIO; } if (count == 0) { printf("No data to hash for configuration '%s/%s': %s\n", conf_name, sig_name, fdt_strerror(ret)); return -EINVAL; } /* Build our list of data blocks */ region = fit_region_make_list(fit, fdt_regions, count, NULL); if (!region) { printf("Out of memory hashing configuration '%s/%s'\n", conf_name, sig_name); return -ENOMEM; } /* Create a list of all hashed properties */ debug("Hash nodes:\n"); for (i = len = 0; i < node_inc.count; i++) { debug(" %s\n", node_inc.strings[i]); len += strlen(node_inc.strings[i]) + 1; } region_prop = malloc(len); if (!region_prop) { printf("Out of memory setting up regions for configuration '%s/%s'\n", conf_name, sig_name); return -ENOMEM; } for (i = len = 0; i < node_inc.count; len += strlen(node_inc.strings[i]) + 1, i++) strcpy(region_prop + len, node_inc.strings[i]); strlist_free(&node_inc); *region_countp = count; *regionp = region; *region_propp = region_prop; *region_proplen = len; return 0; }
bool service_list(struct client *cli, const char *user) { GList *files = NULL, *content = NULL; char *s; enum errcode err = InternalError; int rc; bool rcb; DB_TXN *txn = NULL; DBC *cur = NULL; DB_ENV *dbenv = tdbrep.tdb.env; DB *bidx = tdbrep.tdb.buckets_idx; DBT skey, pkey, pval; if (asprintf(&s, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" "<ListAllMyBucketsResult xmlns=\"http://indy.yyz.us/doc/2006-03-01/\">\r\n" " <Owner>\r\n" " <ID>%s</ID>\r\n" " <DisplayName>%s</DisplayName>\r\n" " </Owner>\r\n" " <Buckets>\r\n", user, user) < 0) goto err_out; content = g_list_append(content, s); /* open transaction, search cursor */ rc = dbenv->txn_begin(dbenv, NULL, &txn, 0); if (rc) { dbenv->err(dbenv, rc, "DB_ENV->txn_begin"); goto err_out_content; } rc = bidx->cursor(bidx, txn, &cur, 0); if (rc) { bidx->err(bidx, rc, "bidx->cursor"); goto err_out_content; } memset(&skey, 0, sizeof(skey)); memset(&pkey, 0, sizeof(pkey)); memset(&pval, 0, sizeof(pval)); skey.data = (char *) user; skey.size = strlen(user) + 1; /* FIXME: Use of DB_NEXT rather than DB_SET to begin search * means we iterate through entire db, rather than * starting at the first matching key. */ /* loop through matching buckets, if any */ while (1) { char timestr[64]; struct db_bucket_ent *ent; rc = cur->pget(cur, &skey, &pkey, &pval, DB_NEXT); if (rc) break; ent = pval.data; s = g_markup_printf_escaped( " <Bucket>\r\n" " <Name>%s</Name>\r\n" " <CreationDate>%s</CreationDate>\r\n" " </Bucket>\r\n", ent->name, hutil_time2str(timestr, sizeof(timestr), GUINT64_FROM_LE(ent->time_create))); if (!s) goto err_out_content; content = g_list_append(content, s); } if (rc != DB_NOTFOUND) bidx->err(bidx, rc, "service_list iter"); /* close cursor, transaction */ rc = cur->close(cur); if (rc) bidx->err(bidx, rc, "bidx->cursor close"); rc = txn->commit(txn, 0); if (rc) dbenv->err(dbenv, rc, "DB_ENV->txn_commit"); if (asprintf(&s, " </Buckets>\r\n" "</ListAllMyBucketsResult>\r\n") < 0) goto err_out_content; content = g_list_append(content, s); rcb = cli_resp_xml(cli, 200, content); strlist_free(files); g_list_free(content); return rcb; err_out_content: strlist_free(content); err_out: strlist_free(files); return cli_err(cli, err); }
static void ctw_clear_headers(struct _ctw *common) { strlist_free(common->http_headers); common->http_headers = NULL; }