Ejemplo n.º 1
0
static void insert_smiley_cb(GtkWidget *widget, smiley_callback_data *data)
{
	GtkTextBuffer *entry = NULL;

	if (data && data->c_window)
		entry = gtk_text_view_get_buffer(GTK_TEXT_VIEW(data->c_window->
				entry));
	else {
		eb_debug(DBG_CORE, "smiley_callback_data has no chat* !\n");
		return;
	}

	if (entry) {
		const char *smiley = gtk_widget_get_name(widget);
		if (smiley) {
			gtk_text_buffer_insert_at_cursor(entry,
				smiley, strlen(smiley));
		}
	}

	if (data->c_window && data->c_window->smiley_window) {
		gtk_widget_destroy(data->c_window->smiley_window);
		data->c_window->smiley_window = NULL;
	} else
		eb_debug(DBG_CORE, "smiley_window is null * !\n");
}
Ejemplo n.º 2
0
char *ssl_certificate_check_signer(X509 *cert)
{
	X509_STORE_CTX store_ctx;
	X509_STORE *store;
	char *err_msg = NULL;

	store = X509_STORE_new();
	if (store == NULL) {
		printf("Can't create X509_STORE\n");
		return NULL;
	}
	if (!X509_STORE_set_default_paths(store)) {
		X509_STORE_free(store);
		return g_strdup(_("Can't load X509 default paths"));
	}

	X509_STORE_CTX_init(&store_ctx, store, cert, NULL);

	if (!X509_verify_cert(&store_ctx)) {
		err_msg =
			g_strdup(X509_verify_cert_error_string
			(X509_STORE_CTX_get_error(&store_ctx)));
		eb_debug(DBG_CORE, "Can't check signer: %s\n", err_msg);
		X509_STORE_CTX_cleanup(&store_ctx);
		X509_STORE_free(store);
		return err_msg;

	}
	X509_STORE_CTX_cleanup(&store_ctx);
	X509_STORE_free(store);
	return NULL;
}
Ejemplo n.º 3
0
Archivo: prefs.c Proyecto: ayttm/ayttm
static void s_write_module_prefs(void *inListItem, void *inData)
{
	eb_PLUGIN_INFO *plugin_info = inListItem;
	FILE *fp = (FILE *)inData;
	LList *master_prefs = NULL;
	LList *current_prefs = NULL;

	eb_debug(DBG_CORE, "Writing prefs for %s\n", plugin_info->name);

	fprintf(fp, "\t%s\n", plugin_info->name);

	master_prefs = GetPref(plugin_info->name);
	master_prefs = value_pair_remove(master_prefs, "load");

	current_prefs = eb_input_to_value_pair(plugin_info->pi.prefs);

	if (plugin_info->status == PLUGIN_LOADED)
		current_prefs = value_pair_add(current_prefs, "load", "1");
	else
		current_prefs = value_pair_add(current_prefs, "load", "0");

	master_prefs = value_pair_update(master_prefs, current_prefs);

	SetPref(plugin_info->name, master_prefs);

	value_pair_print_values(master_prefs, fp, 2);

	fprintf(fp, "\tend\n");

	value_pair_free(current_prefs);
}
Ejemplo n.º 4
0
static void ssl_certificate_save(SSLCertificate *cert)
{
	char *file, *port;
	FILE *fp;

	file = g_strconcat(config_dir, G_DIR_SEPARATOR_S,
		"certs", G_DIR_SEPARATOR_S, NULL);

	if (!is_dir_exist(file))
		mkdir(file, S_IRWXU);

	g_free(file);

	port = g_strdup_printf("%d", cert->port);
	file = g_strconcat(config_dir, G_DIR_SEPARATOR_S,
		"certs", G_DIR_SEPARATOR_S,
		cert->host, ".", port, ".cert", NULL);

	g_free(port);
	fp = fopen(file, "wb");
	if (fp == NULL) {
		g_free(file);
		eb_debug(DBG_CORE, "Can't save certificate !\n");
		return;
	}
	i2d_X509_fp(fp, cert->x509_cert);
	g_free(file);
	fclose(fp);

}
Ejemplo n.º 5
0
static int plugin_init()
{
	input_list *il = g_new0(input_list, 1);
	eb_debug(DBG_MOD, "icq-toc\n");
	ref_count = 0;
	plugin_info.prefs = il;
	il->widget.entry.value = icq_server;
	il->name = "icq_server";
	il->label = _("Server:");
	il->type = EB_INPUT_ENTRY;

	il->next = g_new0(input_list, 1);
	il = il->next;
	il->widget.entry.value = icq_port;
	il->name = "icq_port";
	il->label = _("Port:");
	il->type = EB_INPUT_ENTRY;

	il->next = g_new0(input_list, 1);
	il = il->next;
	il->widget.checkbox.value = &do_icq_debug;
	il->name = "do_icq_debug";
	il->label = _("Enable debugging");
	il->type = EB_INPUT_CHECKBOX;

/*
	il->next = g_new0(input_list, 1);
	il = il->next;
	il->widget.entry.value = icq_info;
	il->name = "icq_info";
	il->label = _("Info:");
	il->type = EB_INPUT_ENTRY;
*/
	return (0);
}
Ejemplo n.º 6
0
static int eb_icq_keep_alive(gpointer data)
{
	struct eb_icq_local_account_data *alad = data;
	toc_conn *conn = alad->conn;
	eb_debug(DBG_TOC, "eb_icq_keep_alive %d %d\n", conn->fd, conn->seq_num);
	icqtoc_send_keep_alive(alad->conn);
	return TRUE;
}
Ejemplo n.º 7
0
static void eb_icq_join_ack(toc_conn *conn, char *id, char *name)
{
	eb_chat_room *ecr =
		find_chat_room_by_name(name, SERVICE_INFO.protocol_id);
	eb_local_account *ela = conn->account;

	eb_debug(DBG_TOC, "eb_icq_join_ack %s %s\n", id, name);

	if (!ecr) {
		ecr = eb_icq_make_chat_room(name, ela, 0);
	}
	eb_debug(DBG_TOC, "Match found, copying id!!");

	strncpy(ecr->id, id, sizeof(ecr->id));

	eb_join_chat_room(ecr, TRUE);
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
/* 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);
}
Ejemplo n.º 10
0
static void eb_icq_disconnect(toc_conn *conn)
{
	eb_local_account *ela = conn->account;
	eb_debug(DBG_TOC, "eb_icq_disconnect %d %d\n", conn->fd, conn->seq_num);
	if (ela) {
		eb_icq_logout(ela);
	} else
		g_warning("NULL account associated with icq connection");
}
Ejemplo n.º 11
0
static int plugin_finish()
{
	while (plugin_info.prefs) {
		input_list *il = plugin_info.prefs->next;
		g_free(plugin_info.prefs);
		plugin_info.prefs = il;
	}
	eb_debug(DBG_MOD, "Returning the ref_count: %i\n", ref_count);
	return (ref_count);
}
Ejemplo n.º 12
0
void AySpellChecker::reload()
{
	language = get_language();
	delete spell_checker;

	try {
		spell_checker = enchant::Broker::instance()->request_dict(language);
	} catch (enchant::Exception e) {
		eb_debug(DBG_CORE, "Error while loading enchant dictionary: %s\n", e.what());
	}
}
Ejemplo n.º 13
0
static void eb_icq_join_error(toc_conn *conn, char *name)
{
	eb_chat_room *ecr =
		find_chat_room_by_name(name, SERVICE_INFO.protocol_id);

	eb_debug(DBG_TOC, "eb_icq_join_err %s\n", name);

	if (!ecr)
		return;

	eb_destroy_chat_room(ecr);
}
Ejemplo n.º 14
0
static void eb_icq_callback(void *data, int source,
	eb_input_condition condition)
{
	struct eb_icq_local_account_data *alad = data;
	toc_conn *conn = alad->conn;
	eb_debug(DBG_TOC, "eb_icq_callback %d %d\n", conn->fd, conn->seq_num);
	if (source < 0) {
		//eb_input_remove(*((int*)data));
		g_assert(0);
	}
	icqtoc_callback(((struct eb_icq_local_account_data *)data)->conn);

}
Ejemplo n.º 15
0
static eb_local_account *eb_nomodule_read_local_config(LList *pairs)
{
	eb_local_account *ela = calloc(1, sizeof(eb_local_account));
	struct eb_nomodule_local_account_data *ala =
		calloc(1, sizeof(struct eb_nomodule_local_account_data));
	char *ptr = NULL;

	eb_debug(DBG_CORE, "eb_nomodule_read_local_config: entering\n");
	/*you know, eventually error handling should be put in here */
	ptr = value_pair_get_value(pairs, "SCREEN_NAME");

	if (ptr) {
		strncpy(ela->handle, ptr, sizeof(ela->handle));
		free(ptr);
	}

	if (!ela->handle[0]) {
		fprintf(stderr,
			"Error!  Invalid account config no SCREEN_NAME defined!\n");
		return 0;
	}

	strncpy(ela->alias, ela->handle, MAX_PREF_LEN);
	ptr = value_pair_get_value(pairs, "PASSWORD");
	if (!ptr) {
		fprintf(stderr,
			"Warning!  No password specified for handle %s\n",
			ela->handle);
	} else {
		strncpy(ala->password, ptr, 255);
		free(ptr);
	}
	ela->service_id = SERVICE_INFO.protocol_id;
	ela->protocol_local_account_data = ala;
	ala->status = 0;
	eb_debug(DBG_CORE, "eb_nomodule_read_local_config: leaving\n");

	return ela;
}
Ejemplo n.º 16
0
void	display_pixel(t_img *img, int x, int y, t_ray *rayon)
{
	t_data		*d;
	t_vector	b;
	t_vector	ray_dir;
	int			color;

	d = data_init();
	vector_set(&b, x - (d->win_size_x / 2), y - (d->win_size_y / 2), 0);
	vector_set(&ray_dir, b.x - d->cam->x, b.y - d->cam->y, b.z - d->cam->z);
	vector_normalize(&ray_dir);
	vector_set(rayon->o, d->cam->x, d->cam->y, d->cam->z);
	vector_set(rayon->d, ray_dir.x, ray_dir.y, ray_dir.z);
	vector_normalize(rayon->d);
	color = color_pixel(rayon, 200000, DEPTH);
	eb_debug(ft_concat2("couleur du pixel : ", ft_lutohex(color)), 1);
	eb_put_pixel_to_img(img, x, y, color);
}
Ejemplo n.º 17
0
int load_accounts_from_file(const char *file)
{
	FILE *fp;
	extern int accountparse();
	extern FILE *accountin;
	/*char buff[1024];
	   LList *accounts_old = accounts; */

	if (!(fp = fopen(file, "r")))
		return 0;

	accountin = fp;
	accountparse();
	eb_debug(DBG_CORE, "closing fp\n");
	fclose(fp);
	/*if (accounts_old) {
	   LList *walk = accounts_old;
	   for (; walk; walk = walk->next) 
	   accounts = l_list_append(accounts, walk->data);
	   }
	   fp = NULL; */
/*	g_snprintf(buff, 1024, "%saccounts", eb_config_dir());
	fp = fdopen(creat(buff, 0700), "w");
	while (fp && naccounts) {
		LList *config = NULL;
		eb_local_account *ela = (eb_local_account *)(naccounts->data);
		config = RUN_SERVICE(ela)->write_local_config(ela);

		fprintf(fp, "<ACCOUNT %s>\n", get_service_name(ela->service_id));
		value_pair_print_values(config, fp, 1);
		fprintf(fp, "</ACCOUNT>\n");

		naccounts = naccounts->next;
	}
	fclose(fp);
*/
	ay_set_submenus();
	return accounts != NULL;
}
Ejemplo n.º 18
0
int load_contacts_from_file(const char *file)
{
	FILE *fp;
	extern int contactparse();
	extern FILE *contactin;
	LList *cts = NULL;

	if (!(fp = fopen(file, "r")))
		return 0;
	contactin = fp;

	contactparse();

	fclose(fp);

	/* rename logs from old format (contact->nick) to new 
	   (contact->nick "-" contact->group->name) */

	if (temp_groups && groups) {
		while (temp_groups) {
			grouplist *grp = (grouplist *)temp_groups->data;
			grouplist *oldgrp = NULL;
			if ((oldgrp = find_grouplist_by_name(grp->name)) ==
				NULL) {
				eb_debug(DBG_CORE, "adding group %s\n",
					grp->name);
				add_group(grp->name);
				oldgrp = find_grouplist_by_name(grp->name);
			}
			while (grp->members) {
				struct contact *con =
					(struct contact *)grp->members->data;
				if (!find_contact_in_group_by_nick(con->nick,
						oldgrp)) {
					LList *w = con->accounts;
					int sid = 0;
					while (w) {
						eb_account *ea =
							(eb_account *)w->data;
						if (find_account_by_handle(ea->
								handle,
								ea->
								service_id)) {
							con->accounts =
								l_list_remove
								(con->accounts,
								ea);
							w = con->accounts;
						} else {
							sid = ea->service_id;
							w = w->next;
						}
					}
					if (!l_list_empty(con->accounts)
						&& con->accounts->data) {
						eb_debug(DBG_CORE,
							" adding contact %s\n",
							con->nick);
						add_new_contact(grp->name,
							con->nick, sid);
						w = con->accounts;
						while (w) {
							add_account_silent(con->
								nick,
								(eb_account *)
								w->data);
							eb_debug(DBG_CORE,
								"  adding account %s\n",
								((eb_account *)
									w->
									data)->
								handle);
							w = w->next;
						}
					}
				} else {
					while (con->accounts) {
						eb_account *ea =
							(eb_account *)con->
							accounts->data;
						if (!find_account_by_handle(ea->
								handle,
								ea->
								service_id)) {
							add_account_silent(con->
								nick, ea);
							eb_debug(DBG_CORE,
								"  adding account to ex.ct %s\n",
								ea->handle);
						}
						con->accounts =
							con->accounts->next;
					}
				}
				grp->members = grp->members->next;
			}

			temp_groups = temp_groups->next;
		}
	} else if (temp_groups) {
		eb_debug(DBG_CORE, "First pass\n");
		groups = temp_groups;
	}

	if (groups) {
		update_contact_list();
		write_contact_list();
	}

	cts = get_all_contacts();
	for (; cts && cts->data; cts = cts->next) {
		struct contact *c = (struct contact *)cts->data;
		FILE *test = NULL;
		char buff[NAME_MAX];
		eb_debug(DBG_CORE, "contact:%s\n", c->nick);
		make_safe_filename(buff, c->nick, c->group->name);
		if ((test = fopen(buff, "r")) != NULL)
			fclose(test);
		else
			rename_nick_log(NULL, c->nick, c->group->name, c->nick);
	}
	return 1;
}
Ejemplo n.º 19
0
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);

}
Ejemplo n.º 20
0
int ssl_certificate_check(X509 *x509_cert, const char *host, int port,
	void *data)
{
	SSLCertificate *current_cert =
		ssl_certificate_new(x509_cert, host, port);
	SSLCertificate *known_cert;

	if (current_cert == NULL) {
		eb_debug(DBG_CORE, "Buggy certificate !\n");
		return FALSE;
	}

	eb_debug(DBG_CORE, "%s%d\n", host, port);
	known_cert = ssl_certificate_find(host, port);

	if (known_cert == NULL) {
		char *err_msg, *cur_cert_str, *sig_status;
		int result = 0;

		sig_status = ssl_certificate_check_signer(x509_cert);

		if (sig_status == NULL) {
			char buf[1024];
			if (X509_NAME_get_text_by_NID(X509_get_subject_name
					(x509_cert), NID_commonName, buf,
					100) >= 0)
				if (!strcmp(buf, current_cert->host)) {
					ssl_certificate_save(current_cert);
					ssl_certificate_destroy(current_cert);
					return TRUE;
				}
		} else
			g_free(sig_status);

		cur_cert_str = ssl_certificate_to_string(current_cert);

		err_msg =
			g_strdup_printf(_
			("The server <b>%s</b> presented an unknown SSL certificate:\n\n%s\n\n"
				"Do you want to continue connecting?"),
			current_cert->host, cur_cert_str);

		result = ay_connection_verify(err_msg,
			_("Unknown Certificate!"), data);

		g_free(cur_cert_str);

		g_free(err_msg);

		if (result) {
			ssl_certificate_save(current_cert);
		}
		ssl_certificate_destroy(current_cert);

		return result;
	} else if (!ssl_certificate_compare(current_cert, known_cert)) {
		char *err_msg, *known_cert_str, *cur_cert_str;
		int result = -1;

		known_cert_str = ssl_certificate_to_string(known_cert);
		cur_cert_str = ssl_certificate_to_string(current_cert);
		err_msg =
			g_strdup_printf(_
			("%s's SSL certificate changed!\nWe have saved this one:\n%s\n\nIt is now:\n%s\n\n"
				"This could mean the server answering is not the known one.\n"
				"Do you want to continue connecting ?"),
			current_cert->host, known_cert_str, cur_cert_str);
		g_free(cur_cert_str);
		g_free(known_cert_str);

		result = ay_connection_verify(err_msg,
			_("Changed Certificate!"), data);

		g_free(err_msg);

		if (result) {
			ssl_certificate_save(current_cert);
		}
		ssl_certificate_destroy(current_cert);

		return result;
	}

	ssl_certificate_destroy(current_cert);
	ssl_certificate_destroy(known_cert);
	return TRUE;
}
Ejemplo n.º 21
0
void eb_parse_incoming_message(eb_local_account *account,
	eb_account *remote, char *message)
{
	char *ptr;
	char *buff = strdup(message);

	ptr = strtok(buff, " ");

	/* Do we want to keep this? */
	if (ptr && !strcmp(ptr, "EB_COMMAND") && !xfer_in_progress) {
		eb_debug(DBG_CORE, "EB_COMMAND received\n");
		ptr = strtok(NULL, " ");
		if (ptr && !strcmp(ptr, "SEND_FILE")) {
			char buff2[1024];
			char myname[1024];
			int s;
			struct sockaddr_in sa;
			struct hostent *hp;

			memset(&sa, 0, sizeof(struct sockaddr_in));	/* clear our address */
			gethostname(myname, 1023);	/* who are we? */
			hp = gethostbyname(myname);	/* get our address info */
			if (hp == NULL) {	/* we don't exist !? */
				eb_debug(DBG_CORE, "gethostbyname failed: %s\n",
					strerror(errno));
				free(buff);
				return;
			}
			sa.sin_family = hp->h_addrtype;	/* this is our host address */
			sa.sin_port = htons(45678);	/* this is our port number */
			if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {	/* create socket */
				eb_debug(DBG_CORE, "socket failed: %s\n",
					strerror(errno));
				free(buff);
				return;
			}
			if (bind(s, (struct sockaddr *)&sa,
					sizeof(struct sockaddr_in)) < 0) {
				eb_debug(DBG_CORE, "bind failed: %s\n",
					strerror(errno));
				close(s);
				free(buff);
				return;	/* bind address to socket */
			}
			listen(s, 1);	/* max # of queued connects */
			snprintf(buff2, 1024, "EB_COMMAND ACCEPT %s",
				get_local_addresses());
			RUN_SERVICE(remote)->send_im(account, remote, buff2);
			get_file(s);
		}
		if (ptr && !strcmp(ptr, "ACCEPT")) {
			int sockfd;
			struct sockaddr_in dest_addr;

			ptr = strtok(NULL, " ");
			if (!ptr) {
				free(buff);
				return;
			}

			sockfd = socket(AF_INET, SOCK_STREAM, 0);

			dest_addr.sin_family = AF_INET;
			dest_addr.sin_port = htons(45678);
			dest_addr.sin_addr.s_addr = inet_addr(ptr);
			memset(&(dest_addr.sin_zero), 0, 8);

			connect(sockfd, (struct sockaddr *)&dest_addr,
				sizeof(struct sockaddr));
			send_file(filename, sockfd);
		}
	} else {
		/* Ensure that the conversation comes up */
		ay_conversation_chat_with_account(remote);

		ay_conversation_got_message(remote->account_contact->conversation,
			remote->account_contact->nick, message);
	}

	free(buff);
}
Ejemplo n.º 22
0
Archivo: prefs.c Proyecto: ayttm/ayttm
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);
}