//FIXME on sinks should replace old connection! Con *filter_connect_real(Filter *source, int out, Filter *sink, int in) { Con *con = malloc(sizeof(Con)); con->source = eina_array_data_get(source->out, out); con->sink = eina_array_data_get(sink->in, in); if (!source->node->con_trees_out) source->node->con_trees_out = eina_array_new(1); if (!sink->node->con_trees_in) sink->node->con_trees_in = eina_array_new(1); if (ea_count(source->node->con_trees_out)) { printf("WARNING: have con_trees_out\n"); while (ea_count(source->node->con_trees_out)) ea_pop(source->node->con_trees_out); } if (ea_count(sink->node->con_trees_in)) { printf("WARNING: have con_trees_in\n"); while (ea_count(sink->node->con_trees_in)) ea_pop(sink->node->con_trees_in); } eina_array_push(source->node->con_trees_out, con); eina_array_push(sink->node->con_trees_in, con); filter_hash_invalidate(source); return con; }
END_TEST START_TEST(eina_binshare_collision) { Eina_Array *ea; char buffer[50]; int i; srand(time(NULL)); eina_init(); ea = eina_array_new(256); fail_if(!ea); for (i = 0; i < 10000; ++i) { eina_convert_itoa(rand(), buffer); eina_array_push(ea, (void *)eina_binshare_add_length(buffer, strlen(buffer))); if (rand() > RAND_MAX / 2) { const char *r = eina_binshare_add_length(buffer, strlen(buffer)); fail_if(r == NULL); } } for (i = 0; i < 10000; ++i) { const char *r; eina_convert_itoa(60000 - i, buffer); eina_array_push(ea, (void *)eina_binshare_add_length(buffer, strlen(buffer))); r = eina_binshare_add_length(buffer, strlen(buffer)); fail_if(r == NULL); r = eina_binshare_add_length(buffer, strlen(buffer)); fail_if(r == NULL); } for (i = 0; i < 200; ++i) eina_binshare_del(eina_array_data_get(ea, i)); for (i = 0; i < 1000; ++i) eina_binshare_del(eina_array_pop(ea)); eina_shutdown(); eina_array_free(ea); }
Eina_Bool evas_module_register(const Evas_Module_Api *module, Evas_Module_Type type) { Evas_Module *em; if ((unsigned int)type > 3) return EINA_FALSE; if (!module) return EINA_FALSE; if (module->version != EVAS_MODULE_API_VERSION) return EINA_FALSE; em = eina_hash_find(evas_modules[type], module->name); if (em) return EINA_FALSE; em = calloc(1, sizeof (Evas_Module)); if (!em) return EINA_FALSE; em->definition = module; if (type == EVAS_MODULE_TYPE_ENGINE) { eina_array_push(evas_engines, em); em->id_engine = eina_array_count(evas_engines); } eina_hash_direct_add(evas_modules[type], module->name, em); return EINA_TRUE; }
/* * This function creates a color table for an rtf file. It returns 1 upon * success and 0 in case of failure. */ int ertf_color_table(FILE *fp) { int c; DBG("Inside color table handler."); // create an eina array color_table = eina_array_new(7); if (!color_table) { // In case of success, the eina array module shall be shut down by ertf // clean up functions when the app is closed. return 0; } // ready to parse the color table now while ((c=fgetc(fp)) != EOF) { switch (c) { Ertf_Color *node; case ';':// indicates default color node = (Ertf_Color *)malloc(sizeof(Ertf_Color)); if (!node) { ERR("short of memory while allocating color node"); return 0; } node->r = _ertf_default_color_r; node->g = _ertf_default_color_g; node->b = _ertf_default_color_b; eina_array_push(color_table, node); break; case '\\': ungetc(c, fp); if (_ertf_color_add(fp)) continue; else INFO("Ill-formed rtf"); break; case '}':// end of color table // generate markup strings for all colors _ertf_color_generate_markup(); return 1; default: if (c == '\n' || c == '\r') _line++; DBG("skipping control character `%c'", c); } } ERR("End of file reached in color table"); return 0; }
//FIXME on sinks should replace old connection! Con *filter_connect(Filter *source, int out, Filter *sink, int in) { Con *con = malloc(sizeof(Con)); //no composition yet assert(in == 0); assert(out == 0); assert(source->in); assert(sink->out); lime_config_reset(sink); lime_config_reset(source); con->source = eina_array_data_get(source->out, out); con->sink = eina_array_data_get(sink->in, in); if (!source->node_orig->con_trees_out) source->node_orig->con_trees_out = eina_array_new(1); if (!sink->node_orig->con_trees_in) sink->node_orig->con_trees_in = eina_array_new(1); if (!ea_count(source->node_orig->con_trees_out)) eina_array_push(source->node_orig->con_trees_out, con); else { while (ea_count(source->node_orig->con_trees_out)) con_del(ea_pop(source->node_orig->con_trees_out)); eina_array_push(source->node_orig->con_trees_out, con); } if (!ea_count(sink->node_orig->con_trees_in)) eina_array_push(sink->node_orig->con_trees_in, con); else { while (ea_count(sink->node_orig->con_trees_in)) con_del(ea_pop(sink->node_orig->con_trees_in)); eina_array_push(sink->node_orig->con_trees_in, con); } filter_hash_invalidate(source); return con; }
static Eina_Bool cache_fallback_scan_dir(Eina_Hash *icons, Eina_Hash *dirs, const char *dir, Eina_Bool *changed) { Eina_Iterator *it; Eina_File_Direct_Info *entry; if (!cache_directory_find(dirs, dir)) return 1; it = eina_file_stat_ls(dir); if (!it) return 1; EINA_ITERATOR_FOREACH(it, entry) { Efreet_Cache_Fallback_Icon *icon; char *name; char *ext; unsigned int i; if (entry->type == EINA_FILE_DIR) continue; ext = strrchr(entry->path + entry->name_start, '.'); if (!ext || !_cache_extention_lookup(ext)) continue; /* icon with known extension */ name = entry->path + entry->name_start; *ext = '\0'; icon = eina_hash_find(icons, name); if (!icon) { icon = NEW(Efreet_Cache_Fallback_Icon, 1); icon->theme = NULL; eina_hash_add(icons, name, icon); } *ext = '.'; for (i = 0; i < icon->icons_count; ++i) if (!strcmp(icon->icons[i], entry->path)) break; if (i != icon->icons_count) continue ; /* we don't really track path deat here, so we will leak... */ icon->icons = realloc(icon->icons, sizeof (char *) * (icon->icons_count + 1)); icon->icons[icon->icons_count] = eina_stringshare_add(entry->path); eina_array_push(strs, icon->icons[icon->icons_count++]); *changed = EINA_TRUE; }
static Eina_Bool _etui_epub_opf_spine_item_attr_parse_cb(void *data, const char *key, const char *value) { Etui_Provider_Data *pd; pd = (Etui_Provider_Data *)data; if (!strcmp("idref", key)) eina_array_push(pd->opf.spine, strdup(value)); return EINA_TRUE; }
static Eina_Bool _dir_list_get_cb(Eina_Module *m, void *data) { Dir_List_Get_Cb_Data *cb_data = data; Eina_Bool ret = EINA_TRUE; if (cb_data->cb) ret = cb_data->cb(m, cb_data->data); if (ret) eina_array_push(cb_data->array, m); return ret; }
static void eina_bench_lookup_evas(int request) { Evas_Hash *hash = NULL; Eina_Array *array = NULL; int *tmp_val; Eina_Array_Iterator it; unsigned int i; unsigned int j; array = eina_array_new(10000); for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; tmp_val = malloc(sizeof (int)); if (!tmp_val) continue; eina_convert_itoa(i, tmp_key); *tmp_val = i; hash = evas_hash_add(hash, tmp_key, tmp_val); eina_array_push(array, tmp_val); } srand(time(NULL)); for (j = 0; j < 200; ++j) for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; eina_convert_itoa(rand() % request, tmp_key); tmp_val = evas_hash_find(hash, tmp_key); } evas_hash_free(hash); EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it) free(tmp_val); eina_array_free(array); }
Eina_Array * wkb_ibus_properties_from_message_iter(Eldbus_Message_Iter *iter) { struct wkb_ibus_serializable ignore = { 0 }; struct wkb_ibus_property *property = NULL; Eina_Array *properties = NULL; Eldbus_Message_Iter *iter_props, *props, *prop; DBG("Message iter signature '%s'", eldbus_message_iter_signature_get(iter)); eldbus_message_iter_arguments_get(iter, "(sa{sv}av)", &iter_props); if (!eldbus_message_iter_arguments_get(iter_props, "sa{sv}av", &ignore.text, &ignore.dict, &props)) { ERR("Error deserializing IBusPropList"); goto end; } if (!props) { INF("PropList has no property"); goto end; } while (eldbus_message_iter_get_and_next(props, 'v', &prop)) { if (!(property = wkb_ibus_property_from_message_iter(prop))) { wkb_ibus_properties_free(properties); properties = NULL; goto end; } if (!properties) properties = eina_array_new(10); DBG("Appending new property %p", property); eina_array_push(properties, property); } end: return properties; }
END_TEST START_TEST(eina_rbtree_remove) { Eina_Rbtree_Int *root = NULL; Eina_Rbtree_Int *item; Eina_Array *ea; Eina_Array_Iterator it; unsigned int i; eina_init(); ea = eina_array_new(11); fail_if(!ea); srand(time(NULL)); for (i = 0; i < 500; ++i) { item = _eina_rbtree_int_new(rand()); eina_array_push(ea, item); root = (Eina_Rbtree_Int *)eina_rbtree_inline_insert( &root->node, &item->node, EINA_RBTREE_CMP_NODE_CB( eina_rbtree_int_cmp), NULL); } _eina_rbtree_black_height(&root->node, EINA_RBTREE_CMP_NODE_CB(eina_rbtree_int_cmp)); EINA_ARRAY_ITER_NEXT(ea, i, item, it) { root = (Eina_Rbtree_Int *)eina_rbtree_inline_remove( &root->node, &item->node, EINA_RBTREE_CMP_NODE_CB( eina_rbtree_int_cmp), NULL); _eina_rbtree_black_height(&root->node, EINA_RBTREE_CMP_NODE_CB(eina_rbtree_int_cmp)); }
static Eina_Array * _wkb_ibus_attr_list_from_message_iter(Eldbus_Message_Iter *iter) { struct wkb_ibus_serializable ignore = { 0 }; Eldbus_Message_Iter *iter_array, *iter_attr; struct wkb_ibus_attr *attr = NULL; Eina_Array *attr_list = NULL; DBG("Message iter signature '%s'", eldbus_message_iter_signature_get(iter)); eldbus_message_iter_arguments_get(iter, "(sa{sv}av)", &iter_attr); if (!eldbus_message_iter_arguments_get(iter_attr, "sa{sv}av", &ignore.text, &ignore.dict, &iter_array)) { ERR("Error deserializing IBusAttrList"); goto end; } if (!iter_array) { INF("AttrList has no attribute"); goto end; } while (eldbus_message_iter_get_and_next(iter_array, 'v', &iter_attr)) { if (!(attr = wkb_ibus_attr_from_message_iter(iter_attr))) { _free_eina_array(attr_list, (_free_func) free); attr_list = NULL; goto end; } if (!attr_list) attr_list = eina_array_new(10); DBG("Appending new attribute: %p", attr); eina_array_push(attr_list, attr); } end: return attr_list; }
static void _dir_arch_list_cb(const char *name, const char *path, void *data) { Dir_List_Get_Cb_Data *cb_data = data; Eina_Module *m; char *file = NULL; size_t length; length = strlen(path) + 1 + strlen(name) + 1 + strlen((char *)(cb_data->data)) + 1 + sizeof("module") + sizeof(SHARED_LIB_SUFFIX) + 1; file = alloca(length); snprintf(file, length, "%s" SEP_S "%s" SEP_S "%s" SEP_S "module" SHARED_LIB_SUFFIX, path, name, (char *)(cb_data->data)); m = eina_module_new(file); if (!m) return; eina_array_push(cb_data->array, m); }
//Positionen und Größer immer bezogen auf scale //FIXME check if area is already cached! Render_State *render_state_new(Rect *area, Filter *f) { Render_State *state = calloc(sizeof(Render_State), 1); Tile *tile; if (area) { tile = tile_new(area, tile_hash_calc(f, area), f, NULL, 1); } else tile = NULL; Render_Node *node = render_node_new(f, tile, state, 1); node->need = 1000; state->currstate = eina_array_new(64); state->ready = eina_array_new(64); eina_array_push(state->currstate, node); return state; }
/* * Adds a header to a response * * Adds a header to the response object given pointers to the key * and value starting points and respective string lengths. * * @param m request to add the header into * @param key starting point for the key * @param key_len key length * @param value starting point for the value * @param value_len value length * * @note This function does not check duplicate headers. If added twice, * header will be duplicated. * * @return On success returns EINA_TRUE, otherwise EINA_FALSE. */ Eina_Bool eupnp_http_response_header_add(Eupnp_HTTP_Response *r, const char *key, int key_len, const char *value, int value_len) { Eupnp_HTTP_Header *h; h = eupnp_http_header_new(key, key_len, value, value_len); if (!h) { eina_error_set(EINA_ERROR_OUT_OF_MEMORY); ERROR("header alloc error.\n"); return EINA_FALSE; } if (!eina_array_push(r->headers, h)) { WARN("incomplete headers\n"); eupnp_http_header_free(h); return EINA_FALSE; } return EINA_TRUE; }
struct wkb_ibus_lookup_table * wkb_ibus_lookup_table_from_message_iter(Eldbus_Message_Iter *iter) { struct wkb_ibus_serializable ignore = { 0 }; struct wkb_ibus_lookup_table *table = calloc(1, sizeof(*table)); struct wkb_ibus_text *text = NULL; Eldbus_Message_Iter *iter_table, *candidates, *labels, *t; EINA_SAFETY_ON_NULL_RETURN_VAL(table, NULL); DBG("Message iter signature '%s'", eldbus_message_iter_signature_get(iter)); eldbus_message_iter_arguments_get(iter, "(sa{sv}uubbiavav)", &iter_table); if (!eldbus_message_iter_arguments_get(iter_table, "sa{sv}uubbiavav", &ignore.text, &ignore.dict, &table->page_size, &table->cursor_pos, &table->cursor_visible, &table->round, &table->orientation, &candidates, &labels)) { ERR("Error deserializing IBusLookupTable"); free(table); table = NULL; goto end; } DBG("Lookup table:"); DBG("\tPage size.......: '%d'", table->page_size); DBG("\tCursor position.: '%d'", table->cursor_pos); DBG("\tCursor visible..: '%d'", table->cursor_visible); DBG("\tRound...........: '%d'", table->round); DBG("\tOrientation.....: '%d'", table->orientation); DBG("\tCandidates......: '%p'", candidates); DBG("\tLabels..........: '%p'", labels); if (!candidates) { INF("Lookup table has no candidates"); goto labels; } while (eldbus_message_iter_get_and_next(candidates, 'v', &t)) { if (!(text = wkb_ibus_text_from_message_iter(t))) { wkb_ibus_lookup_table_free(table); table = NULL; goto end; } if (!table->candidates) table->candidates = eina_array_new(10); DBG("Appending new candidate %s", text->text); eina_array_push(table->candidates, text); } labels: if (!labels) { INF("Lookup table has no labels"); goto end; } while (eldbus_message_iter_get_and_next(labels, 'v', &t)) { if (!(text = wkb_ibus_text_from_message_iter(t))) { wkb_ibus_lookup_table_free(table); table = NULL; goto end; } if (!table->labels) table->labels = eina_array_new(10); DBG("Appending new label %s", text->text); eina_array_push(table->labels, text); } end: return table; }
char * _nedje_text_escape(const char *text) { Eina_Strbuf *txt; char *ret; const char *text_end; size_t text_len; Eina_Array *arr; const char *cur_tag = NULL; if (!text) return NULL; txt = eina_strbuf_new(); text_len = strlen(text); arr = eina_array_new(3); text_end = text + text_len; while (text < text_end) { int advance; if ((text[0] == '<') && text[1]) { const char *tag, *popped; Eina_Bool closing = EINA_FALSE; if (text[1] == '/') //closing tag { closing = EINA_TRUE; tag = _get_tag(text + 2); } else tag = _get_tag(text + 1); if (closing) { if (cur_tag && (tag != cur_tag)) { /* tag mismatch: autoclose all failure tags * not technically required by the spec, * but it makes me feel better about myself */ do { popped = eina_array_pop(arr); if (eina_array_count(arr)) cur_tag = eina_array_data_get(arr, eina_array_count(arr) - 1); else cur_tag = NULL; eina_strbuf_append_printf(txt, "</%c>", popped[1]); } while (cur_tag && (popped != tag)); advance = 4; } else if (cur_tag) { /* tag match: just pop */ popped = eina_array_pop(arr); if (eina_array_count(arr)) cur_tag = eina_array_data_get(arr, eina_array_count(arr) - 1); else cur_tag = NULL; eina_strbuf_append_printf(txt, "</%c>", popped[1]); advance = 4; } else { /* no current tag: escape */ advance = _text_escape(txt, text); } } else { if (tag) { cur_tag = tag; eina_array_push(arr, tag); eina_strbuf_append_printf(txt, "<%c>", tag[1]); advance = 3; } else advance = _text_escape(txt, text); } } else if (text[0] == '&') { const char *s; s = strchr(text, ';'); if (s) s = evas_textblock_escape_string_range_get(text, s + 1); if (s) { eina_strbuf_append_char(txt, text[0]); advance = 1; } else advance = _text_escape(txt, text); } else advance = _text_escape(txt, text); text += advance; } eina_array_free(arr); ret = eina_strbuf_string_steal(txt); eina_strbuf_free(txt); return ret; }
static int _ertf_color_add(FILE *fp) { char color[7]; int idx; int set = 0; Ertf_Color *node; int c; node = (Ertf_Color *)malloc(sizeof(Ertf_Color)); if (!node) { ERR("short of memory while allocating color node"); return 0; } DBG("Inside color entry parser"); while ((c = fgetc(fp)) != EOF) { switch (c) { case '\\': if (ertf_tag_get(fp, color)) { ERR("EOF encountered while getting control tag"); goto err; } fscanf(fp, "%d", &idx); // todo: do error checking for range of rgb value if (feof(fp)) goto err; if (strcmp(color, "green") == 0) { if (!(set & GREEN)) node->g = idx; else WARN("multiple values for same color"); } else if (strcmp(color, "red") == 0) node->r = idx; // todo: add set/unset check as above else if (strcmp(color, "blue") == 0) node->b = idx; // todo: add set/unset check as above else // continue as the tag is not recognised and should be therefore skipped DBG("skipped unrecognised control tag `%s'", color); break; case ';':// todo: error checking on success of the push operation eina_array_push(color_table, node); return 1; default: if (c == '\n' || c == '\r') _line++; DBG("skipped control character %c.\n", c); } } err: free(node); return 0; }
/** * @brief Init the module system */ int enna_module_init(void) { Eina_Array_Iterator iterator; unsigned int i; #ifdef USE_STATIC_MODULES Enna_Module_Api *api; /* Populate the array of available plugins statically */ _plugins_array = eina_array_new(20); #ifdef BUILD_ACTIVITY_BOOKSTORE eina_array_push(_plugins_array, &enna_mod_activity_bookstore_api); #endif #ifdef BUILD_ACTIVITY_CONFIGURATION eina_array_push(_plugins_array, &enna_mod_activity_configuration_api); #endif #ifdef BUILD_ACTIVITY_GAMES eina_array_push(_plugins_array, &enna_mod_activity_games_api); #endif #ifdef BUILD_ACTIVITY_MUSIC eina_array_push(_plugins_array, &enna_mod_activity_music_api); #endif #ifdef BUILD_ACTIVITY_PHOTO eina_array_push(_plugins_array, &enna_mod_activity_photo_api); #endif #ifdef BUILD_ACTIVITY_TV eina_array_push(_plugins_array, &enna_mod_activity_tv_api); #endif #ifdef BUILD_ACTIVITY_VIDEO eina_array_push(_plugins_array, &enna_mod_activity_video_api); #endif #ifdef BUILD_ACTIVITY_WEATHER eina_array_push(_plugins_array, &enna_mod_activity_weather_api); #endif #ifdef BUILD_BROWSER_CDDA eina_array_push(_plugins_array, &enna_mod_browser_cdda_api); #endif #ifdef BUILD_BROWSER_DVD eina_array_push(_plugins_array, &enna_mod_browser_dvd_api); #endif #ifdef BUILD_BROWSER_IPOD eina_array_push(_plugins_array, &enna_mod_browser_ipod_api); #endif #ifdef BUILD_BROWSER_SPOTIFY eina_array_push(_plugins_array, &enna_mod_browser_spotify_api); #endif #ifdef BUILD_BROWSER_LOCALFILES eina_array_push(_plugins_array, &enna_mod_browser_localfiles_api); #endif #ifdef BUILD_BROWSER_NETSTREAMS eina_array_push(_plugins_array, &enna_mod_browser_netstreams_api); #endif #ifdef BUILD_BROWSER_PODCASTS eina_array_push(_plugins_array, &enna_mod_browser_podcasts_api); #endif #ifdef BUILD_BROWSER_SHOUTCAST eina_array_push(_plugins_array, &enna_mod_browser_shoutcast_api); #endif #ifdef BUILD_BROWSER_UPNP eina_array_push(_plugins_array, &enna_mod_browser_upnp_api); #endif #ifdef BUILD_BROWSER_VALHALLA eina_array_push(_plugins_array, &enna_mod_browser_valhalla_api); #endif #ifdef BUILD_GADGET_DATE eina_array_push(_plugins_array, &enna_mod_gadget_date_api); #endif #ifdef BUILD_GADGET_DUMMY eina_array_push(_plugins_array, &enna_mod_gadget_dummy_api); #endif #ifdef BUILD_GADGET_WEATHER eina_array_push(_plugins_array, &enna_mod_gadget_weather_api); #endif #ifdef BUILD_INPUT_KBD eina_array_push(_plugins_array, &enna_mod_input_kbd_api); #endif #ifdef BUILD_INPUT_LIRC eina_array_push(_plugins_array, &enna_mod_input_lirc_api); #endif #ifdef BUILD_INPUT_WIIMOTE eina_array_push(_plugins_array, &enna_mod_input_wiimote_api); #endif #ifdef BUILD_VOLUME_HAL eina_array_push(_plugins_array, &enna_mod_volume_hal_api); #endif #ifdef BUILD_VOLUME_MTAB eina_array_push(_plugins_array, &enna_mod_volume_mtab_api); #endif #ifdef BUILD_VOLUME_UDEV eina_array_push(_plugins_array, &enna_mod_volume_udev_api); #endif /* Log the array */ enna_log(ENNA_MSG_INFO, NULL, "Available Plugins (static):"); EINA_ARRAY_ITER_NEXT(_plugins_array, i, api, iterator) enna_log(ENNA_MSG_INFO, NULL, "\t * %s", api->name); #else Eina_Module *module; /* Populate the array of available plugins dinamically */ _plugins_array = eina_array_new(20); _plugins_array = eina_module_list_get(_plugins_array, PACKAGE_LIB_DIR"/enna/modules/", 0, NULL, NULL); enna_log(ENNA_MSG_INFO, NULL, "Plugin Directory: %s", PACKAGE_LIB_DIR"/enna/modules/"); /* Log the array */ enna_log(ENNA_MSG_INFO, NULL, "Available Plugins (dynamic):"); EINA_ARRAY_ITER_NEXT(_plugins_array, i, module, iterator) enna_log(ENNA_MSG_INFO, NULL, "\t * %s", eina_module_file_get(module)); #endif /* USE_STATIC_MODULES */ #if ENABLE_CONFIG_PANEL _config_panel = enna_config_panel_register(_("Modules"), "icon/module", _config_panel_show, _config_panel_hide, NULL); #endif return 0; }
static Eina_Bool _etui_epub_ncx_parse_cb(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset EINA_UNUSED, unsigned length) { Etui_Provider_Data *pd; pd = (Etui_Provider_Data *)data; if ((type == EINA_SIMPLE_XML_OPEN) || (type == EINA_SIMPLE_XML_OPEN_EMPTY)) { if (strncmp("ncx", content, strlen("ncx")) == 0) { if (pd->ncx.has_ncx) { return EINA_FALSE; } pd->ncx.has_ncx = 1; } else if (strncmp("meta", content, strlen("meta")) == 0) { const char *tags; tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _etui_epub_ncx_meta_attr_parse_cb, pd); } else if (strncmp("docTitle", content, strlen("docTitle")) == 0) { if (!pd->ncx.has_ncx || pd->ncx.has_title) { return EINA_FALSE; } pd->ncx.has_title = 1; } else if (strncmp("docAuthor", content, strlen("docAuthor")) == 0) { if (!pd->ncx.has_ncx || pd->ncx.has_author) { return EINA_FALSE; } pd->ncx.has_author = 1; } else if (strncmp("text", content, strlen("text")) == 0) { if (pd->ncx.has_title) pd->ncx.has_title_text = 1; if (pd->ncx.has_author) pd->ncx.has_author_text = 1; if (pd->ncx.has_navpoint) pd->ncx.has_navpoint_text = 1; } else if (strncmp("navMap", content, strlen("navMap")) == 0) { int i; for (i = 0; i < 2; i++) { if (!strcmp(pd->ncx.meta_items[i].name, "dtb:uid")) pd->ncx.uid = pd->ncx.meta_items[i].content; if (!strcmp(pd->ncx.meta_items[i].name, "dtb:depth")) { pd->ncx.depth = atoi(pd->ncx.meta_items[i].content); free(pd->ncx.meta_items[i].content); pd->ncx.meta_item_to_free = 1 - i; } free(pd->ncx.meta_items[i].name); } /* FIXME: use an eina_array instead */ if (pd->ncx.depth == 0) pd->ncx.depth = 10; pd->ncx.stack = (Etui_Epub_Ncx_Toc_Item **)calloc(pd->ncx.depth, sizeof(Etui_Epub_Ncx_Toc_Item *)); } else if (strncmp("navPoint", content, strlen("navPoint")) == 0) { pd->ncx.current_depth++; pd->ncx.stack[pd->ncx.current_depth] = (Etui_Epub_Ncx_Toc_Item *)calloc(1, sizeof(Etui_Epub_Ncx_Toc_Item)); if (pd->ncx.current_depth > 0) { if (pd->ncx.stack[pd->ncx.current_depth - 1]->child == NULL) pd->ncx.stack[pd->ncx.current_depth - 1]->child = eina_array_new(4); } pd->ncx.has_navpoint = 1; } else if (strncmp("content", content, strlen("content")) == 0) { const char *tags; tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _etui_epub_ncx_content_attr_parse_cb, pd); } } else if (type == EINA_SIMPLE_XML_DATA) { if (pd->ncx.has_title_text) { pd->ncx.title = (char *)malloc(length + 1); if (pd->ncx.title) { memcpy(pd->ncx.title, content, length); pd->ncx.title[length] = '\0'; } } else if (pd->ncx.has_author_text) { pd->ncx.author = (char *)malloc(length + 1); if (pd->ncx.author) { memcpy(pd->ncx.author, content, length); pd->ncx.author[length] = '\0'; } } else if (pd->ncx.has_navpoint_text) { if (pd->ncx.stack[pd->ncx.current_depth]) { char *label; label = (char *)malloc(length + 1); if (label) { memcpy(label, content, length); label[length] = '\0'; pd->ncx.stack[pd->ncx.current_depth]->label = label; } } } } else if (type == EINA_SIMPLE_XML_CLOSE) { if (strncmp("docTitle", content, strlen("docTitle")) == 0) { pd->ncx.has_title = 0; } else if (strncmp("docAuthor", content, strlen("docAuthor")) == 0) { pd->ncx.has_author = 0; } else if (strncmp("navPoint", content, strlen("navPoint")) == 0) { pd->ncx.has_navpoint = 0; if (pd->ncx.stack[pd->ncx.current_depth]) { if (pd->ncx.current_depth == 0) eina_array_push(&pd->doc.toc, pd->ncx.stack[pd->ncx.current_depth]); else eina_array_push(pd->ncx.stack[pd->ncx.current_depth - 1]->child, pd->ncx.stack[pd->ncx.current_depth]); } pd->ncx.current_depth--; } else if (strncmp("navMap", content, strlen("navMap")) == 0) { free(pd->ncx.stack); pd->ncx.stack = NULL; } else if (strncmp("text", content, strlen("text")) == 0) { if (pd->ncx.has_title) pd->ncx.has_title_text = 0; if (pd->ncx.has_author) pd->ncx.has_author_text = 0; if (pd->ncx.has_navpoint) pd->ncx.has_navpoint_text = 0; } } return EINA_TRUE; }
Filter *filter_down_new(void) { Filter *filter = filter_new(&filter_core_down); Meta *in, *out, *channel, *bitdepth, *setting, *bound; Meta *ch_out[3]; _Data *data = calloc(sizeof(_Data), 1); filter->fixme_outcount = 3; ea_push(filter->data, data); filter->mode_buffer = filter_mode_buffer_new(); filter->mode_buffer->worker = &_worker_linear; filter->mode_buffer->area_calc = &_area_calc; filter->setting_changed = &_setting_changed; bitdepth = meta_new_data(MT_BITDEPTH, filter, malloc(sizeof(int))); *(int*)(bitdepth->data) = BD_U8; bitdepth->replace = bitdepth; out = meta_new(MT_BUNDLE, filter); eina_array_push(filter->out, out); channel = meta_new_channel(filter, 1); data->color[0] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int))); *(int*)(data->color[0]->data) = CS_LAB_L; meta_attach(channel, data->color[0]); meta_attach(channel, bitdepth); meta_attach(out, channel); ch_out[0] = channel; channel = meta_new_channel(filter, 2); data->color[1] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int))); *(int*)(data->color[1]->data) = CS_LAB_A; meta_attach(channel, data->color[1]); meta_attach(channel, bitdepth); meta_attach(out, channel); ch_out[1] = channel; channel = meta_new_channel(filter, 3); data->color[2] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int))); *(int*)(data->color[2]->data) = CS_LAB_B; meta_attach(channel, data->color[2]); meta_attach(channel, bitdepth); meta_attach(out, channel); ch_out[2] = channel; in = meta_new(MT_BUNDLE, filter); in->replace = out; eina_array_push(filter->in, in); channel = meta_new_channel(filter, 1); data->color[0]->replace = data->color[0]; channel->replace = ch_out[0]; meta_attach(channel, data->color[0]); meta_attach(channel, bitdepth); meta_attach(in, channel); channel = meta_new_channel(filter, 2); data->color[1]->replace = data->color[1]; channel->replace = ch_out[1]; meta_attach(channel, data->color[1]); meta_attach(channel, bitdepth); meta_attach(in, channel); channel = meta_new_channel(filter, 3); data->color[2]->replace = data->color[2]; channel->replace = ch_out[2]; meta_attach(channel, data->color[2]); meta_attach(channel, bitdepth); meta_attach(in, channel); setting = meta_new_data(MT_INT, filter, &data->colorspace); meta_name_set(setting, "colorspace"); eina_array_push(filter->settings, setting); bound = meta_new_data(MT_INT, filter, malloc(sizeof(int))); *(int*)bound->data = 0; meta_name_set(bound, "PARENT_SETTING_MIN"); meta_attach(setting, bound); bound = meta_new_data(MT_INT, filter, malloc(sizeof(int))); *(int*)bound->data = 1; meta_name_set(bound, "PARENT_SETTING_MAX"); meta_attach(setting, bound); return filter; }
/* * List depends on: * - state->sort * - state->tags * - state->filter * - dir contents on FS */ static Eina_Array * _fill_files(const madshelf_state_t *state, const char *dir, int *old_pos) { char *old_file = curdir_get(dir); if(old_pos) *old_pos = -1; Eina_Array *files = eina_array_new(10); /* HACK: using global variable to pas state into sort function */ cur_dir = !strcmp(dir, "/") ? "" : dir; Eina_List *ls = ecore_file_ls(dir); ls = eina_list_sort(ls, eina_list_count(ls), state->sort == MADSHELF_SORT_NAME ? &_name : (state->sort == MADSHELF_SORT_NAMEREV ? &_namerev : &_daterev)); /* First select directories */ for (Eina_List *i = ls; i; i = eina_list_next(i)) { const char *file = eina_list_data_get(i); char *filename = xasprintf("%s/%s", !strcmp(dir, "/") ? "" : dir, file); if (!ecore_file_is_dir(filename)) { free(filename); continue; } if (!state->show_hidden && is_hidden(state, filename)) { free(filename); continue; } if (old_file && old_pos) if (!strcmp(old_file, file)) *old_pos = eina_array_count_get(files); eina_array_push(files, filename); } /* Then files */ for (Eina_List *i = ls; i; i = eina_list_next(i)) { const char *file = eina_list_data_get(i); char *filename = xasprintf("%s/%s", !strcmp(dir, "/") ? "" : dir, file); if (ecore_file_is_dir(filename)) { free(filename); continue; } if (!state->show_hidden && is_hidden(state, filename)) { free(filename); continue; } if (old_file && old_pos) if (!strcmp(old_file, file)) *old_pos = eina_array_count_get(files); eina_array_push(files, filename); } char* s; EINA_LIST_FREE(ls, s) free(s); free(old_file); return files; }
Filter *filter_gauss_blur_new(void) { Filter *filter = filter_new(&filter_core_gauss); Meta *in, *out, *channel, *bitdepth, *color[3], *setting, *bound; Meta *ch_out[3]; _Data *data = calloc(sizeof(_Data), 1); data->sigma = calloc(sizeof(float), 1); data->buf1 = malloc(BLURBUF); data->buf2 = malloc(BLURBUF); filter->fixme_outcount = 3; ea_push(filter->data, data); *data->sigma = 5.0; filter->mode_buffer = filter_mode_buffer_new(); filter->mode_buffer->worker = &_worker; filter->mode_buffer->threadsafe = 1; filter->mode_buffer->area_calc = &_area_calc; filter->mode_buffer->data_new = &_gauss_data_new; bitdepth = meta_new_data(MT_BITDEPTH, filter, malloc(sizeof(int))); *(int*)(bitdepth->data) = BD_U8; bitdepth->replace = bitdepth; out = meta_new(MT_BUNDLE, filter); eina_array_push(filter->out, out); channel = meta_new_channel(filter, 1); color[0] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int))); *(int*)(color[0]->data) = CS_LAB_L; meta_attach(channel, color[0]); meta_attach(channel, bitdepth); meta_attach(out, channel); ch_out[0] = channel; channel = meta_new_channel(filter, 2); color[1] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int))); *(int*)(color[1]->data) = CS_LAB_A; meta_attach(channel, color[1]); meta_attach(channel, bitdepth); meta_attach(out, channel); ch_out[1] = channel; channel = meta_new_channel(filter, 3); color[2] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int))); *(int*)(color[2]->data) = CS_LAB_B; meta_attach(channel, color[2]); meta_attach(channel, bitdepth); meta_attach(out, channel); ch_out[2] = channel; in = meta_new(MT_BUNDLE, filter); in->replace = out; eina_array_push(filter->in, in); channel = meta_new_channel(filter, 1); color[0]->replace = color[0]; channel->replace = ch_out[0]; meta_attach(channel, color[0]); meta_attach(channel, bitdepth); meta_attach(in, channel); channel = meta_new_channel(filter, 2); color[1]->replace = color[1]; channel->replace = ch_out[1]; meta_attach(channel, color[1]); meta_attach(channel, bitdepth); meta_attach(in, channel); channel = meta_new_channel(filter, 3); color[2]->replace = color[2]; color[2]->replace = color[2]; channel->replace = ch_out[2]; meta_attach(channel, color[2]); meta_attach(channel, bitdepth); meta_attach(in, channel); setting = meta_new_data(MT_FLOAT, filter, data->sigma); meta_name_set(setting, "sigma"); eina_array_push(filter->settings, setting); bound = meta_new_data(MT_FLOAT, filter, malloc(sizeof(int))); *(float*)bound->data = 0; meta_name_set(bound, "PARENT_SETTING_MIN"); meta_attach(setting, bound); bound = meta_new_data(MT_FLOAT, filter, malloc(sizeof(int))); *(float*)bound->data = MAX_SIGMA; meta_name_set(bound, "PARENT_SETTING_MAX"); meta_attach(setting, bound); return filter; }
static void _initialize_handlers(Eio_Sentry_Data *pd) { Ecore_Event_Handler *h; EINA_SAFETY_ON_NULL_RETURN(pd); pd->handlers = eina_array_new(11); h = ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_DIRECTORY_CREATED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_DIRECTORY_MODIFIED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_DIRECTORY_CLOSED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_SELF_RENAME, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_SELF_DELETED, _handle_event, pd); eina_array_push(pd->handlers, h); h = ecore_event_handler_add(EIO_MONITOR_ERROR, _handle_event, pd); eina_array_push(pd->handlers, h); }
void * evas_software_xcb_outbuf_new_region_for_update(Outbuf *buf, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch) { RGBA_Image *im = NULL; Outbuf_Region *obr = NULL; Eina_Bool use_shm = EINA_TRUE; Eina_Bool alpha = EINA_FALSE; int bpl = 0; if ((buf->onebuf) && (buf->priv.x11.xcb.shm)) { Eina_Rectangle *rect; RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, buf->w, buf->h); if (!(obr = calloc(1, sizeof(Outbuf_Region)))) return NULL; if (!(rect = eina_rectangle_new(x, y, w, h))) { free(obr); return NULL; } if ((eina_array_push(&buf->priv.onebuf_regions, rect)) && (buf->priv.onebuf)) { if (cx) *cx = x; if (cy) *cy = y; if (cw) *cw = w; if (ch) *ch = h; if (!buf->priv.synced) { _xcbob_sync(buf->priv.x11.xcb.conn); buf->priv.synced = EINA_TRUE; } free(obr); return buf->priv.onebuf; } obr->x = 0; obr->y = 0; obr->w = buf->w; obr->h = buf->h; if (cx) *cx = x; if (cy) *cy = y; if (cw) *cw = w; if (ch) *ch = h; alpha = ((buf->priv.x11.xcb.mask) || (buf->priv.destination_alpha)); use_shm = buf->priv.x11.xcb.shm; if ((buf->rot == 0) && (buf->priv.x11.xcb.imdepth == 32) && (buf->priv.mask.r == 0xff0000) && (buf->priv.mask.g == 0x00ff00) && (buf->priv.mask.b == 0x0000ff)) { obr->xcbob = evas_software_xcb_output_buffer_new(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.visual, buf->priv.x11.xcb.depth, buf->w, buf->h, use_shm, NULL); if (!obr->xcbob) { free(obr); return NULL; } #ifdef EVAS_CSERVE2 if (evas_cserve2_use_get()) { im = (RGBA_Image *)evas_cache2_image_data(evas_common_image_cache2_get(), buf->w, buf->h, (DATA32 *)evas_software_xcb_output_buffer_data(obr->xcbob, &bpl), alpha, EVAS_COLORSPACE_ARGB8888); } else #endif { im = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(), buf->w, buf->h, (DATA32 *)evas_software_xcb_output_buffer_data(obr->xcbob, &bpl), alpha, EVAS_COLORSPACE_ARGB8888); } if (!im) { evas_software_xcb_output_buffer_free(obr->xcbob, EINA_FALSE); free(obr); return NULL; } im->extended_info = obr; if (buf->priv.x11.xcb.mask) { obr->mask = evas_software_xcb_output_buffer_new(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.visual, 1, buf->w, buf->h, use_shm, NULL); } } else { int bw = 0, bh = 0; #ifdef EVAS_CSERVE2 if (evas_cserve2_use_get()) { im = (RGBA_Image *)evas_cache2_image_empty(evas_common_image_cache2_get()); } else #endif { im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get()); } if (!im) { free(obr); return NULL; } im->cache_entry.flags.alpha |= (alpha ? 1 : 0); #ifdef EVAS_CSERVE2 if (evas_cserve2_use_get()) evas_cache2_image_surface_alloc(&im->cache_entry, buf->w, buf->h); else #endif evas_cache_image_surface_alloc(&im->cache_entry, buf->w, buf->h); im->extended_info = obr; if ((buf->rot == 0) || (buf->rot == 180)) { bw = buf->w; bh = buf->h; } else if ((buf->rot == 90) || (buf->rot == 270)) { bw = buf->h; bh = buf->w; } obr->xcbob = evas_software_xcb_output_buffer_new(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.visual, buf->priv.x11.xcb.depth, bw, bh, use_shm, NULL); if (!obr->xcbob) { #ifdef EVAS_CSERVE2 if (evas_cserve2_use_get()) evas_cache2_image_close(&im->cache_entry); else #endif evas_cache_image_drop(&im->cache_entry); free(obr); return NULL; } if (buf->priv.x11.xcb.mask) { obr->mask = evas_software_xcb_output_buffer_new(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.visual, 1, bw, bh, use_shm, NULL); } } /* FIXME: We should be able to remove this memset. */ if ((alpha) && (im->image.data)) { /* FIXME: Faster memset */ // memset(im->image.data, 0, (w * h * sizeof(DATA32))); } buf->priv.onebuf = im; return im; } if (!(obr = calloc(1, sizeof(Outbuf_Region)))) return NULL; obr->x = x; obr->y = y; obr->w = w; obr->h = h; if (cx) *cx = 0; if (cy) *cy = 0; if (cw) *cw = w; if (ch) *ch = h; use_shm = buf->priv.x11.xcb.shm; alpha = ((buf->priv.x11.xcb.mask) || (buf->priv.destination_alpha)); if ((buf->rot == 0) && (buf->priv.x11.xcb.imdepth == 32) && (buf->priv.mask.r == 0xff0000) && (buf->priv.mask.g == 0x00ff00) && (buf->priv.mask.b == 0x0000ff)) { obr->xcbob = _find_xcbob(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.visual, buf->priv.x11.xcb.depth, w, h, use_shm, NULL); if (!obr->xcbob) { free(obr); return NULL; } #ifdef EVAS_CSERVE2 if (evas_cserve2_use_get()) { im = (RGBA_Image *)evas_cache2_image_data(evas_common_image_cache2_get(), w, h, (DATA32 *)evas_software_xcb_output_buffer_data(obr->xcbob, &bpl), alpha, EVAS_COLORSPACE_ARGB8888); } else #endif { im = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(), w, h, (DATA32 *)evas_software_xcb_output_buffer_data(obr->xcbob, &bpl), alpha, EVAS_COLORSPACE_ARGB8888); } if (!im) { _unfind_xcbob(obr->xcbob, EINA_FALSE); free(obr); return NULL; } im->extended_info = obr; if (buf->priv.x11.xcb.mask) { obr->mask = _find_xcbob(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.visual, 1, w, h, use_shm, NULL); } } else { int bw = 0, bh = 0; #ifdef EVAS_CSERVE2 if (evas_cserve2_use_get()) { im = (RGBA_Image *)evas_cache2_image_empty(evas_common_image_cache2_get()); } else #endif { im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get()); } if (!im) { free(obr); return NULL; } im->cache_entry.flags.alpha |= (alpha ? 1 : 0); #ifdef EVAS_CSERVE2 if (evas_cserve2_use_get()) evas_cache2_image_surface_alloc(&im->cache_entry, w, h); else #endif evas_cache_image_surface_alloc(&im->cache_entry, w, h); im->extended_info = obr; if ((buf->rot == 0) || (buf->rot == 180)) { bw = w; bh = h; } else if ((buf->rot == 90) || (buf->rot == 270)) { bw = h; bh = w; } obr->xcbob = _find_xcbob(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.visual, buf->priv.x11.xcb.depth, bw, bh, use_shm, NULL); if (!obr->xcbob) { #ifdef EVAS_CSERVE2 if (evas_cserve2_use_get()) evas_cache2_image_close(&im->cache_entry); else #endif evas_cache_image_drop(&im->cache_entry); free(obr); return NULL; } if (buf->priv.x11.xcb.mask) { obr->mask = _find_xcbob(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.visual, 1, bw, bh, use_shm, NULL); } } /* FIXME: We should be able to remove this memset. */ if (((buf->priv.x11.xcb.mask) || (buf->priv.destination_alpha)) && (im->image.data)) { /* FIXME: Faster memset */ // memset(im->image.data, 0, (w * h * sizeof(DATA32))); } buf->priv.pending_writes = eina_list_append(buf->priv.pending_writes, im); return im; }
static Eina_Value * azy_value_deserialize_struct_json(cJSON *object) { Eina_Array *st_members, *st_values; unsigned int offset = 0, z = 0; Eina_Value *value_st = NULL; Eina_Value_Struct_Member *members; Eina_Value_Struct_Desc *st_desc; const char *name; cJSON *child; st_desc = azy_value_util_struct_desc_new(); st_members = eina_array_new(1); st_values = eina_array_new(1); for (child = object->child; child; child = child->next) { Eina_Value_Struct_Member *m; const Eina_Value_Type *type; Eina_Value *v; type = _azy_value_type_get(child); if (!type) goto end; name = child->string; m = (Eina_Value_Struct_Member*)calloc(1, sizeof(Eina_Value_Struct_Member)); m->name = eina_stringshare_add(name); offset = azy_value_util_type_offset(type, offset); m->offset = offset; offset += azy_value_util_type_size(type); m->type = type; eina_array_push(st_members, m); v = azy_value_deserialize_json(child); if (!v) goto end; eina_array_push(st_values, v); z++; } if (!z) { free(st_desc); goto end; } members = (Eina_Value_Struct_Member*)malloc(eina_array_count(st_members) * sizeof(Eina_Value_Struct_Member)); for (z = 0; z < eina_array_count(st_members); z++) { Eina_Value_Struct_Member *m = (Eina_Value_Struct_Member*)eina_array_data_get(st_members, z); members[z].name = m->name; members[z].offset = m->offset; members[z].type = m->type; free(m); } //setup st_desc->members = members; st_desc->member_count = eina_array_count(st_members); st_desc->size = offset; value_st = eina_value_struct_new(st_desc); //filling with data for (z = 0; z < eina_array_count(st_values); z++) { Eina_Value *v = (Eina_Value*)eina_array_data_get(st_values, z); eina_value_struct_value_set(value_st, members[z].name, v); eina_value_free(v); } end: eina_array_free(st_members); eina_array_free(st_values); return value_st; }
/* * (params[0] | (top of stack)) == filename * params[1 | 0] == key * params[2 | 1] == (cipher pass) */ static const Elixir_Loader_File * _elixir_eet_request(int param, const char **params) { Elixir_Loader_File *result = NULL; Elixir_Eet_Filename *top = NULL; Elixir_Eet_Filename *lookup = NULL; Eet_File *eet = NULL; char *filename; char *section = NULL; char *compiled_key; char *content = NULL; char *compiled = NULL; const char *key; const char *cipher; Eina_Bool free_compiled = EINA_FALSE; Eina_Bool free_content = EINA_FALSE; int content_length; int compiled_length; unsigned int i; if (param < 1 || param > 3) return NULL; cipher = NULL; switch (param) { case 1: if (stack && eina_array_count_get(stack) > 0) { top = eina_array_data_get(stack, eina_array_count_get(stack) - 1); filename = top->filename; key = params[0]; } else { filename = (char*) params[0]; key = "elixir/main"; } break; case 2: filename = (char*) params[0]; key = params[1]; break; case 3: filename = (char*) params[0]; key = params[1]; cipher = params[2]; break; default: return NULL; } filename = elixir_exe_canonicalize(filename); if (!filename) return NULL; section = strdup(key); if (!section) goto on_error; eet = eet_open(filename, EET_FILE_MODE_READ); if (!eet) goto on_error; /* Use a cache to prevent useless security check. */ lookup = eina_hash_find(cache, filename); if (lookup && lookup->eet == eet) { eet_close(eet); if (top != lookup) { eina_array_push(stack, lookup); top = lookup; } eet = lookup->eet; lru = eina_list_remove(lru, lookup); } else { /* Lookup is no longer valid, remove it from cache. */ if (lookup) { lru = eina_list_remove(lru, lookup); eina_hash_del(cache, filename, lookup); } if (!_elixir_eet_security_check(eet)) goto on_error; } compiled_key = alloca(strlen(key) + 2); snprintf(compiled_key, strlen(key) + 2, "%sx", key); if (cipher) { free_content = EINA_TRUE; content = eet_read_cipher(eet, key, &content_length, cipher); if (!content) goto on_error; compiled = eet_read_cipher(eet, compiled_key, &compiled_length, cipher); } else { content = (char*) eet_read_direct(eet, key, &content_length); if (!content) { free_content = EINA_TRUE; content = eet_read(eet, key, &content_length); } if (!content) goto on_error; compiled = (char*) eet_read_direct(eet, compiled_key, &compiled_length); if (!compiled) { free_compiled = EINA_TRUE; compiled = eet_read(eet, compiled_key, &compiled_length); } } if (memchr(content, '\0', content_length)) goto on_error; if (compiled) { for (i = 0; i < sizeof (_jsx_header) / sizeof (_jsx_header[0]); ++i) if (*(unsigned int*) compiled == _jsx_header[i]) break; if (i == sizeof (_jsx_header) / sizeof (_jsx_header[0])) if (free_compiled) { free(compiled); free_compiled = EINA_FALSE; compiled = NULL; } } result = malloc(sizeof (Elixir_Loader_File)); if (!result) goto on_error; result->content_length = content_length; result->content = content; result->free_content = free_content; result->compiled_length = compiled_length; result->compiled = compiled; result->free_compiled = free_compiled; /* Ref counting helper to find current open file. */ if (top) { top->reference++; free(filename); } else { top = malloc(sizeof (Elixir_Eet_Filename) + strlen(filename)); if (!top) goto on_error; top->reference = 1; top->filename = filename; top->eet = eet; eina_array_push(stack, top); eina_hash_add(cache, filename, top); } result->file = top; result->section = section; return result; on_error: if (result) free(result); if (content && free_content) free(content); if (compiled && free_compiled) free(compiled); if (eet) eet_close(eet); if (section) free(section); free(filename); return NULL; }