int main(int argc, char **argv) { line_ctx ctx; if (argc != 2) { printf("Usage: %s <filename>\n", argv[0]); return 1; } memset(&ctx, 0, sizeof(ctx)); lwc_intern_string("class", SLEN("class"), &ctx.attr_class); lwc_intern_string("id", SLEN("id"), &ctx.attr_id); assert(css__parse_testfile(argv[1], handle_line, &ctx) == true); /* and run final test */ if (ctx.tree != NULL) run_test(&ctx, ctx.exp, ctx.expused); free(ctx.exp); lwc_string_unref(ctx.attr_class); lwc_string_unref(ctx.attr_id); lwc_iterate_strings(printing_lwc_iterator, NULL); assert(fail_because_lwc_leaked == false); printf("PASS\n"); return 0; }
END_TEST START_TEST (test_lwc_intern_string_twice_same_ok) { lwc_string *str1 = NULL, *str2 = NULL; fail_unless(lwc_intern_string("A", 1, &str1) == lwc_error_ok, "Unable to intern a simple string"); fail_unless(str1 != NULL, "Returned OK but str was still NULL"); fail_unless(lwc_intern_string("A", 1, &str2) == lwc_error_ok, "Unable to intern a simple string"); fail_unless(str2 != NULL, "Returned OK but str was still NULL"); }
static const ULONG ami_file_asl_mime_hook(struct Hook *mh, struct FileRequester *fr, struct AnchorPathOld *ap) { char fname[1024]; BOOL ret = FALSE; char *mt = NULL; lwc_string *lwc_mt = NULL; lwc_error lerror; content_type ct; if(ap->ap_Info.fib_DirEntryType > 0) return(TRUE); strcpy(fname,fr->fr_Drawer); AddPart(fname,ap->ap_Info.fib_FileName,1024); mt = strdup(fetch_filetype(fname)); lerror = lwc_intern_string(mt, strlen(mt), &lwc_mt); if (lerror != lwc_error_ok) return FALSE; ct = content_factory_type_from_mime_type(lwc_mt); lwc_string_unref(lwc_mt); if(ct != CONTENT_NONE) ret = TRUE; free(mt); return ret; }
/** * Create an interned DOM string from a string of characters * * \param ptr Pointer to string of characters * \param len Length, in bytes, of string of characters * \param str Pointer to location to receive result * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion * * The returned string will already be referenced, so there is no need * to explicitly reference it. * * The string of characters passed in will be copied for use by the * returned DOM string. */ dom_exception dom_string_create_interned(const uint8_t *ptr, size_t len, dom_string **str) { dom_string_internal *ret; if (ptr == NULL || len == 0) { ptr = (const uint8_t *) ""; len = 0; } ret = malloc(sizeof(*ret)); if (ret == NULL) return DOM_NO_MEM_ERR; if (lwc_intern_string((const char *) ptr, len, &ret->data.intern) != lwc_error_ok) { free(ret); return DOM_NO_MEM_ERR; } ret->base.refcnt = 1; ret->type = DOM_STRING_INTERNED; *str = (dom_string *)ret; return DOM_NO_ERR; }
/** * Register a handler with the content factory * * \param mime_type MIME type to handle * \param handler Content handler for MIME type * \return NSERROR_OK on success, appropriate error otherwise * * \note Latest registration for a MIME type wins */ nserror content_factory_register_handler(const char *mime_type, const content_handler *handler) { lwc_string *imime_type; lwc_error lerror; content_handler_entry *entry; bool match; lerror = lwc_intern_string(mime_type, strlen(mime_type), &imime_type); if (lerror != lwc_error_ok) return NSERROR_NOMEM; for (entry = content_handlers; entry != NULL; entry = entry->next) { if (lwc_string_caseless_isequal(imime_type, entry->mime_type, &match) == lwc_error_ok && match) break; } if (entry == NULL) { entry = malloc(sizeof(content_handler_entry)); if (entry == NULL) return NSERROR_NOMEM; entry->next = content_handlers; content_handlers = entry; entry->mime_type = imime_type; } else { lwc_string_unref(imime_type); } entry->handler = handler; return NSERROR_OK; }
void fetch_rsrc_register(void) { lwc_string *scheme; int err; err = find_app_resources(); if (err < B_OK) { warn_user("Resources", strerror(err)); return; } if (lwc_intern_string("rsrc", SLEN("rsrc"), &scheme) != lwc_error_ok) { die("Failed to initialise the fetch module " "(couldn't intern \"rsrc\")."); } fetch_add_fetcher(scheme, fetch_rsrc_initialise, fetch_rsrc_can_fetch, fetch_rsrc_setup, fetch_rsrc_start, fetch_rsrc_abort, fetch_rsrc_free, fetch_rsrc_poll, fetch_rsrc_finalise); }
/** callback to initialise the resource fetcher. */ static bool fetch_resource_initialise(lwc_string *scheme) { struct fetch_resource_map_entry *e; uint32_t i; fetch_resource_path_count = 0; for (i = 0; i < NOF_ELEMENTS(fetch_resource_paths); i++) { e = &fetch_resource_map[fetch_resource_path_count]; if (lwc_intern_string(fetch_resource_paths[i], strlen(fetch_resource_paths[i]), &e->path) != lwc_error_ok) { while (i > 0) { i--; lwc_string_unref(fetch_resource_map[i].path); nsurl_unref(fetch_resource_map[i].url); } } e->url = gui_get_resource_url(fetch_resource_paths[i]); LOG(("URL is %s " ,lwc_string_data(e->path))); if (e->url == NULL) { lwc_string_unref(e->path); } else { fetch_resource_path_count++; } } return true; }
bool gui_system_colour_init(void) { unsigned int ccount; if (gui_system_colour_pw != NULL) return false; /* Intern colour strings */ for (ccount = 0; ccount < colour_list_len; ccount++) { if (lwc_intern_string(colour_list[ccount].name, colour_list[ccount].length, &(colour_list[ccount].lwcstr)) != lwc_error_ok) { return false; } } /* pull in options if set (ie not transparent) */ for (ccount = 0; ccount < colour_list_len; ccount++) { if (*(colour_list[ccount].option_colour) != 0) { colour_list[ccount].colour = *(colour_list[ccount].option_colour); } } gui_system_colour_pw = colour_list; return true; }
static void with_filled_context_setup(void) { fail_unless(lwc_intern_string("one", 3, &intern_one) == lwc_error_ok, "Unable to intern 'one'"); fail_unless(lwc_intern_string("two", 3, &intern_two) == lwc_error_ok, "Unable to intern 'two'"); fail_unless(lwc_intern_string("three", 5, &intern_three) == lwc_error_ok, "Unable to intern 'three'"); fail_unless(lwc_intern_string("YAY", 3, &intern_YAY) == lwc_error_ok, "Unable to intern 'YAY'"); fail_unless(intern_one != intern_two, "'one' == 'two'"); fail_unless(intern_one != intern_three, "'one' == 'three'"); fail_unless(intern_two != intern_three, "'two' == 'three'"); }
/** * Make the dom_string be interned * * \param str The dom_string to be interned * \param lwcstr The result lwc_string * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception dom_string_intern(dom_string *str, struct lwc_string_s **lwcstr) { dom_string_internal *istr = (dom_string_internal *) str; /* If this string is already interned, do nothing */ if (istr->type != DOM_STRING_INTERNED) { lwc_string *ret; lwc_error lerr; lerr = lwc_intern_string((const char *) istr->data.cdata.ptr, istr->data.cdata.len, &ret); if (lerr != lwc_error_ok) { return _dom_exception_from_lwc_error(lerr); } free(istr->data.cdata.ptr); istr->data.intern = ret; istr->type = DOM_STRING_INTERNED; } *lwcstr = lwc_string_ref(istr->data.intern); return DOM_NO_ERR; }
END_TEST START_TEST (test_lwc_intern_substring_aborts2) { lwc_string *str; fail_unless(lwc_intern_string("Jam", 3, &str) == lwc_error_ok, "unable to intern 'Jam'"); lwc_intern_substring(str, 88, 77, NULL); }
END_TEST START_TEST (test_lwc_string_is_nul_terminated) { lwc_string *new_ONE; fail_unless(lwc_intern_string("ONE", 3, &new_ONE) == lwc_error_ok, "Failure interning 'ONE'"); fail_unless(lwc_string_data(new_ONE)[lwc_string_length(new_ONE)] == '\0', "Interned string isn't NUL terminated"); }
void fetch_init(void) { fetch_curl_register(); fetch_data_register(); fetch_file_register(); fetch_resource_register(); fetch_about_register(); fetch_active = false; if (lwc_intern_string("http", SLEN("http"), &fetch_http_lwc) != lwc_error_ok) { die("Failed to initialise the fetch module " "(couldn't intern \"http\")."); } if (lwc_intern_string("https", SLEN("https"), &fetch_https_lwc) != lwc_error_ok) { die("Failed to initialise the fetch module " "(couldn't intern \"https\")."); } }
END_TEST START_TEST (test_lwc_intern_substring) { lwc_string *new_hre = NULL, *sub_hre = NULL; fail_unless(lwc_intern_string("hre", 3, &new_hre) == lwc_error_ok, "Unable to intern 'hre'"); fail_unless(lwc_intern_substring(intern_three, 1, 3, &sub_hre) == lwc_error_ok, "Unable to re-intern 'hre' by substring"); fail_unless(new_hre == sub_hre, "'hre' != 'hre' -- wow!"); }
lwc_error lwc_intern_substring(lwc_string *str, size_t ssoffset, size_t sslen, lwc_string **ret) { assert(str); assert(ret); if (ssoffset >= str->len) return lwc_error_range; if ((ssoffset + sslen) > str->len) return lwc_error_range; return lwc_intern_string(CSTR_OF(str) + ssoffset, sslen, ret); }
END_TEST START_TEST (test_lwc_string_caseless_isequal_ok2) { bool result = true; lwc_string *new_yay; fail_unless(lwc_intern_string("yay", 3, &new_yay) == lwc_error_ok, "Failure interning 'yay'"); fail_unless((lwc_string_isequal(intern_YAY, new_yay, &result)) == lwc_error_ok); fail_unless(result == false, "'yay' == 'YAY' ?!"); fail_unless((lwc_string_caseless_isequal(intern_YAY, new_yay, &result)) == lwc_error_ok, "Failure comparing 'yay' and 'YAY' caselessly"); fail_unless(result == true, "'yay' !~= 'YAY' ?!"); }
END_TEST START_TEST (test_lwc_string_caseless_isequal_ok1) { bool result = true; lwc_string *new_ONE; fail_unless(lwc_intern_string("ONE", 3, &new_ONE) == lwc_error_ok, "Failure interning 'ONE'"); fail_unless((lwc_string_isequal(intern_one, new_ONE, &result)) == lwc_error_ok); fail_unless(result == false, "'one' == 'ONE' ?!"); fail_unless((lwc_string_caseless_isequal(intern_one, new_ONE, &result)) == lwc_error_ok, "Failure comparing 'one' and 'ONE' caselessly"); fail_unless(result == true, "'one' !~= 'ONE' ?!"); }
/** callback to initialise the about fetcher. */ static bool fetch_about_initialise(lwc_string *scheme) { unsigned int abt_loop = 0; lwc_error error; for (abt_loop = 0; abt_loop < about_handler_list_len; abt_loop++) { error = lwc_intern_string(about_handler_list[abt_loop].name, about_handler_list[abt_loop].name_len, &about_handler_list[abt_loop].lname); if (error != lwc_error_ok) { while (abt_loop-- != 0) { lwc_string_unref(about_handler_list[abt_loop].lname); } return false; } } return true; }
void fetch_resource_register(void) { lwc_string *scheme; if (lwc_intern_string("resource", SLEN("resource"), &scheme) != lwc_error_ok) { die("Failed to initialise the fetch module " "(couldn't intern \"resource\")."); } fetch_add_fetcher(scheme, fetch_resource_initialise, fetch_resource_can_fetch, fetch_resource_setup, fetch_resource_start, fetch_resource_abort, fetch_resource_free, fetch_resource_poll, fetch_resource_finalise); }
/** * Initialise the CSS content handler */ nserror nscss_init(void) { lwc_error lerror; nserror error; lerror = lwc_intern_string("charset", SLEN("charset"), &css_charset); if (lerror != lwc_error_ok) { error = NSERROR_NOMEM; goto error; } error = content_factory_register_handler("text/css", &css_content_handler); if (error != NSERROR_OK) goto error; return NSERROR_OK; error: nscss_fini(); return error; }
/** * URL resolution callback for libcss * * \param pw Resolution context * \param base Base URI * \param rel Relative URL * \param abs Pointer to location to receive resolved URL * \return CSS_OK on success, * CSS_NOMEM on memory exhaustion, * CSS_INVALID if resolution failed. */ css_error nscss_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs) { lwc_error lerror; nserror error; nsurl *nsbase; nsurl *nsabs; /* Create nsurl from base */ /* TODO: avoid this */ error = nsurl_create(base, &nsbase); if (error != NSERROR_OK) { return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID; } /* Resolve URI */ error = nsurl_join(nsbase, lwc_string_data(rel), &nsabs); if (error != NSERROR_OK) { nsurl_unref(nsbase); return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID; } nsurl_unref(nsbase); /* Intern it */ lerror = lwc_intern_string(nsurl_access(nsabs), nsurl_length(nsabs), abs); if (lerror != lwc_error_ok) { *abs = NULL; nsurl_unref(nsabs); return lerror == lwc_error_oom ? CSS_NOMEM : CSS_INVALID; } nsurl_unref(nsabs); return CSS_OK; }
/** * Obtain pointer to interned propstring list * * \param sheet Returns pointer to propstring table * \return CSS_OK on success, * CSS_NOMEM on memory exhaustion * * The propstring list is generated with the first call to this function and * destroyed when it has no more users. Call css__propstrings_unref() when * finished with the propstring list. */ css_error css__propstrings_get(lwc_string ***strings) { if (css__propstrings.count > 0) { css__propstrings.count++; } else { int i; lwc_error lerror; /* Intern all known strings */ for (i = 0; i < LAST_KNOWN; i++) { lerror = lwc_intern_string(stringmap[i].data, stringmap[i].len, &css__propstrings.strings[i]); if (lerror != lwc_error_ok) return CSS_NOMEM; } css__propstrings.count++; } *strings = css__propstrings.strings; return CSS_OK; }
void css__parse_tree_data(line_ctx *ctx, const char *data, size_t len) { const char *p = data; const char *end = data + len; const char *name = NULL; const char *value = NULL; size_t namelen = 0; size_t valuelen = 0; uint32_t depth = 0; bool target = false; /* ' '{depth+1} [ <element> '*'? | <attr> ] * * <element> ::= [^=*[:space:]]+ * <attr> ::= [^=*[:space:]]+ '=' [^[:space:]]* */ while (p < end && isspace(*p)) { depth++; p++; } depth--; /* Get element/attribute name */ name = p; while (p < end && *p != '=' && *p != '*' && isspace(*p) == false) { namelen++; p++; } /* Skip whitespace */ while (p < end && isspace(*p)) p++; if (p < end && *p == '=') { /* Attribute value */ p++; value = p; while (p < end && isspace(*p) == false) { valuelen++; p++; } } else if (p < end && *p == '*') { /* Element is target node */ target = true; } if (value == NULL) { /* We have an element, so create it */ node *n = malloc(sizeof(node)); assert(n != NULL); memset(n, 0, sizeof(node)); lwc_intern_string(name, namelen, &n->name); /* Insert it into tree */ if (ctx->tree == NULL) { ctx->tree = n; } else { assert(depth > 0); assert(depth <= ctx->depth + 1); /* Find node to insert into */ while (depth <= ctx->depth) { ctx->depth--; ctx->current = ctx->current->parent; } /* Insert into current node */ if (ctx->current->children == NULL) { ctx->current->children = n; ctx->current->last_child = n; } else { ctx->current->last_child->next = n; n->prev = ctx->current->last_child; ctx->current->last_child = n; } n->parent = ctx->current; } ctx->current = n; ctx->depth = depth; /* Mark the target, if it's us */ if (target) ctx->target = n; } else { /* New attribute */ bool amatch = false; attribute *attr; node *n = ctx->current; attribute *temp = realloc(n->attrs, (n->n_attrs + 1) * sizeof(attribute)); assert(temp != NULL); n->attrs = temp; attr = &n->attrs[n->n_attrs]; lwc_intern_string(name, namelen, &attr->name); lwc_intern_string(value, valuelen, &attr->value); assert(lwc_string_caseless_isequal( n->attrs[n->n_attrs].name, ctx->attr_class, &amatch) == lwc_error_ok); if (amatch == true) { n->classes = realloc(NULL, sizeof(lwc_string **)); assert(n->classes != NULL); n->classes[0] = lwc_string_ref( n->attrs[n->n_attrs]. value); n->n_classes = 1; } n->n_attrs++; } }
/** * Create a string from a list of IDENT/S tokens * * \param c Parsing context * \param vector Vector containing tokens * \param ctx Vector iteration context * \param reserved Callback to determine if an identifier is reserved * \param result Pointer to location to receive resulting string * \return CSS_OK on success, appropriate error otherwise. * * Post condition: \a *ctx is updated with the next token to process * If the input is invalid, then \a *ctx remains unchanged. * * The resulting string's reference is passed to the caller */ css_error css__ident_list_to_string(css_language *c, const parserutils_vector *vector, int *ctx, bool (*reserved)(css_language *c, const css_token *ident), lwc_string **result) { int orig_ctx = *ctx; const css_token *token; css_error error = CSS_OK; parserutils_buffer *buffer; parserutils_error perror; lwc_string *interned; lwc_error lerror; perror = parserutils_buffer_create((parserutils_alloc) c->alloc, c->pw, &buffer); if (perror != PARSERUTILS_OK) return css_error_from_parserutils_error(perror); /* We know this token exists, and is an IDENT */ token = parserutils_vector_iterate(vector, ctx); /* Consume all subsequent IDENT or S tokens */ while (token != NULL && (token->type == CSS_TOKEN_IDENT || token->type == CSS_TOKEN_S)) { if (token->type == CSS_TOKEN_IDENT) { /* IDENT -- if reserved, reject style */ if (reserved != NULL && reserved(c, token)) { error = CSS_INVALID; goto cleanup; } perror = parserutils_buffer_append(buffer, (const uint8_t *) lwc_string_data(token->idata), lwc_string_length(token->idata)); } else { /* S */ perror = parserutils_buffer_append(buffer, (const uint8_t *) " ", 1); } if (perror != PARSERUTILS_OK) { error = css_error_from_parserutils_error(perror); goto cleanup; } token = parserutils_vector_iterate(vector, ctx); } /* Rewind context by one step if we consumed an unacceptable token */ if (token != NULL) *ctx = *ctx - 1; /* Strip trailing whitespace */ while (buffer->length > 0 && buffer->data[buffer->length - 1] == ' ') buffer->length--; /* Intern the buffer contents */ lerror = lwc_intern_string((char *) buffer->data, buffer->length, &interned); if (lerror != lwc_error_ok) { error = css_error_from_lwc_error(lerror); goto cleanup; } *result = interned; cleanup: parserutils_buffer_destroy(buffer); if (error != CSS_OK) *ctx = orig_ctx; return error; }
svgtiny_code svgtiny_parse_dom(const char *buffer, size_t size, const char *url, dom_document **output_dom) { dom_document *document; dom_exception exc; dom_xml_parser *parser; dom_xml_error err; dom_element *svg; dom_string *svg_name; lwc_string *svg_name_lwc; assert(buffer); assert(url); UNUSED(url); parser = dom_xml_parser_create(NULL, NULL, ignore_msg, NULL, &document); if (parser == NULL) return svgtiny_LIBDOM_ERROR; err = dom_xml_parser_parse_chunk(parser, (uint8_t *)buffer, size); if (err != DOM_XML_OK) { dom_node_unref(document); dom_xml_parser_destroy(parser); return svgtiny_LIBDOM_ERROR; } err = dom_xml_parser_completed(parser); if (err != DOM_XML_OK) { dom_node_unref(document); dom_xml_parser_destroy(parser); return svgtiny_LIBDOM_ERROR; } /* We're done parsing, drop the parser. * We now own the document entirely. */ dom_xml_parser_destroy(parser); /* find root <svg> element */ exc = dom_document_get_document_element(document, &svg); if (exc != DOM_NO_ERR) { dom_node_unref(document); return svgtiny_LIBDOM_ERROR; } exc = dom_node_get_node_name(svg, &svg_name); if (exc != DOM_NO_ERR) { dom_node_unref(svg); dom_node_unref(document); return svgtiny_LIBDOM_ERROR; } if (lwc_intern_string("svg", 3 /* SLEN("svg") */, &svg_name_lwc) != lwc_error_ok) { dom_string_unref(svg_name); dom_node_unref(svg); dom_node_unref(document); return svgtiny_LIBDOM_ERROR; } if (!dom_string_caseless_lwc_isequal(svg_name, svg_name_lwc)) { lwc_string_unref(svg_name_lwc); dom_string_unref(svg_name); dom_node_unref(svg); dom_node_unref(document); return svgtiny_NOT_SVG; } dom_node_unref(svg); lwc_string_unref(svg_name_lwc); dom_string_unref(svg_name); *output_dom = document; return svgtiny_OK; }
/* See content-type.h for documentation */ nserror http_parse_content_type(const char *header_value, http_content_type **result) { const char *pos = header_value; lwc_string *type; lwc_string *subtype = NULL; http_parameter *params = NULL; char *mime; size_t mime_len; lwc_string *imime; http_content_type *ct; nserror error; /* type "/" subtype *( ";" parameter ) */ http__skip_LWS(&pos); error = http__parse_token(&pos, &type); if (error != NSERROR_OK) return error; http__skip_LWS(&pos); if (*pos != '/') { lwc_string_unref(type); return NSERROR_NOT_FOUND; } pos++; http__skip_LWS(&pos); error = http__parse_token(&pos, &subtype); if (error != NSERROR_OK) { lwc_string_unref(type); return error; } http__skip_LWS(&pos); if (*pos == ';') { error = http__item_list_parse(&pos, http__parse_parameter, NULL, ¶ms); if (error != NSERROR_OK && error != NSERROR_NOT_FOUND) { lwc_string_unref(subtype); lwc_string_unref(type); return error; } } /* <type> + <subtype> + '/' */ mime_len = lwc_string_length(type) + lwc_string_length(subtype) + 1; mime = malloc(mime_len + 1); if (mime == NULL) { http_parameter_list_destroy(params); lwc_string_unref(subtype); lwc_string_unref(type); return NSERROR_NOMEM; } sprintf(mime, "%.*s/%.*s", (int) lwc_string_length(type), lwc_string_data(type), (int) lwc_string_length(subtype), lwc_string_data(subtype)); lwc_string_unref(subtype); lwc_string_unref(type); if (lwc_intern_string(mime, mime_len, &imime) != lwc_error_ok) { http_parameter_list_destroy(params); free(mime); return NSERROR_NOMEM; } free(mime); ct = malloc(sizeof(*ct)); if (ct == NULL) { lwc_string_unref(imime); http_parameter_list_destroy(params); return NSERROR_NOMEM; } ct->media_type = imime; ct->parameters = params; *result = ct; return NSERROR_OK; }
/** * Process fetch headers for a download context. * Extracts MIME type, total length, and creates gui_download_window * * \param ctx Context to process * \return NSERROR_OK on success, appropriate error otherwise */ static nserror download_context_process_headers(download_context *ctx) { const char *http_header; http_content_type *content_type; unsigned long length; nserror error; /* Retrieve and parse Content-Type */ http_header = llcache_handle_get_header(ctx->llcache, "Content-Type"); if (http_header == NULL) http_header = "text/plain"; error = http_parse_content_type(http_header, &content_type); if (error != NSERROR_OK) return error; /* Retrieve and parse Content-Length */ http_header = llcache_handle_get_header(ctx->llcache, "Content-Length"); if (http_header == NULL) length = 0; else length = strtoul(http_header, NULL, 10); /* Retrieve and parse Content-Disposition */ http_header = llcache_handle_get_header(ctx->llcache, "Content-Disposition"); if (http_header != NULL) { lwc_string *filename; lwc_string *filename_value; http_content_disposition *disposition; if (lwc_intern_string("filename", SLEN("filename"), &filename) != lwc_error_ok) { http_content_type_destroy(content_type); return NSERROR_NOMEM; } error = http_parse_content_disposition(http_header, &disposition); if (error != NSERROR_OK) { lwc_string_unref(filename); http_content_type_destroy(content_type); return error; } error = http_parameter_list_find_item(disposition->parameters, filename, &filename_value); if (error == NSERROR_OK) { ctx->filename = download_parse_filename( lwc_string_data(filename_value)); lwc_string_unref(filename_value); } http_content_disposition_destroy(disposition); lwc_string_unref(filename); } ctx->mime_type = lwc_string_ref(content_type->media_type); ctx->total_length = length; if (ctx->filename == NULL) { ctx->filename = download_default_filename( nsurl_access( llcache_handle_get_url(ctx->llcache))); } http_content_type_destroy(content_type); if (ctx->filename == NULL) { lwc_string_unref(ctx->mime_type); ctx->mime_type = NULL; return NSERROR_NOMEM; } /* Create the frontend window */ ctx->window = gui_download_window_create(ctx, ctx->parent); if (ctx->window == NULL) { free(ctx->filename); ctx->filename = NULL; lwc_string_unref(ctx->mime_type); ctx->mime_type = NULL; return NSERROR_NOMEM; } return NSERROR_OK; }
END_TEST START_TEST (test_lwc_intern_string_aborts2) { lwc_intern_string("A", 1, NULL); }
/** * Initialise the treeview entry feilds * * \return true on success, false on memory exhaustion */ static nserror cookie_manager_init_entry_fields(void) { int i; const char *label; for (i = 0; i < COOKIE_M_N_FIELDS; i++) cm_ctx.fields[i].field = NULL; cm_ctx.fields[COOKIE_M_NAME].flags = TREE_FLAG_DEFAULT; label = "TreeviewLabelName"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_NAME].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_CONTENT].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelContent"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_CONTENT].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_DOMAIN].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelDomain"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_DOMAIN].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_PATH].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelPath"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_PATH].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_EXPIRES].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelExpires"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_EXPIRES].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_LAST_USED].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelLastUsed"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_LAST_USED].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_RESTRICTIONS].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelRestrictions"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_RESTRICTIONS].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_VERSION].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelVersion"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_VERSION].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_PERSISTENT].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelPersistent"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_PERSISTENT].field) != lwc_error_ok) { goto error; } cm_ctx.fields[COOKIE_M_DOMAIN_FOLDER].flags = TREE_FLAG_DEFAULT; label = "TreeviewLabelDomainFolder"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &cm_ctx.fields[COOKIE_M_DOMAIN_FOLDER].field) != lwc_error_ok) { return false; } return NSERROR_OK; error: for (i = 0; i < COOKIE_M_N_FIELDS; i++) if (cm_ctx.fields[i].field != NULL) lwc_string_unref(cm_ctx.fields[i].field); return NSERROR_UNKNOWN; }
/** * Initialise the treeview entry feilds * * \return NSERROR_OK on success, or appropriate error otherwise */ static nserror global_history_initialise_entry_fields(void) { int i; const char *label; for (i = 0; i < N_FIELDS; i++) gh_ctx.fields[i].field = NULL; gh_ctx.fields[GH_TITLE].flags = TREE_FLAG_DEFAULT; label = "TreeviewLabelTitle"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &gh_ctx.fields[GH_TITLE].field) != lwc_error_ok) { goto error; } gh_ctx.fields[GH_URL].flags = TREE_FLAG_COPY_TEXT; label = "TreeviewLabelURL"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &gh_ctx.fields[GH_URL].field) != lwc_error_ok) { goto error; } gh_ctx.fields[GH_LAST_VISIT].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelLastVisit"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &gh_ctx.fields[GH_LAST_VISIT].field) != lwc_error_ok) { goto error; } gh_ctx.fields[GH_VISITS].flags = TREE_FLAG_SHOW_NAME; label = "TreeviewLabelVisits"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &gh_ctx.fields[GH_VISITS].field) != lwc_error_ok) { goto error; } gh_ctx.fields[GH_PERIOD].flags = TREE_FLAG_DEFAULT; label = "TreeviewLabelPeriod"; label = messages_get(label); if (lwc_intern_string(label, strlen(label), &gh_ctx.fields[GH_PERIOD].field) != lwc_error_ok) { return false; } return NSERROR_OK; error: for (i = 0; i < N_FIELDS; i++) if (gh_ctx.fields[i].field != NULL) lwc_string_unref(gh_ctx.fields[i].field); return NSERROR_UNKNOWN; }