/* public functions */ EAPI int elm_main(int argc, char **argv) { Emote_Event *d; struct sigaction action; Emote_Protocol *p; unsigned int i; if (argc < 3) { printf("Usage:\n\temote <server> <nick> [username] [password]\n"); exit(1); } # ifdef ENABLE_NLS setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR); textdomain(PACKAGE); # endif /* trap keyboard interrupt from user (Ctrl + C) */ action.sa_sigaction = _em_main_interrupt; action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO; sigemptyset(&action.sa_mask); sigaction(SIGINT, &action, NULL); /* init our config subsystem */ if (!em_config_init()) _em_main_shutdown(EXIT_FAILURE); _em_main_shutdown_push(em_config_shutdown); /* init protocol subsystem */ if (!emote_init()) _em_main_shutdown(EXIT_FAILURE); _em_main_shutdown_push(emote_shutdown); /* init our gui subsystem */ if (!em_gui_init()) _em_main_shutdown(EXIT_FAILURE); _em_main_shutdown_push(em_gui_shutdown); for (i = 0; i < (sizeof(_em_events)/sizeof(Emote_Event_Type)); i++) { emote_event_handler_add(_em_events[i], _em_main_chat_events_handler, NULL); } em_protocols = eina_hash_string_superfast_new(NULL); p = emote_protocol_load("irc"); eina_hash_add(em_protocols, "irc", p); d = emote_event_new(p, EMOTE_EVENT_SERVER_CONNECT, argv[1], 6667, argv[2], ((argc > 3) ? argv[3] : "emote"), ((argc > 4) ? argv[4] : NULL)); emote_event_send(d); /* start main loop */ elm_run(); /* shutdown elm */ elm_shutdown(); /* shutdown */ _em_main_shutdown(EXIT_SUCCESS); return EXIT_SUCCESS; }
void hist_items_add(Hist *hist, const char * url, Hist_Item *hist_item) { EINA_SAFETY_ON_NULL_RETURN(hist); eina_hash_add(hist->items, url, hist_item); }
void fav_items_add(Fav *fav, const char * url, Fav_Item *fav_item) { EINA_SAFETY_ON_NULL_RETURN(fav); eina_hash_add(fav->items, url, fav_item); }
static int auth_etc_enlightenment_sysactions(char *a, char *u, char **g) { FILE *f; char file[4096], buf[4096], id[4096], ugname[4096], perm[4096], act[4096]; char *p, *pp, *s, **gp; int len, line = 0, ok = 0; int allow = 0; int deny = 0; snprintf(file, sizeof(file), "/etc/enlightenment/sysactions.conf"); f = fopen(file, "r"); if (!f) { snprintf(file, sizeof(file), PACKAGE_SYSCONF_DIR "/enlightenment/sysactions.conf"); f = fopen(file, "r"); if (!f) return 0; } while (fgets(buf, sizeof(buf), f)) { line++; len = strlen(buf); if (len < 1) continue; if (buf[len - 1] == '\n') buf[len - 1] = 0; /* format: * * # comment * user: username [allow:|deny:] halt reboot ... * group: groupname [allow:|deny:] suspend ... */ if (buf[0] == '#') continue; p = buf; p = get_word(p, id); p = get_word(p, ugname); pp = p; p = get_word(p, perm); allow = 0; deny = 0; if (!strcmp(id, "user:"******"allow:")) allow = 1; else if (!strcmp(perm, "deny:")) deny = 1; else goto malformed; } else continue; } else if (!strcmp(id, "group:")) { int matched; matched = 0; for (gp = g; *gp; gp++) { if (!fnmatch(ugname, *gp, 0)) { matched = 1; if (!strcmp(perm, "allow:")) allow = 1; else if (!strcmp(perm, "deny:")) deny = 1; else goto malformed; } } if (!matched) continue; } else if (!strcmp(id, "action:")) { while ((*pp) && (isspace(*pp))) pp++; s = eina_hash_find(actions, ugname); if (s) eina_hash_del(actions, ugname, s); if (!actions) actions = eina_hash_string_superfast_new(free); eina_hash_add(actions, ugname, strdup(pp)); continue; } else if (id[0] == 0) continue; else goto malformed; for (;; ) { p = get_word(p, act); if (act[0] == 0) break; if (!fnmatch(act, a, 0)) { if (allow) ok = 1; else if (deny) ok = -1; goto done; } } continue; malformed: printf("WARNING: %s:%i\n" "LINE: '%s'\n" "MALFORMED LINE. SKIPPED.\n", file, line, buf); } done: fclose(f); return ok; }
/** * @internal * @param file The file to parse * @return Returns an Eina_Hash with the contents of @a file, or NULL if the * file fails to parse or if the file doesn't exist * @brief Parses the ini file @a file into an Eina_Hash */ static Eina_Hash * efreet_ini_parse(const char *file) { const char *buffer, *line_start; FILE *f; Eina_Hash *data, *section = NULL; struct stat file_stat; int line_length, left; if (!file) return NULL; f = fopen(file, "rb"); if (!f) return NULL; if (fstat(fileno(f), &file_stat) || (file_stat.st_size < 1)) { fclose(f); return NULL; } if (!S_ISREG(file_stat.st_mode)) /* if not a regular file - close */ { fclose(f); return NULL; } left = file_stat.st_size; buffer = mmap(NULL, left, PROT_READ, MAP_SHARED, fileno(f), 0); if (buffer == MAP_FAILED) { fclose(f); return NULL; } data = eina_hash_string_small_new(EINA_FREE_CB(eina_hash_free)); line_start = buffer; while (left > 0) { int sep; /* find the end of line */ for (line_length = 0; (line_length < left) && (line_start[line_length] != '\n'); line_length++) ; /* check for all white space */ while (isspace(line_start[0]) && (line_length > 0)) { line_start++; line_length--; } /* skip empty lines and comments */ if ((line_length == 0) || (line_start[0] == '\r') || (line_start[0] == '\n') || (line_start[0] == '#') || (line_start[0] == '\0')) goto next_line; /* new section */ if (line_start[0] == '[') { int header_length; /* find the ']' */ for (header_length = 1; (header_length < line_length) && (line_start[header_length] != ']'); ++header_length) ; if (line_start[header_length] == ']') { const char *header; header = alloca(header_length * sizeof(unsigned char)); if (!header) goto next_line; memcpy((char*)header, line_start + 1, header_length - 1); ((char*)header)[header_length - 1] = '\0'; section = eina_hash_string_small_new(EINA_FREE_CB(eina_stringshare_del)); eina_hash_del_by_key(data, header); // if (old) INF("[efreet] Warning: duplicate section '%s' " // "in file '%s'", header, file); eina_hash_add(data, header, section); } else { /* invalid file - skip line? or refuse to parse file? */ /* just printf for now till we figure out what to do */ // printf("Invalid file (%s) (missing ] on group name)\n", file); } goto next_line; } if (!section) { // INF("Invalid file (%s) (missing section)", file); goto next_line; } /* find for '=' */ for (sep = 0; (sep < line_length) && (line_start[sep] != '='); ++sep) ; if (sep < line_length) { char *key, *value; int key_end, value_start, value_end; /* trim whitespace from end of key */ for (key_end = sep - 1; (key_end > 0) && isspace(line_start[key_end]); --key_end) ; if (!isspace(line_start[key_end])) key_end++; /* trim whitespace from start of value */ for (value_start = sep + 1; (value_start < line_length) && isspace(line_start[value_start]); ++value_start) ; /* trim \n off of end of value */ for (value_end = line_length; (value_end > value_start) && ((line_start[value_end] == '\n') || (line_start[value_end] == '\r')); --value_end) ; if (line_start[value_end] != '\n' && line_start[value_end] != '\r' && value_end < line_length) value_end++; /* make sure we have a key. blank values are allowed */ if (key_end == 0) { /* invalid file... */ // INF("Invalid file (%s) (invalid key=value pair)", file); goto next_line; } key = alloca(key_end + 1); value = alloca(value_end - value_start + 1); if (!key || !value) goto next_line; memcpy(key, line_start, key_end); key[key_end] = '\0'; memcpy(value, line_start + value_start, value_end - value_start); value[value_end - value_start] = '\0'; eina_hash_del_by_key(section, key); eina_hash_add(section, key, efreet_ini_unescape(value)); } // else // { // /* invalid file... */ // INF("Invalid file (%s) (missing = from key=value pair)", file); // } next_line: left -= line_length + 1; line_start += line_length + 1; } munmap((char*) buffer, file_stat.st_size); fclose(f); #if 0 if (!eina_hash_population(data)) { eina_hash_free(data); return NULL; } #endif return data; }
void lime_filter_add(Filter_Core *fc) { eina_hash_add(lime_filters, fc->shortname, fc); }
void lime_filters_init(void) { //TODO dynamic loading from filters as dynamic library! on-demand? (by short-name?) lime_filters = eina_hash_string_small_new(&free); eina_hash_add(lime_filters, filter_core_gauss.shortname, &filter_core_gauss); eina_hash_add(lime_filters, filter_core_compare.shortname, &filter_core_compare); eina_hash_add(lime_filters, filter_core_down.shortname, &filter_core_down); eina_hash_add(lime_filters, filter_core_memsink.shortname, &filter_core_memsink); eina_hash_add(lime_filters, filter_core_convert.shortname, &filter_core_convert); eina_hash_add(lime_filters, filter_core_loadtiff.shortname, &filter_core_loadtiff); eina_hash_add(lime_filters, filter_core_contrast.shortname, &filter_core_contrast); eina_hash_add(lime_filters, filter_core_exposure.shortname, &filter_core_exposure); eina_hash_add(lime_filters, filter_core_load.shortname, &filter_core_load); eina_hash_add(lime_filters, filter_core_savetiff.shortname, &filter_core_savetiff); eina_hash_add(lime_filters, filter_core_sharpen.shortname, &filter_core_sharpen); eina_hash_add(lime_filters, filter_core_denoise.shortname, &filter_core_denoise); eina_hash_add(lime_filters, filter_core_pretend.shortname, &filter_core_pretend); //eina_hash_add(lime_filters, filter_core_crop.shortname, &filter_core_crop); eina_hash_add(lime_filters, filter_core_simplerotate.shortname, &filter_core_simplerotate); eina_hash_add(lime_filters, filter_core_rotate.shortname, &filter_core_rotate); eina_hash_add(lime_filters, filter_core_savejpeg.shortname, &filter_core_savejpeg); eina_hash_add(lime_filters, filter_core_curves.shortname, &filter_core_curves); eina_hash_add(lime_filters, filter_core_lrdeconv.shortname, &filter_core_lrdeconv); eina_hash_add(lime_filters, filter_core_lensfun.shortname, &filter_core_lensfun); }
int main(int argc, const char *argv[]) { Eina_Hash *phone_book = NULL; int i; const char *entry_name = "Heitor Villa-Lobos"; char *phone = NULL; Eina_Bool r; Eina_Iterator *it; void *data; eina_init(); phone_book = eina_hash_string_superfast_new(_phone_entry_free_cb); // Add initial entries to our hash for (i = 0; _start_entries[i].name != NULL; i++) { eina_hash_add(phone_book, _start_entries[i].name, strdup(_start_entries[i].number)); } // Look for a specific entry and get its phone number phone = eina_hash_find(phone_book, entry_name); if (phone) { printf("Printing entry.\n"); printf("Name: %s\n", entry_name); printf("Number: %s\n\n", phone); } // Delete this entry r = eina_hash_del(phone_book, entry_name, NULL); printf("Hash entry successfully deleted? %d\n\n", r); // Modify the pointer data of an entry and free the old one phone = eina_hash_modify(phone_book, "Richard Georg Strauss", strdup("+23 45 111-11111")); free(phone); // Modify or add an entry to the hash with eina_hash_set // Let's first add a new entry eina_error_set(0); phone = eina_hash_set(phone_book, "Raul Seixas", strdup("+55 01 234-56789")); if (!phone) { Eina_Error err = eina_error_get(); if (!err) { printf("No previous phone found for Raul Seixas. "); printf("Creating new entry.\n"); } else printf("Error when setting phone for Raul Seixas\n"); } else { printf("Old phone for Raul Seixas was %s\n", phone); free(phone); } printf("\n"); // Now change the phone number eina_error_set(0); phone = eina_hash_set(phone_book, "Raul Seixas", strdup("+55 02 222-22222")); if (phone) { printf("Changing phone for Raul Seixas to +55 02 222-22222. "); printf("Old phone was %s\n", phone); free(phone); } else { Eina_Error err = eina_error_get(); if (err) printf("Error when changing phone for Raul Seixas\n"); else { printf("No previous phone found for Raul Seixas. "); printf("Creating new entry.\n"); } } // There are many ways to iterate over our Phone book. // First, iterate showing the names and associated numbers. printf("List of phones:\n"); eina_hash_foreach(phone_book, _phone_book_foreach_cb, NULL); printf("\n"); // Now iterate using an iterator printf("List of phones:\n"); it = eina_hash_iterator_tuple_new(phone_book); while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = data; const char *name = t->key; const char *number = t->data; printf("%s: %s\n", name, number); } eina_iterator_free(it); // Always free the iterator after its use printf("\n"); // Just iterate over the keys (names) printf("List of names in the phone book:\n"); it = eina_hash_iterator_key_new(phone_book); while (eina_iterator_next(it, &data)) { const char *name = data; printf("%s\n", name); } eina_iterator_free(it); printf("\n"); // Just iterate over the data (numbers) printf("List of numbers in the phone book:\n"); it = eina_hash_iterator_data_new(phone_book); while (eina_iterator_next(it, &data)) { const char *number = data; printf("%s\n", number); } eina_iterator_free(it); printf("\n"); // Check how many items are in the phone book printf("There are %d items in the hash.\n\n", eina_hash_population(phone_book)); // Change the name (key) on an entry eina_hash_move(phone_book, "Raul Seixas", "Alceu Valenca"); printf("List of phones after change:\n"); eina_hash_foreach(phone_book, _phone_book_foreach_cb, NULL); printf("\n"); // Empty the phone book, but don't destroy it eina_hash_free_buckets(phone_book); printf("There are %d items in the hash.\n\n", eina_hash_population(phone_book)); // Phone book could still be used, but we are freeing it since we are // done for now eina_hash_free(phone_book); eina_shutdown(); }
static int cache_add(const char *path, const char *file_id, int priority __UNUSED__, int *changed) { Efreet_Desktop *desk; char *ext; INF("FOUND: %s", path); if (file_id) INF(" (id): %s", file_id); ext = strrchr(path, '.'); if (!ext || (strcmp(ext, ".desktop") && strcmp(ext, ".directory"))) return 1; desk = efreet_desktop_new(path); if (desk) INF(" OK"); else INF(" FAIL"); if (!desk) return 1; if (!desk->eet) { /* This file isn't in cache */ *changed = 1; INF(" NEW"); } else if (ecore_file_mod_time(desk->orig_path) != desk->load_time) { efreet_desktop_free(desk); *changed = 1; desk = efreet_desktop_uncached_new(path); if (desk) INF(" CHANGED"); else INF(" NO UNCACHED"); } if (!desk) return 1; if (file_id && old_file_ids && !eina_hash_find(old_file_ids->hash, file_id)) { *changed = 1; INF(" NOT IN UTILS"); } if (!eina_hash_find(paths, desk->orig_path)) { if (!eet_data_write(ef, edd, desk->orig_path, desk, 0)) return 0; eina_hash_add(paths, desk->orig_path, (void *)1); } /* TODO: We should check priority, and not just hope we search in right order */ /* TODO: We need to find out if prioritized file id has changed because of * changed search order. */ if (!desk->hidden && desk->type == EFREET_DESKTOP_TYPE_APPLICATION && file_id && !eina_hash_find(file_ids, file_id)) { Eina_List *l; char *data; Efreet_Cache_Array_String *array; #define ADD_LIST(list, hash) \ EINA_LIST_FOREACH((list), l, data) \ { \ array = eina_hash_find((hash), data); \ if (!array) \ array = NEW(Efreet_Cache_Array_String, 1); \ array->array = realloc(array->array, sizeof (char *) * (array->array_count + 1)); \ array->array[array->array_count++] = desk->orig_path; \ eina_hash_set((hash), data, array); \ } #define ADD_ELEM(elem, hash) \ if ((elem)) \ { \ data = (elem); \ array = eina_hash_find((hash), data); \ if (!array) \ array = NEW(Efreet_Cache_Array_String, 1); \ array->array = realloc(array->array, sizeof (char *) * (array->array_count + 1)); \ array->array[array->array_count++] = desk->orig_path; \ eina_hash_set((hash), data, array); \ } ADD_LIST(desk->mime_types, mime_types); ADD_LIST(desk->categories, categories); ADD_ELEM(desk->startup_wm_class, startup_wm_class); ADD_ELEM(desk->name, name); ADD_ELEM(desk->generic_name, generic_name); ADD_ELEM(desk->comment, comment); ADD_ELEM(desk->exec, exec); eina_hash_add(file_ids, file_id, desk->orig_path); eina_hash_add(desktops, desk->orig_path, desk); } else efreet_desktop_free(desk); return 1; }
/* * (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; }