AyModulePrefs *ay_prefs_sift_modules(void) { const LList *plugins = GetPref(EB_PLUGIN_LIST); AyModulePrefs *out = g_new0(AyModulePrefs, 1); for (; plugins; plugins = plugins->next) { eb_PLUGIN_INFO *plugin_info = plugins->data; if (plugin_info == NULL) continue; switch (plugin_info->pi.type) { case PLUGIN_SERVICE: out->services = l_list_append(out->services, plugin_info); break; case PLUGIN_FILTER: out->filters = l_list_append(out->filters, plugin_info); break; case PLUGIN_UTILITY: case PLUGIN_UNKNOWN: out->utilities = l_list_append(out->utilities, plugin_info); break; case PLUGIN_SMILEY: out->smileys = l_list_append(out->smileys, plugin_info); break; case PLUGIN_IMPORTER: out->importers = l_list_append(out->importers, plugin_info); break; } } return out; }
static gboolean save_accounts(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { FILE *fp = data; int tmp_connect = 0; char *service, *user, *pass; int id; gtk_tree_model_get(GTK_TREE_MODEL(account_list_store), iter, CONNECT, &tmp_connect, SERVICE_TYPE, &service, USER_NAME, &user, PASSWORD, &pass, -1); id = get_service_id(service); if (accounts && (ela = find_local_account_by_handle(user, id))) { LList *config = NULL; config = eb_services[id].sc->write_local_config(ela); config = value_pair_remove(config, "SCREEN_NAME"); config = value_pair_add(config, "SCREEN_NAME", user); config = value_pair_remove(config, "PASSWORD"); config = value_pair_add(config, "PASSWORD", pass); config = value_pair_remove(config, "CONNECT"); config = value_pair_add(config, "CONNECT", tmp_connect ? "1" : "0"); fprintf(fp, "<ACCOUNT %s>\n", service); value_pair_print_values(config, fp, 1); fprintf(fp, "</ACCOUNT>\n"); existing_accounts = l_list_append(existing_accounts, ela); } else { LList *config = NULL; eb_debug(DBG_CORE, "Adding new account %s service %s\n", user, service); pairs = value_pair_add(NULL, "SCREEN_NAME", user); pairs = value_pair_add(pairs, "PASSWORD", pass); save_account_info(service, pairs); ela = eb_services[id].sc->read_local_account_config(pairs); if (ela != NULL) { /* Is this an account for which a module is not loaded? */ if (ela->service_id == -1) ela->service_id = id; new_accounts = l_list_append(new_accounts, ela); config = eb_services[id].sc->write_local_config(ela); config = value_pair_remove(config, "CONNECT"); config = value_pair_add(config, "CONNECT", tmp_connect ? "1" : "0"); fprintf(fp, "<ACCOUNT %s>\n", service); value_pair_print_values(config, fp, 1); fprintf(fp, "</ACCOUNT>\n"); } else ay_do_error(_("Invalid Service"), _("Can't add account : unknown service")); } return FALSE; }
LList *add_protocol_smiley(LList *list, const char *text, const char *name) { protocol_smiley *psmile; psmile = g_new0(protocol_smiley, 1); strncpy(psmile->text, text, sizeof(psmile->text)); strncpy(psmile->name, name, sizeof(psmile->name)); return l_list_append(list, psmile); }
static void s_add_pref(const char *key, void *data) { ptr_list *pref_data = calloc(1, sizeof(ptr_list)); strcpy(pref_data->key, key); pref_data->value = (void *)data; s_global_prefs = l_list_append(s_global_prefs, pref_data); }
LList *add_smiley(LList *list, const char *name, const char **data, const char *service) { smiley *psmile; psmile = g_new0(smiley, 1); strncpy(psmile->name, name, sizeof(psmile->name)); if (service) psmile->service = strdup(service); psmile->pixmap = data; return l_list_append(list, psmile); }
LList * AySpellChecker::suggest(const char * word) { if(!word || !spell_checker) return NULL; std::vector<std::string> suggestions; spell_checker->suggest(word, suggestions); LList * words = NULL; std::vector<std::string>::iterator aEnd = suggestions.end(); for (std::vector<std::string>::iterator aI = suggestions.begin(); aI != aEnd; ++aI) words = l_list_append(words, strdup(aI->c_str())); return words; }
void *search_trd_fn(void *s_data) { // New thread has been created, that will be pushed into the search_threads list // s_data is the -m string that we need to search for. s_node *s = (s_node *)s_data; int len = strlen(s->_m); node *iter; for(iter = s->infile_list->head; iter != NULL; iter = iter->next) { //printf("Hi from search_thread_fn! My data is: %s, my thread id is: %u, protected is %s", s->_m, //(unsigned int)s->tid, iter->data); /**************************************************************************/ char *begin = iter->data; char *end = strchr(begin, '\0'); // terminating null char char *match = NULL; int matches = 0; int matched = 0; while (begin < end && (match = strstr(begin, s->_m)) != NULL) { printf("Found %s in line %s, tid: %u\n", s->_m, iter->data, (unsigned int)s->tid); matches++; matched++; begin = match + len; } s->lines += (matches > 0); s->matches += matches; /**************************************************************************/ if(matched > 0) { // Post data to collector thread. pthread_mutex_lock(&mutex); l_list_append(p3_data, iter->data); pthread_mutex_unlock(&mutex); } } pthread_exit(NULL); return NULL; }
static void eb_icq_oncoming_buddy(toc_conn *conn, char *user, int online, time_t idle, int evil, int unavailable) { eb_account *ea = find_account_with_ela(user, icq_find_local_account_by_conn(conn)); struct eb_icq_account_data *aad; struct eb_icq_local_account_data *alad; if (!ea) return; alad = ea->ela ? (struct eb_icq_local_account_data *)ea->ela-> protocol_local_account_data : NULL; aad = ea->protocol_account_data; if (alad && !l_list_find(alad->icq_buddies, ea->handle)) alad->icq_buddies = l_list_append(alad->icq_buddies, ea->handle); if (online && (aad->status == ICQ_OFFLINE)) { aad->status = ICQ_ONLINE; buddy_login(ea); } else if (!online && (aad->status != ICQ_OFFLINE)) { aad->status = ICQ_OFFLINE; buddy_logoff(ea); } if (online && unavailable) aad->status = ICQ_AWAY; else if (online) aad->status = ICQ_ONLINE; aad->evil = evil; aad->idle_time = idle; buddy_update_status(ea); }
void *read_trd_fn(void *trd_data) { // A new thread has been created, only one of its kind. // It was created in p2_actions // trd_data points to a struct r_trd_data which contains // (1) a linked list of all the lines from the input file // (2) a struct foo iterator of all the -m options supplied by the command line. struct r_trd_dat *infile_m_lines = (struct r_trd_dat *)trd_data; printf("Initting semaphore variable\n"); /* sem_init(&search_sem, 0, 1); // Initial value of search_sem set to 1 sem_init(&n_sem, 0, 0); // n_sem for producer/consumer, init to 0 sem_init(&more_data_sem, 0, 0); sem_init(&empty, 0, 1); sem_init(&full, 0, 0);*/ pthread_mutex_init(&mutex, NULL); struct foo *m = infile_m_lines->m_list; l_list *infile_list = infile_m_lines->infile_list; // Create list of search threads s_list *search_threads = s_list_init(); // initialize p3_data: p3_data = l_list_init(); int s_count = 0; for(; m != NULL; m = m->next) s_count++; int i = 0; // create each search thread: for(m = infile_m_lines->m_list; m != NULL; m = m->next) { s_node *s = (s_node *)malloc(sizeof(s_node)); if(s == NULL) err_sys("malloc (read_trd_fn)"); s->next = NULL; s->_m = strdup(m->string); if(s->_m == NULL) err_sys("strdup (read_trd_fn)"); // Copy input file buffer over to this s node: s->infile_list = l_list_init(); node *copy_iter = infile_list->head; for(; copy_iter != NULL; copy_iter = copy_iter->next) { l_list_append(s->infile_list, copy_iter->data); } // Append the newly created s_node to the list. if(s_list_append(search_threads, s) != 0) exit(0); pthread_create(&s->tid, NULL, search_trd_fn, (void *)s); pthread_join(s->tid, NULL); i++; } printf("s_count = %d\n", s_count); // Now all the search threads have been created (for 3 -m options supplied, there should be 3 threads) // Now put each line from the input file into each (search_thread's) s_node's _protected char*. node *end; for(end = p3_data->head; end != NULL; end = end->next) fprintf(infile_m_lines->fp, "%s", end->data); pthread_exit(NULL); return NULL; }
void show_smileys_cb(smiley_callback_data *data) { eb_local_account *account; LList *smileys = NULL; protocol_smiley *msmiley = NULL; GtkWidget *smileys_table = NULL; GtkWidget *button = NULL; GtkWidget *iconwid; GdkPixbuf *icon; GtkWidget *smiley_window; LList *done = NULL; LList *l; smiley *dsmile = NULL; int real_len = 0, x = -1, y = 0; int win_w = 0, win_h = 0, w, h; int win_x, win_y; int rows, cols; if (data && data->c_window) account = data->c_window->conv->local_user; else { eb_debug(DBG_CORE, "no chat* in data !\n"); return; } /* close popup if open */ if (data->c_window && data->c_window->smiley_window) { gtk_widget_destroy(data->c_window->smiley_window); data->c_window->smiley_window = NULL; return; } if (account && RUN_SERVICE(account)->get_smileys) smileys = RUN_SERVICE(account)->get_smileys(); else return; for (; smileys; smileys = smileys->next) { gboolean already_done = FALSE; msmiley = smileys->data; for (l = done; l; l = l->next) { protocol_smiley *done_smiley = l->data; if (!strcmp(msmiley->name, done_smiley->name)) { already_done = TRUE; break; } } if (already_done || !get_smiley_by_name(msmiley->name)) continue; done = l_list_append(done, msmiley); real_len++; } rows = fast_sqrt(real_len) - 1; if (rows < 5) rows = 5; cols = real_len / rows + !(!(real_len % rows)); smileys_table = gtk_table_new(rows, cols, TRUE); for (l = done; l; l = l_list_next(l)) { msmiley = l->data; dsmile = get_smiley_by_name_and_service(msmiley->name, GET_SERVICE(account).name); if (dsmile != NULL) { GtkWidget *parent = NULL; if (data && data->c_window) parent = data->c_window->window; icon = gdk_pixbuf_new_from_xpm_data((const char **) dsmile->pixmap); iconwid = gtk_image_new_from_pixbuf(icon); sscanf(dsmile->pixmap[0], "%d %d", &w, &h); if (x < rows) { x++; if (y == 0) win_h += h + 2; } if (x == rows) { y++; x = 0; win_w += w + 2; } gtk_widget_show(iconwid); button = gtk_button_new(); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); gtk_container_add(GTK_CONTAINER(button), iconwid); gtk_widget_show(button); gtk_widget_set_name(button, msmiley->text); g_signal_connect(button, "clicked", G_CALLBACK(insert_smiley_cb), data); gtk_table_attach(GTK_TABLE(smileys_table), button, y, y + 1, x, x + 1, GTK_FILL, GTK_FILL, 0, 0); } } l_list_free(done); done = NULL; smiley_window = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_set_transient_for(GTK_WINDOW(smiley_window), GTK_WINDOW(data->c_window->window)); gtk_window_set_modal(GTK_WINDOW(smiley_window), FALSE); gtk_window_set_wmclass(GTK_WINDOW(smiley_window), "ayttm-chat", "Ayttm"); gtk_window_set_title(GTK_WINDOW(smiley_window), "Smileys"); gtk_window_set_resizable(GTK_WINDOW(smiley_window), FALSE); gtk_widget_realize(smiley_window); g_signal_connect(smiley_window, "delete-event", G_CALLBACK(delete_event_cb), (gpointer) data); gtk_container_add(GTK_CONTAINER(smiley_window), smileys_table); gtk_widget_show(smileys_table); /* move the window a bit after the cursor and in the screen */ gdk_window_get_pointer(NULL, &win_x, &win_y, NULL); win_x += 5; win_y += 5; while ((win_x) + win_w > gdk_screen_width() - 30) win_x -= 20; while ((win_y) + win_h > gdk_screen_height() - 30) win_y -= 20; gtk_window_move(GTK_WINDOW(smiley_window), win_x, win_y); if (data && data->c_window) data->c_window->smiley_window = smiley_window; gtk_widget_show(smiley_window); }
/* Callback for OK button */ static void ok_callback(GtkWidget *widget, gpointer data) { FILE *fp; char buff[1024]; LList *saved_acc_info = NULL, *acc_walk = NULL, *to_remove = NULL; if (gtk_entry_get_text(GTK_ENTRY(username)) != NULL && strlen(gtk_entry_get_text(GTK_ENTRY(username))) > 0 && num_accounts == 0) { add_callback(widget, data); } g_snprintf(buff, 1024, "%saccounts", config_dir); fp = fdopen(creat(buff, 0700), "w"); if (num_accounts == 0) { ay_do_error(_("Invalid Account"), _("You didn't define an account.")); return; } eb_sign_off_all(); gtk_tree_model_foreach(GTK_TREE_MODEL(account_list_store), save_accounts, fp); fclose(fp); saved_acc_info = ay_save_account_information(-1); acc_walk = accounts; if (acc_walk) { while (acc_walk != NULL && acc_walk->data != NULL) { if (!l_list_find(existing_accounts, acc_walk->data)) { eb_local_account *removed = (eb_local_account *)(acc_walk->data); /* removed account */ if (removed && removed->connected && RUN_SERVICE(removed)->logout != NULL) RUN_SERVICE(removed)->logout(removed); to_remove = l_list_append(to_remove, acc_walk->data); } acc_walk = acc_walk->next; } for (acc_walk = to_remove; acc_walk && acc_walk->data; acc_walk = acc_walk->next) accounts = l_list_remove(accounts, acc_walk->data); l_list_free(to_remove); } acc_walk = new_accounts; if (acc_walk) { while (acc_walk != NULL) { accounts = l_list_append(accounts, acc_walk->data); acc_walk = acc_walk->next; } } gtk_widget_destroy(account_window); load_accounts(); rebuild_set_status_menu(); set_menu_sensitivity(); ay_restore_account_information(saved_acc_info); l_list_free(saved_acc_info); }