service_container::service_ptr_t service_container::resolve_service_dependencies(string id) { logtrace << "service_container::resolve_service_dependencies('" << id << "')"; service_ptr_t service = this->services_.find(id); logtrace << " » found service: " << service->id() << ", got a " << service->get_service_definition_type_name(); if (service->was_visited()) return service; else if (service->is_resolving_in_progress()) return nullptr; // todo: throw ex. ? is this a cycle ? logtrace << " » resolving dependencies..."; service->set_resolving_in_progress(true); auto dependencies = service->get_dependencies_map(); logtrace << " » dependencies map contains " << dependencies.size() << " elements."; for (auto pair : dependencies) { auto depdecl = pair.second; logtrace << " - depends on service " << depdecl->get_service_id() << ", type: " << depdecl->get_service_type().pretty_name(); service_ptr_t serv = this->resolve_service_dependencies( depdecl->get_service_id() ); logtrace << " » " << service->id() << " : finished processing dep. : " << depdecl->get_service_id(); depdecl->set_service(serv); } logtrace << " » " << service->id() << " : end of dependencies resolution."; logtrace << " » " << service->id() << " : about to construct service."; service->construct(); logtrace << " » " << service->id() << " : construct() done."; service->set_resolving_in_progress(false); service->set_visited(true); return service; }
int connection_register(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); struct network_peer *peer; struct network_conn *nc; uint16_t id = get_service_id(service); DBG("%s id %u", device_get_path(device), id); peer = find_peer(peers, device); if (!peer) { peer = create_peer(device); if (!peer) return -1; peers = g_slist_append(peers, peer); } nc = g_new0(struct network_conn, 1); nc->id = id; nc->service = btd_service_ref(service); nc->state = DISCONNECTED; nc->peer = peer; btd_service_set_user_data(service, nc); DBG("id %u registered", id); peer->connections = g_slist_append(peer->connections, nc); return 0; }
/* Connect and initiate BNEP session */ int connection_connect(struct btd_service *service) { struct network_conn *nc = btd_service_get_user_data(service); struct network_peer *peer = nc->peer; uint16_t id = get_service_id(service); GError *err = NULL; const bdaddr_t *src; const bdaddr_t *dst; DBG("id %u", id); if (nc->state != DISCONNECTED) return -EALREADY; src = btd_adapter_get_address(device_get_adapter(peer->device)); dst = device_get_address(peer->device); nc->io = bt_io_connect(connect_cb, nc, NULL, &err, BT_IO_OPT_SOURCE_BDADDR, src, BT_IO_OPT_DEST_BDADDR, dst, BT_IO_OPT_PSM, BNEP_PSM, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM, BT_IO_OPT_OMTU, BNEP_MTU, BT_IO_OPT_IMTU, BNEP_MTU, BT_IO_OPT_INVALID); if (!nc->io) return -EIO; nc->state = CONNECTING; return 0; }
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; }
/* Callback for Add Button */ static void add_callback(GtkWidget *widget, gpointer data) { const gchar *text[4]; char *error_message = NULL; GtkTreeIter insert; text[CONNECT] = ""; text[USER_NAME] = gtk_entry_get_text(GTK_ENTRY(username)); text[PASSWORD] = gtk_entry_get_text(GTK_ENTRY(password)); text[SERVICE_TYPE] = gtk_combo_box_get_active_text(GTK_COMBO_BOX(service_type)); error_message = check_login_validity(text); if (error_message) { char *buf = g_strdup_printf(_ ("This account is not a valid %s account: \n\n %s"), (text[SERVICE_TYPE] ? text[SERVICE_TYPE] : ""), error_message); g_free(error_message); ay_do_error(_("Invalid Account"), buf); g_free(buf); return; } if (!can_multiaccount(eb_services[get_service_id(text[SERVICE_TYPE])])) { service_exists = FALSE; gtk_tree_model_foreach(GTK_TREE_MODEL(account_list_store), find_existing_account_add, (gchar *)text[SERVICE_TYPE]); if (service_exists) { char *buf = g_strdup_printf(_ ("You already have an account for %s service.\n\n" "Multiple accounts on this service aren't supported yet."), text[SERVICE_TYPE]); ay_do_error(_("Invalid Account"), buf); g_free(buf); return; } } gtk_list_store_append(account_list_store, &insert); gtk_list_store_set(account_list_store, &insert, CONNECT, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (connect_at_startup)), SERVICE_TYPE, text[SERVICE_TYPE], USER_NAME, text[USER_NAME], PASSWORD, text[PASSWORD], -1); num_accounts++; eb_debug(DBG_CORE, "num_accounts %d\n", num_accounts); gtk_entry_set_text(GTK_ENTRY(username), ""); gtk_entry_set_text(GTK_ENTRY(password), ""); gtk_combo_box_set_active(GTK_COMBO_BOX(service_type), -1); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(connect_at_startup), FALSE); }
gboolean find_existing_account_mod(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { gpointer serv; GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(account_list)); gtk_tree_model_get(model, iter, SERVICE_TYPE, &serv, -1); if (!gtk_tree_selection_path_is_selected(selection, path) && !strcasecmp(serv, data) && !can_multiaccount(eb_services[get_service_id(data)])) { return (service_exists = TRUE); } return (service_exists = FALSE); }
void connection_unregister(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); struct network_conn *conn = btd_service_get_user_data(service); struct network_peer *peer = conn->peer; uint16_t id = get_service_id(service); DBG("%s id %u", device_get_path(device), id); peer->connections = g_slist_remove(peer->connections, conn); connection_free(conn); if (peer->connections != NULL) return; g_dbus_unregister_interface(btd_get_dbus_connection(), device_get_path(device), NETWORK_PEER_INTERFACE); }
static char *check_login_validity(const gchar *text[]) { LList *services = get_service_list(); LList *l = services; if (text[USER_NAME] == NULL || strlen(text[USER_NAME]) == 0) return strdup(_("Please enter an account name.")); if (text[SERVICE_TYPE] == NULL || strlen(text[SERVICE_TYPE]) == 0) return strdup(_("Please select an account type.")); while (l) { if (!strcmp(l->data, text[SERVICE_TYPE])) return eb_services[get_service_id(l->data)]. sc->check_login(text[USER_NAME], text[PASSWORD]); l = l->next; } return NULL; }
void ayttm_prefs_read_file(char *file) { const int buffer_size = 1024; char buff[buffer_size]; char *const param = buff; /* just another name for buff... */ FILE *fp = NULL; snprintf(buff, buffer_size, "%s", file); fp = fopen(buff, "r"); if (fp == NULL) { char tmp[1024]; snprintf(tmp, 1024, "%sprefs", config_dir); if (!strcmp(file, tmp)) { printf("Creating prefs file [%s]\n", buff); ayttm_prefs_write(); } return; } fgets(param, buffer_size, fp); while (!feof(fp)) { int pref_type = CORE_PREF; char *val = buff; s_strip_whitespace(param); if (!strcasecmp(param, "plugins")) pref_type = PLUGIN_PREF; else if (!strcasecmp(param, "connections")) pref_type = SERVICE_PREF; if (pref_type != CORE_PREF) { for (;;) { int id = -1; char *plugin_name = NULL; LList *session_prefs = NULL; fgets(param, buffer_size, fp); s_strip_whitespace(param); if (!strcasecmp(param, "end")) break; switch (pref_type) { case PLUGIN_PREF: plugin_name = strdup(param); break; case SERVICE_PREF: id = get_service_id(param); break; default: assert(FALSE); break; } for (;;) { LList *old_session_prefs = NULL; fgets(param, buffer_size, fp); s_strip_whitespace(param); if (!strcasecmp(param, "end")) { switch (pref_type) { case PLUGIN_PREF: old_session_prefs = SetPref (plugin_name, session_prefs); free(plugin_name); break; case SERVICE_PREF: old_session_prefs = SetPref (get_service_name (id), session_prefs); break; default: assert(FALSE); break; } if (old_session_prefs != NULL) { eb_debug(DBG_CORE, "Freeing old_session_prefs\n"); value_pair_free (old_session_prefs); } break; } else { val = param; while (*val != 0 && *val != '=') val++; if (*val == '=') { *val = '\0'; val++; } /* strip off quotes */ if (*val == '"') { val++; val[strlen(val) - 1] = '\0'; } eb_debug(DBG_CORE, "Adding %s:%s to session_prefs\n", param, val); session_prefs = value_pair_add (session_prefs, param, val); } } } continue; } /* if(pref_type != CORE_PREF) */ val = param; while (*val != 0 && *val != '=') val++; if (*val == '=') { *val = '\0'; val++; } cSetLocalPref(param, val); fgets(param, buffer_size, fp); } fclose(fp); if (iGetLocalPref("do_proxy_auth") != 0) ay_proxy_set_default(iGetLocalPref("proxy_type"), cGetLocalPref("proxy_host"), iGetLocalPref("proxy_port"), cGetLocalPref("proxy_user"), cGetLocalPref("proxy_password")); else ay_proxy_set_default(iGetLocalPref("proxy_type"), cGetLocalPref("proxy_host"), iGetLocalPref("proxy_port"), NULL, NULL); }