Exemplo n.º 1
0
static void
xfr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
{
	char *host;
	int port;

	if (strcmp(cmd->params[1], "SB") && strcmp(cmd->params[1], "NS"))
	{
		/* Maybe we can have a generic bad command error. */
		gaim_debug_error("msn", "Bad XFR command (%s)\n", cmd->params[1]);
		return;
	}

	msn_parse_socket(cmd->params[2], &host, &port);

	if (!strcmp(cmd->params[1], "SB"))
	{
		gaim_debug_error("msn", "This shouldn't be handled here.\n");
	}
	else if (!strcmp(cmd->params[1], "NS"))
	{
		MsnSession *session;

		session = cmdproc->session;

		msn_session_set_login_step(session, MSN_LOGIN_STEP_TRANSFER);

		msn_notification_connect(session->notification, host, port);
	}

	g_free(host);
}
Exemplo n.º 2
0
gboolean gaym_unreference_channel_member(struct gaym_conn * gaym,
                                         gchar * name)
{

    GaymBuddy *channel_member;
    channel_member =
        (GaymBuddy *) g_hash_table_lookup(gaym->channel_members, gaim_normalize(gaym->account,name));
    if (!channel_member)
        return FALSE;
    else {

        if (channel_member->ref_count <= 0)
            gaim_debug_error("gaym",
                             "****Reference counting error with channel members struct.\n");

        channel_member->ref_count--;

        if (channel_member->ref_count == 0) {
            gaim_debug_misc("gaym", "Removing %s from channel_members\n",
                            name);
            return g_hash_table_remove(gaym->channel_members, gaim_normalize(gaym->account, name));
        }
        return FALSE;
    }
}
Exemplo n.º 3
0
void gaym_update_channel_member(struct gaym_conn *gaym, const char *nick,
                                const char *info)
{
    GaymBuddy *cm = gaym_get_channel_member_reference(gaym, nick);
    if (!cm) {
        gaim_debug_error("gaym",
                         "ERROR: A member has joined a channel, or a conversation was opened, but we were unable to add the member to the internal management structure. Report a bug.");
        return;
    } else {
        gchar *stats = gaym_stats_strdup(info);
        if (stats) {
            gchar **s = g_strsplit(stats, "|", 3);
            if (s[0] && strlen(g_strstrip(s[0])) > 0) {
                cm->sex = g_ascii_strup(s[0], -1);
            }
            if (s[1] && strlen(g_strstrip(s[1])) > 0) {
                cm->age = g_strdup(s[1]);
            }
            if (s[2] && strlen(g_strstrip(s[2])) > 0) {
                cm->location = g_strdup(s[2]);
            }
            g_strfreev(s);
            g_free(stats);
        }
        cm->name = g_strdup(nick);
        cm->bio = gaym_bio_strdup(info);
        cm->thumbnail = gaym_thumbnail_strdup(info);

    }
}
Exemplo n.º 4
0
void yahoo_packet_hash(struct yahoo_packet *pkt, const char *fmt, ...)
{
	char *strval;
	int key, intval;
	const char *cur;
	va_list ap;

	va_start(ap, fmt);
	for (cur = fmt; *cur; cur++) {
		key = va_arg(ap, int);
		switch (*cur) {
		case 'i':
			intval = va_arg(ap, int);
			yahoo_packet_hash_int(pkt, key, intval);
			break;
		case 's':
			strval = va_arg(ap, char *);
			yahoo_packet_hash_str(pkt, key, strval);
			break;
		default:
			gaim_debug_error("yahoo", "Invalid format character '%c'\n", *cur);
			break;
		}
	}
	va_end(ap);
}
Exemplo n.º 5
0
Arquivo: status.c Projeto: VoxOx/VoxOx
void
gaim_status_set_attr_string(GaimStatus *status, const char *id,
		const char *value)
{
	GaimValue *attr_value;

	g_return_if_fail(status != NULL);
	g_return_if_fail(id     != NULL);

	/* Make sure this attribute exists and is the correct type. */
	attr_value = gaim_status_get_attr_value(status, id);
	/* This used to be g_return_if_fail, but it's failing a LOT, so
	 * let's generate a log error for now. */
	/* g_return_if_fail(attr_value != NULL); */
	if (attr_value == NULL) {
		gaim_debug_error("status",
				 "Attempted to set status attribute '%s' for "
				 "status '%s', which is not legal.  Fix "
                                 "this!\n", id,
				 gaim_status_type_get_name(gaim_status_get_type(status)));
		return;
	}
	g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_STRING);

	gaim_value_set_string(attr_value, value);
}
Exemplo n.º 6
0
static void
connect_cb(gpointer data, gint source, const gchar *error_message)
{
	MsnDirectConn* directconn;
	int fd;

	gaim_debug_misc("msn", "directconn: connect_cb: %d\n", source);

	directconn = data;
	directconn->connect_data = NULL;

	if (TRUE)
	{
		fd = source;
	}
	else
	{
		struct sockaddr_in client_addr;
		unsigned int client;
		fd = accept (source, (struct sockaddr *)&client_addr, &client);
	}

	directconn->fd = fd;

	if (fd > 0)
	{
		directconn->inpa = gaim_input_add(fd, GAIM_INPUT_READ, read_cb,
										  directconn);

		if (TRUE)
		{
			/* Send foo. */
			msn_directconn_write(directconn, "foo", strlen("foo") + 1);

			/* Send Handshake */
			msn_directconn_send_handshake(directconn);
		}
		else
		{
		}
	}
	else
	{
		/* ERROR */
		gaim_debug_error("msn", "could not add input\n");

		if (directconn->inpa)
			gaim_input_remove(directconn->inpa);

		close(directconn->fd);
	}
}
Exemplo n.º 7
0
void gaym_fetch_thumbnail_cb(void *user_data, const char *pic_data,
                             size_t len)
{
    if (!user_data)
        return;
    struct gaym_fetch_thumbnail_data *d = user_data;
    if (!pic_data) {
        return;
    }

    if (len && !g_strrstr_len(pic_data, len, "Server Error")) {
        char *dir =
            g_build_filename(gaim_user_dir(), "icons", "gaym", d->who,
                             NULL);
        char *filename = g_strdup(d->filename);
        char *path = g_build_filename(dir, filename, NULL);
        gaim_debug_misc("gayminfo", "dir: %s\n", dir);
        gaim_debug_misc("gayminfo", "filename: %s\n", filename);
        gaim_debug_misc("gayminfo", "path: %s\n", path);
        if (!g_file_test(dir, G_FILE_TEST_EXISTS))
            gaim_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR);

        if (path && !g_file_test(path, G_FILE_TEST_EXISTS)) {
            FILE *file;
            if ((file = g_fopen(path, "wb"))) {
                fwrite(pic_data, 1, len, file);
                fclose(file);
            } else {
                gaim_debug_misc("fetch_thumbnail_cb",
                                "Couldn't write file\n");
            }
            g_free(filename);
            g_free(path);
            g_free(dir);
        }
    }
    if (GAIM_CONNECTION_IS_VALID(d->gc) && len) {
        gaim_signal_emit(gaim_accounts_get_handle(), "info-updated",
                         d->gc, NULL, d->who);
        if (gaim_find_conversation_with_account(d->who, d->gc->account)) {
            //gaim_buddy_icons_set_for_user(gaim_connection_get_account
            //                              (d->gc), d->who,
            //                              (void *) pic_data, len);
        }

    } else {
        gaim_debug_error("gaym", "Fetching buddy icon failed.\n");
    }

    g_free(d->who);
    g_free(d);
}
Exemplo n.º 8
0
void gaym_fetch_thumbnail_cb(GaimUtilFetchUrlData *url_data, void *user_data, const gchar *pic_data,
                             gsize len, const gchar* error_message)
{
    if (!user_data)
        return;
    struct gaym_fetch_thumbnail_data *d = user_data;
    if (!pic_data) {
        return;
    }
     
    if (!d->gc)
	return;
    if (len && !g_strrstr_len(pic_data, len, "Server Error")) {
	gaim_debug_misc("gaym","Setting buddy icon for %s\n",d->who);
	if(len<1024) {
	    void* new_pic_data=NULL;
	    gaim_debug_misc("gaym","Short icon file, padding to 1024\n");
	    new_pic_data=g_malloc0(1024);
	    memcpy(new_pic_data, pic_data, len);
	    len=1024;
	    gaim_buddy_icon_new(d->gc->account, d->who, (void*)new_pic_data, len);
	    g_free(new_pic_data);
	}
	else {
	    gaim_buddy_icon_new(d->gc->account, d->who, (void*)pic_data, len);
	}
	//GaimBuddyIcon *icon=gaim_buddy_icons_find(d->gc->account,d->who);
	//guint len;
	//const guchar* data=gaim_buddy_icon_get_data(icon, &len);
    }
    if (GAIM_CONNECTION_IS_VALID(d->gc) && len) {
        gaim_signal_emit(gaim_accounts_get_handle(), "info-updated",
                         d->gc->account, d->who);
      /*  if (gaim_find_conversation_with_account(d->who, d->gc->account)) {
	    
	    gaim_debug_misc("fetch_thumbnail_cb","setting buddy icon\n");
            gaim_buddy_icons_set_for_user(gaim_connection_get_account
             (d->gc), d->who,
             (void *) pic_data, len);
        }*/

    } else {
        gaim_debug_error("gaym", "Fetching buddy icon failed.\n");
    }

    g_free(d->who);
    g_free(d);
}
Exemplo n.º 9
0
static GaimConversation *
msn_switchboard_get_conv(MsnSwitchBoard *swboard)
{
	GaimAccount *account;

	g_return_val_if_fail(swboard != NULL, NULL);

	if (swboard->conv != NULL)
		return swboard->conv;

	gaim_debug_error("msn", "Switchboard with unassigned conversation\n");

	account = swboard->session->account;

	return (swboard->conv = gaim_conversation_new(GAIM_CONV_TYPE_IM,
												  account, swboard->im_user));
}
Exemplo n.º 10
0
void
msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error)
{
	char *tmp;
	const char *reason;

	const char *names[] = { "Notification", "Switchboard" };
	const char *name;

	name = names[servconn->type];

	switch (error)
	{
		case MSN_SERVCONN_ERROR_CONNECT:
			reason = _("Unable to connect"); break;
		case MSN_SERVCONN_ERROR_WRITE:
			reason = _("Writing error"); break;
		case MSN_SERVCONN_ERROR_READ:
			reason = _("Reading error"); break;
		default:
			reason = _("Unknown error"); break;
	}

	gaim_debug_error("msn", "Connection error from %s server (%s): %s\n",
					 name, servconn->host, reason);
	tmp = g_strdup_printf(_("Connection error from %s server:\n%s"),
						  name, reason);

	if (servconn->type == MSN_SERVCONN_NS)
	{
		msn_session_set_error(servconn->session, MSN_ERROR_SERVCONN, tmp);
	}
	else if (servconn->type == MSN_SERVCONN_SB)
	{
		MsnSwitchBoard *swboard;
		swboard = servconn->cmdproc->data;
		if (swboard != NULL)
			swboard->error = MSN_SB_ERROR_CONNECTION;
	}

	msn_servconn_disconnect(servconn);

	g_free(tmp);
}
Exemplo n.º 11
0
Arquivo: dnssrv.c Projeto: VoxOx/VoxOx
static gboolean
res_main_thread_cb(gpointer data)
{
	GaimSrvResponse *srvres = NULL;
	int size = 0;
	GaimSrvQueryData *query_data = data;

	if(query_data->error_message != NULL)
		gaim_debug_error("dnssrv", query_data->error_message);
	else {
		GaimSrvResponse *srvres_tmp = NULL;
		GSList *lst = query_data->results;

		size = g_slist_length(query_data->results);

		if(query_data->cb)
			srvres_tmp = srvres = g_new0(GaimSrvResponse, size);
		while (lst) {
			if(query_data->cb)
				memcpy(srvres_tmp++, lst->data, sizeof(GaimSrvResponse));
			g_free(lst->data);
			lst = g_slist_remove(lst, lst->data);
		}

		query_data->results = NULL;
	}

	gaim_debug_info("dnssrv", "found %d SRV entries\n", size);

	if(query_data->cb)
		query_data->cb(srvres, size, query_data->extradata);

	query_data->resolver = NULL;
	query_data->handle = 0;

	gaim_srv_cancel(query_data);

	return FALSE;
}
Exemplo n.º 12
0
static void
bye_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
{
	MsnSwitchBoard *swboard;
	const char *user;

	swboard = cmdproc->data;
	user = cmd->params[0];

	/* cmdproc->data is set to NULL when the switchboard is destroyed;
	 * we may get a bye shortly thereafter. */
	g_return_if_fail(swboard != NULL);

	if (!(swboard->flag & MSN_SB_FLAG_IM) && (swboard->conv != NULL))
		gaim_debug_error("msn_switchboard", "bye_cmd: helper bug\n");

	if (swboard->conv == NULL)
	{
		/* This is a helper switchboard */
		msn_switchboard_destroy(swboard);
	}
	else if ((swboard->current_users > 1) ||
			 (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT))
	{
		/* This is a switchboard used for a chat */
		gaim_conv_chat_remove_user(GAIM_CONV_CHAT(swboard->conv), user, NULL);
		swboard->current_users--;
		if (swboard->current_users == 0)
			msn_switchboard_destroy(swboard);
	}
	else
	{
		/* This is a switchboard used for a im session */
		msn_switchboard_destroy(swboard);
	}
}
Exemplo n.º 13
0
static void
read_cb(gpointer data, gint source, GaimInputCondition cond)
{
	MsnDirectConn* directconn;
	char *body;
	size_t len, body_len;

	gaim_debug_info("msn", "read_cb: %d, %d\n", source, cond);

	directconn = data;

	/* Let's read the length of the data. */
	len = read(directconn->fd, &body_len, sizeof(body_len));

	if (len <= 0)
	{
		/* ERROR */
		gaim_debug_error("msn", "error reading\n");

		msn_directconn_destroy(directconn);

		return;
	}

	body_len = GUINT32_FROM_LE(body_len);

	gaim_debug_info("msn", "body_len=%d\n", body_len);

	if (body_len <= 0)
	{
		/* ERROR */
		gaim_debug_error("msn", "error reading\n");

		msn_directconn_destroy(directconn);

		return;
	}

	body = g_try_malloc(body_len);

	if (body != NULL)
	{
		/* Let's read the data. */
		len = read(directconn->fd, body, body_len);

		gaim_debug_info("msn", "len=%d\n", len);
	}
	else
	{
		gaim_debug_error("msn", "Failed to allocate memory for read\n");
		len = 0;
	}

	if (len > 0)
	{
		MsnMessage *msg;

#ifdef DEBUG_DC
		str = g_strdup_printf("/home/revo/msntest/r%.4d.bin", directconn->c);

		FILE *tf = g_fopen(str, "w");
		fwrite(body, 1, len, tf);
		fclose(tf);

		g_free(str);
#endif

		directconn->c++;

		msg = msn_message_new_msnslp();
		msn_message_parse_slp_body(msg, body, body_len);

		msn_directconn_process_msg(directconn, msg);
	}
	else
	{
		/* ERROR */
		gaim_debug_error("msn", "error reading\n");

		msn_directconn_destroy(directconn);
	}
}
Exemplo n.º 14
0
Arquivo: dnssrv.c Projeto: VoxOx/VoxOx
GaimSrvQueryData *
gaim_srv_resolve(const char *protocol, const char *transport, const char *domain, GaimSrvCallback cb, gpointer extradata)
{
	char *query;
	GaimSrvQueryData *query_data;
#ifndef _WIN32
	int in[2], out[2];
	int pid;
#else
	GError* err = NULL;
	static gboolean initialized = FALSE;
#endif

	query = g_strdup_printf("_%s._%s.%s", protocol, transport, domain);
	gaim_debug_info("dnssrv","querying SRV record for %s\n", query);

#ifndef _WIN32
	if(pipe(in) || pipe(out)) {
		gaim_debug_error("dnssrv", "Could not create pipe\n");
		g_free(query);
		cb(NULL, 0, extradata);
		return NULL;
	}

	pid = fork();
	if (pid == -1) {
		gaim_debug_error("dnssrv", "Could not create process!\n");
		cb(NULL, 0, extradata);
		g_free(query);
		return NULL;
	}

	/* Child */
	if (pid == 0)
	{
		close(out[0]);
		close(in[1]);
		resolve(in[0], out[1]);
	}

	close(out[1]);
	close(in[0]);

	if (write(in[1], query, strlen(query)+1) < 0)
		gaim_debug_error("dnssrv", "Could not write to SRV resolver\n");

	query_data = g_new0(GaimSrvQueryData, 1);
	query_data->cb = cb;
	query_data->extradata = extradata;
	query_data->handle = gaim_input_add(out[0], GAIM_INPUT_READ, resolved, query_data);

	g_free(query);

	return query_data;
#else
	if (!initialized) {
		MyDnsQuery_UTF8 = (void*) wgaim_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8");
		MyDnsRecordListFree = (void*) wgaim_find_and_loadproc(
			"dnsapi.dll", "DnsRecordListFree");
		initialized = TRUE;
	}

	query_data = g_new0(GaimSrvQueryData, 1);
	query_data->cb = cb;
	query_data->query = query;
	query_data->extradata = extradata;

	if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree) {
		query_data->error_message = g_strdup_printf("System missing DNS API (Requires W2K+)\n");

		/* Asynchronously call the callback since stuff may not expect
		 * the callback to be called before this returns */
		query_data->handle = g_idle_add(res_main_thread_cb, query_data);

		return query_data;
	}

	query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err);
	if (query_data->resolver == NULL)
	{
		query_data->error_message = g_strdup_printf("SRV thread create failure: %s\n", err ? err->message : "");
		g_error_free(err);

		/* Asynchronously call the callback since stuff may not expect
		 * the callback to be called before this returns */
		query_data->handle = g_idle_add(res_main_thread_cb, query_data);

		return query_data;
	}

	return query_data;
#endif
}
Exemplo n.º 15
0
static void
url_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
{
	MsnSession *session;
	GaimAccount *account;
	const char *rru;
	const char *url;
	GaimCipher *cipher;
	GaimCipherContext *context;
	guchar digest[16];
	FILE *fd;
	char *buf;
	char buf2[3];
	char sendbuf[64];
	int i;

	session = cmdproc->session;
	account = session->account;

	rru = cmd->params[1];
	url = cmd->params[2];

	buf = g_strdup_printf("%s%lu%s",
			   session->passport_info.mspauth,
			   time(NULL) - session->passport_info.sl,
			   gaim_connection_get_password(account->gc));

	cipher = gaim_ciphers_find_cipher("md5");
	context = gaim_cipher_context_new(cipher, NULL);

	gaim_cipher_context_append(context, (const guchar *)buf, strlen(buf));
	gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
	gaim_cipher_context_destroy(context);

	g_free(buf);

	memset(sendbuf, 0, sizeof(sendbuf));

	for (i = 0; i < 16; i++)
	{
		g_snprintf(buf2, sizeof(buf2), "%02x", digest[i]);
		strcat(sendbuf, buf2);
	}

	if (session->passport_info.file != NULL)
	{
		g_unlink(session->passport_info.file);
		g_free(session->passport_info.file);
	}

	if ((fd = gaim_mkstemp(&session->passport_info.file, FALSE)) == NULL)
	{
		gaim_debug_error("msn",
						 "Error opening temp passport file: %s\n",
						 strerror(errno));
	}
	else
	{
		fputs("<html>\n"
			  "<head>\n"
			  "<noscript>\n"
			  "<meta http-equiv=\"Refresh\" content=\"0; "
			  "url=http://www.hotmail.com\">\n"
			  "</noscript>\n"
			  "</head>\n\n",
			  fd);

		fprintf(fd, "<body onload=\"document.pform.submit(); \">\n");
		fprintf(fd, "<form name=\"pform\" action=\"%s\" method=\"POST\">\n\n",
				url);
		fprintf(fd, "<input type=\"hidden\" name=\"mode\" value=\"ttl\">\n");
		fprintf(fd, "<input type=\"hidden\" name=\"login\" value=\"%s\">\n",
				gaim_account_get_username(account));
		fprintf(fd, "<input type=\"hidden\" name=\"username\" value=\"%s\">\n",
				gaim_account_get_username(account));
		if (session->passport_info.sid != NULL)
			fprintf(fd, "<input type=\"hidden\" name=\"sid\" value=\"%s\">\n",
					session->passport_info.sid);
		if (session->passport_info.kv != NULL)
			fprintf(fd, "<input type=\"hidden\" name=\"kv\" value=\"%s\">\n",
					session->passport_info.kv);
		fprintf(fd, "<input type=\"hidden\" name=\"id\" value=\"2\">\n");
		fprintf(fd, "<input type=\"hidden\" name=\"sl\" value=\"%ld\">\n",
				time(NULL) - session->passport_info.sl);
		fprintf(fd, "<input type=\"hidden\" name=\"rru\" value=\"%s\">\n",
				rru);
		if (session->passport_info.mspauth != NULL)
			fprintf(fd, "<input type=\"hidden\" name=\"auth\" value=\"%s\">\n",
					session->passport_info.mspauth);
		fprintf(fd, "<input type=\"hidden\" name=\"creds\" value=\"%s\">\n",
				sendbuf); /* TODO Digest me (huh? -- ChipX86) */
		fprintf(fd, "<input type=\"hidden\" name=\"svc\" value=\"mail\">\n");
		fprintf(fd, "<input type=\"hidden\" name=\"js\" value=\"yes\">\n");
		fprintf(fd, "</form></body>\n");
		fprintf(fd, "</html>\n");

		if (fclose(fd))
		{
			gaim_debug_error("msn",
							 "Error closing temp passport file: %s\n",
							 strerror(errno));

			g_unlink(session->passport_info.file);
			g_free(session->passport_info.file);
			session->passport_info.file = NULL;
		}
#ifdef _WIN32
		else
		{
			/*
			 * Renaming file with .html extension, so that the
			 * win32 open_url will work.
			 */
			char *tmp;

			if ((tmp =
				g_strdup_printf("%s.html",
					session->passport_info.file)) != NULL)
			{
				if (g_rename(session->passport_info.file,
							tmp) == 0)
				{
					g_free(session->passport_info.file);
					session->passport_info.file = tmp;
				}
				else
					g_free(tmp);
			}
		}
#endif
	}
}
Exemplo n.º 16
0
static void
msn_switchboard_add_user(MsnSwitchBoard *swboard, const char *user)
{
	MsnCmdProc *cmdproc;
	GaimAccount *account;

	g_return_if_fail(swboard != NULL);

	cmdproc = swboard->cmdproc;
	account = cmdproc->session->account;

	swboard->users = g_list_prepend(swboard->users, g_strdup(user));
	swboard->current_users++;
	swboard->empty = FALSE;

#ifdef MSN_DEBUG_CHAT
	gaim_debug_info("msn", "user=[%s], total=%d\n", user,
					swboard->current_users);
#endif

	if (!(swboard->flag & MSN_SB_FLAG_IM) && (swboard->conv != NULL))
	{
		/* This is a helper switchboard. */
		gaim_debug_error("msn", "switchboard_add_user: conv != NULL\n");
		return;
	}

	if ((swboard->conv != NULL) &&
		(gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT))
	{
		gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), user, NULL,
								GAIM_CBFLAGS_NONE, TRUE);
	}
	else if (swboard->current_users > 1 || swboard->total_users > 1)
	{
		if (swboard->conv == NULL ||
			gaim_conversation_get_type(swboard->conv) != GAIM_CONV_TYPE_CHAT)
		{
			GList *l;

#ifdef MSN_DEBUG_CHAT
			gaim_debug_info("msn", "[chat] Switching to chat.\n");
#endif

#if 0
			/* this is bad - it causes msn_switchboard_close to be called on the
			 * switchboard we're in the middle of using :( */
			if (swboard->conv != NULL)
				gaim_conversation_destroy(swboard->conv);
#endif

			swboard->chat_id = cmdproc->session->conv_seq++;
			swboard->flag |= MSN_SB_FLAG_IM;
			swboard->conv = serv_got_joined_chat(account->gc,
												 swboard->chat_id,
												 "MSN Chat");

			for (l = swboard->users; l != NULL; l = l->next)
			{
				const char *tmp_user;

				tmp_user = l->data;

#ifdef MSN_DEBUG_CHAT
				gaim_debug_info("msn", "[chat] Adding [%s].\n", tmp_user);
#endif

				gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv),
										tmp_user, NULL, GAIM_CBFLAGS_NONE, TRUE);
			}

#ifdef MSN_DEBUG_CHAT
			gaim_debug_info("msn", "[chat] We add ourselves.\n");
#endif

			gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv),
									gaim_account_get_username(account),
									NULL, GAIM_CBFLAGS_NONE, TRUE);

			g_free(swboard->im_user);
			swboard->im_user = NULL;
		}
	}
	else if (swboard->conv == NULL)
	{
		swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
															user, account);
	}
	else
	{
		gaim_debug_warning("msn", "switchboard_add_user: This should not happen!\n");
	}
}
Exemplo n.º 17
0
void
gaim_connection_new(GaimAccount *account, gboolean regist, const char *password)
{
	GaimConnection *gc;
	GaimPlugin *prpl;
	GaimPluginProtocolInfo *prpl_info;

	g_return_if_fail(account != NULL);

	if (!gaim_account_is_disconnected(account))
		return;

	prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));

	if (prpl != NULL)
		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
	else {
		gchar *message;

		message = g_strdup_printf(_("Missing protocol plugin for %s"),
			gaim_account_get_username(account));
		gaim_notify_error(NULL, regist ? _("Registration Error") :
						  _("Connection Error"), message, NULL);
		g_free(message);
		return;
	}

	if (regist)
	{
		if (prpl_info->register_user == NULL)
			return;
	}
	else
	{
		if (((password == NULL) || (*password == '\0')) &&
			!(prpl_info->options & OPT_PROTO_NO_PASSWORD) &&
			!(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL))
		{
			gaim_debug_error("connection", "Can not connect to account %s without "
							 "a password.\n", gaim_account_get_username(account));
			return;
		}
	}

	gc = g_new0(GaimConnection, 1);
	GAIM_DBUS_REGISTER_POINTER(gc, GaimConnection);

	gc->prpl = prpl;
	if ((password != NULL) && (*password != '\0'))
		gc->password = g_strdup(password);
	gaim_connection_set_account(gc, account);
	gaim_connection_set_state(gc, GAIM_CONNECTING);
	connections = g_list_append(connections, gc);
	gaim_account_set_connection(account, gc);

	gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc);

	if (regist)
	{
		gaim_debug_info("connection", "Registering.  gc = %p\n", gc);

		/* set this so we don't auto-reconnect after registering */
		gc->wants_to_die = TRUE;

		prpl_info->register_user(account);
	}
	else
	{
		gaim_debug_info("connection", "Connecting. gc = %p\n", gc);

		gaim_signal_emit(gaim_accounts_get_handle(), "account-connecting", account);
		prpl_info->login(account);
	}
}
Exemplo n.º 18
0
// This is a modified version of gaim's url_fetched_cb function. It has
// been
// modified to pass cookies during requests. The cookies are set in
// user_data,
// cast as a GaimUrlSession item. Any cookies in the response are added to 
// 
// 
// 
// 
// this
// structure, as well.
static void
session_fetched_cb(gpointer url_data, gint sock, GaimInputCondition cond)
{

    GaimFetchUrlData *gfud = url_data;
    char data;
    gboolean got_eof = FALSE;
    if (sock == -1) {
        gfud->callback(gfud->user_data, NULL, 0);

        destroy_fetch_url_data(gfud);

        return;
    }

    if (!gfud->sentreq) {
        char buf[2048];

        if (gfud->session->cookies == NULL)
            gfud->session->cookies = g_strdup("");

        if (gfud->user_agent) {
            /* Host header is not forbidden in HTTP/1.0 requests, and
               HTTP/1.1 clients must know how to handle the "chunked"
               transfer encoding. Gaim doesn't know how to handle
               "chunked", so should always send the Host header
               regardless, to get around some observed problems */
            g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/%s\r\n" "User-Agent: %s\r\n" "Host: %s\r\n" "Cookie: %s\r\n",   // (1) 
                                                                                                                        // 
                       // 
                       // 
                       // 
                       // (see 
                       // above)
                       (gfud->full ? "" : "/"),
                       (gfud->full ? gfud->url : gfud->website.page),
                       (gfud->http11 ? "1.1" : "1.0"),
                       gfud->user_agent, gfud->website.address,
                       gfud->session->cookies);
        } else {
            g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/%s\r\n" "Host: %s\r\n" "Accept-Encoding: identity\r\n" "Cookie: %s\r\n",        // (1) 
                                                                                                                                        // 
                       // 
                       // 
                       // 
                       // See 
                       // above
                       (gfud->full ? "" : "/"),
                       (gfud->full ? gfud->url : gfud->website.page),
                       (gfud->http11 ? "1.1" : "1.0"),
                       gfud->website.address, gfud->session->cookies);
        }
        if (gfud->session->hasFormData)
            strcat(buf,
                   "Content-Type: application/x-www-form-urlencoded\r\n\r\n");
        else
            strcat(buf, "\r\n");
        gaim_debug_misc("gaim_url_fetch", "Request: %s\n", buf);

        write(sock, buf, strlen(buf));
        fcntl(sock, F_SETFL, O_NONBLOCK);
        gfud->sentreq = TRUE;
        gfud->inpa = gaim_input_add(sock, GAIM_INPUT_READ,
                                    session_fetched_cb, url_data);
        gfud->data_len = 4096;
        gfud->webdata = g_malloc(gfud->data_len);

        return;
    }

    if (read(sock, &data, 1) > 0 || errno == EWOULDBLOCK) {
        if (errno == EWOULDBLOCK) {
            errno = 0;

            return;
        }

        gfud->len++;

        if (gfud->len == gfud->data_len + 1) {
            gfud->data_len += (gfud->data_len) / 2;

            gfud->webdata = g_realloc(gfud->webdata, gfud->data_len);
        }

        gfud->webdata[gfud->len - 1] = data;

        if (!gfud->startsaving) {
            if (data == '\r')
                return;

            if (data == '\n') {
                if (gfud->newline) {
                    size_t content_len;
                    gfud->startsaving = TRUE;

                    gaim_debug_misc("gaim_url_fetch",
                                    "Response headers: '%*.*s'\n",
                                    gfud->len, gfud->len, gfud->webdata);

                    // JBL 10-16-2004: Put cookies into session
                    gaim_debug(GAIM_DEBUG_MISC, "gaym",
                               "Parsing cookies...");

                    parse_cookies(gfud->webdata, gfud->session, gfud->len);
                    gaim_debug(GAIM_DEBUG_MISC, "gaym",
                               "Found cookies: %s\n",
                               (gfud->session->cookies));
                    gaim_debug_misc("gaim_url_fetch",
                                    "Parsing of cookies successful\n");
                    /* See if we can find a redirect. */
                    if (parse_redirect
                        (gfud->webdata, gfud->len, sock, gfud))
                        return;

                    /* No redirect. See if we can find a content length. */
                    content_len =
                        parse_content_len(gfud->webdata, gfud->len);

                    if (content_len == 0) {
                        /* We'll stick with an initial 8192 */
                        content_len = 8192;
                    } else {
                        gfud->has_explicit_data_len = TRUE;
                    }

                    /* Out with the old... */
                    gfud->len = 0;
                    g_free(gfud->webdata);
                    gfud->webdata = NULL;

                    /* In with the new. */
                    gfud->data_len = content_len;
                    gfud->webdata = g_try_malloc(gfud->data_len);
                    if (gfud->webdata == NULL) {
                        gaim_debug_error("gaim_url_fetch",
                                         "Failed to allocate %u bytes: %s\n",
                                         gfud->data_len, strerror(errno));
                        gaim_input_remove(gfud->inpa);
                        close(sock);
                        gfud->callback(gfud->user_data, NULL, 0);
                        destroy_fetch_url_data(gfud);
                    }
                } else
                    gfud->newline = TRUE;

                return;
            }

            gfud->newline = FALSE;
        } else if (gfud->has_explicit_data_len
                   && gfud->len == gfud->data_len) {
            got_eof = TRUE;
        }
    } else if (errno != ETIMEDOUT) {
        got_eof = TRUE;
    } else {
        gaim_input_remove(gfud->inpa);
        close(sock);

        gfud->callback(gfud->user_data, NULL, 0);

        destroy_fetch_url_data(gfud);
    }

    if (got_eof) {
        gfud->webdata = g_realloc(gfud->webdata, gfud->len + 1);
        gfud->webdata[gfud->len] = 0;

        /* gaim_debug_misc("gaim_url_fetch", "Received: '%s'\n",
           gfud->webdata); */

        gaim_input_remove(gfud->inpa);
        close(sock);
        gfud->callback(gfud->user_data, gfud->webdata, gfud->len);

        destroy_fetch_url_data(gfud);
    }
}
Exemplo n.º 19
0
static int
create_listener(int port)
{
	int fd;
	const int on = 1;

#if 0
	struct addrinfo hints;
	struct addrinfo *c, *res;
	char port_str[5];

	snprintf(port_str, sizeof(port_str), "%d", port);

	memset(&hints, 0, sizeof(hints));

	hints.ai_flags = AI_PASSIVE;
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;

	if (getaddrinfo(NULL, port_str, &hints, &res) != 0)
	{
		gaim_debug_error("msn", "Could not get address info: %s.\n",
						 port_str);
		return -1;
	}

	for (c = res; c != NULL; c = c->ai_next)
	{
		fd = socket(c->ai_family, c->ai_socktype, c->ai_protocol);

		if (fd < 0)
			continue;

		setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));

		if (bind(fd, c->ai_addr, c->ai_addrlen) == 0)
			break;

		close(fd);
	}

	if (c == NULL)
	{
		gaim_debug_error("msn", "Could not find socket: %s.\n", port_str);
		return -1;
	}

	freeaddrinfo(res);
#else
	struct sockaddr_in sockin;

	fd = socket(AF_INET, SOCK_STREAM, 0);

	if (fd < 0)
		return -1;

	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) != 0)
	{
		close(fd);
		return -1;
	}

	memset(&sockin, 0, sizeof(struct sockaddr_in));
	sockin.sin_family = AF_INET;
	sockin.sin_port = htons(port);

	if (bind(fd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0)
	{
		close(fd);
		return -1;
	}
#endif

	if (listen (fd, 4) != 0)
	{
		close (fd);
		return -1;
	}

	fcntl(fd, F_SETFL, O_NONBLOCK);

	return fd;
}
Exemplo n.º 20
0
static void
read_cb(gpointer data, gint source, GaimInputCondition cond)
{
	MsnServConn *servconn;
	MsnSession *session;
	char buf[MSN_BUF_LEN];
	char *cur, *end, *old_rx_buf;
	int len, cur_len;

	servconn = data;
	session = servconn->session;

	len = read(servconn->fd, buf, sizeof(buf) - 1);

	if (len < 0 && errno == EAGAIN)
		return;
	else if (len <= 0)
	{
		gaim_debug_error("msn", "servconn read error, len: %d error: %s\n", len, strerror(errno));
		msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ);

		return;
	}

	buf[len] = '\0';

	servconn->rx_buf = g_realloc(servconn->rx_buf, len + servconn->rx_len + 1);
	memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1);
	servconn->rx_len += len;

	end = old_rx_buf = servconn->rx_buf;

	servconn->processing = TRUE;

	do
	{
		cur = end;

		if (servconn->payload_len)
		{
			if (servconn->payload_len > servconn->rx_len)
				/* The payload is still not complete. */
				break;

			cur_len = servconn->payload_len;
			end += cur_len;
		}
		else
		{
			end = strstr(cur, "\r\n");

			if (end == NULL)
				/* The command is still not complete. */
				break;

			*end = '\0';
			end += 2;
			cur_len = end - cur;
		}

		servconn->rx_len -= cur_len;

		if (servconn->payload_len)
		{
			msn_cmdproc_process_payload(servconn->cmdproc, cur, cur_len);
			servconn->payload_len = 0;
		}
		else
		{
			msn_cmdproc_process_cmd_text(servconn->cmdproc, cur);
		}
	} while (servconn->connected && !servconn->wasted && servconn->rx_len > 0);

	if (servconn->connected && !servconn->wasted)
	{
		if (servconn->rx_len > 0)
			servconn->rx_buf = g_memdup(cur, servconn->rx_len);
		else
			servconn->rx_buf = NULL;
	}

	servconn->processing = FALSE;

	if (servconn->wasted)
		msn_servconn_destroy(servconn);

	g_free(old_rx_buf);
}
Exemplo n.º 21
0
Arquivo: si.c Projeto: VoxOx/VoxOx
static void
jabber_si_xfer_bytestreams_send_read_again_cb(gpointer data, gint source,
		GaimInputCondition cond)
{
	GaimXfer *xfer = data;
	JabberSIXfer *jsx = xfer->data;
	int i;
	char buffer[256];
	int len;
	char *dstaddr, *p;
	unsigned char hashval[20];
	const char *host;

	gaim_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_again_cb\n");

	if(jsx->rxlen < 5) {
		gaim_debug_info("jabber", "reading the first 5 bytes\n");
		len = read(source, buffer, 5 - jsx->rxlen);
		if(len < 0 && errno == EAGAIN)
			return;
		else if(len <= 0) {
			gaim_input_remove(xfer->watcher);
			xfer->watcher = 0;
			close(source);
			gaim_xfer_cancel_remote(xfer);
			return;
		}
		jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen);
		memcpy(jsx->rxqueue + jsx->rxlen, buffer, len);
		jsx->rxlen += len;
		return;
	} else if(jsx->rxqueue[0] != 0x05 || jsx->rxqueue[1] != 0x01 ||
			jsx->rxqueue[3] != 0x03) {
		gaim_debug_info("jabber", "invalid socks5 stuff\n");
		gaim_input_remove(xfer->watcher);
		xfer->watcher = 0;
		close(source);
		gaim_xfer_cancel_remote(xfer);
		return;
	} else if(jsx->rxlen - 5 <  jsx->rxqueue[4] + 2) {
		gaim_debug_info("jabber", "reading umpteen more bytes\n");
		len = read(source, buffer, jsx->rxqueue[4] + 5 + 2 - jsx->rxlen);
		if(len < 0 && errno == EAGAIN)
			return;
		else if(len <= 0) {
			gaim_input_remove(xfer->watcher);
			xfer->watcher = 0;
			close(source);
			gaim_xfer_cancel_remote(xfer);
			return;
		}
		jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen);
		memcpy(jsx->rxqueue + jsx->rxlen, buffer, len);
		jsx->rxlen += len;
	}

	if(jsx->rxlen - 5 < jsx->rxqueue[4] + 2)
		return;

	gaim_input_remove(xfer->watcher);
	xfer->watcher = 0;

	dstaddr = g_strdup_printf("%s%s@%s/%s%s", jsx->stream_id,
			jsx->js->user->node, jsx->js->user->domain,
			jsx->js->user->resource, xfer->who);

	gaim_cipher_digest_region("sha1", (guchar *)dstaddr, strlen(dstaddr),
							  sizeof(hashval), hashval, NULL);
	g_free(dstaddr);
	dstaddr = g_malloc(41);
	p = dstaddr;
	for(i=0; i<20; i++, p+=2)
		snprintf(p, 3, "%02x", hashval[i]);

	if(jsx->rxqueue[4] != 40 || strncmp(dstaddr, jsx->rxqueue+5, 40) ||
			jsx->rxqueue[45] != 0x00 || jsx->rxqueue[46] != 0x00) {
		gaim_debug_error("jabber", "someone connected with the wrong info!\n");
		close(source);
		gaim_xfer_cancel_remote(xfer);
		return;
	}

	g_free(jsx->rxqueue);
	host = gaim_network_get_my_ip(jsx->js->fd);

	jsx->rxmaxlen = 5 + strlen(host) + 2;
	jsx->rxqueue = g_malloc(jsx->rxmaxlen);
	jsx->rxlen = 0;

	jsx->rxqueue[0] = 0x05;
	jsx->rxqueue[1] = 0x00;
	jsx->rxqueue[2] = 0x00;
	jsx->rxqueue[3] = 0x03;
	jsx->rxqueue[4] = strlen(host);
	memcpy(jsx->rxqueue + 5, host, strlen(host));
	jsx->rxqueue[5+strlen(host)] = 0x00;
	jsx->rxqueue[6+strlen(host)] = 0x00;

	xfer->watcher = gaim_input_add(source, GAIM_INPUT_WRITE,
		jabber_si_xfer_bytestreams_send_read_again_resp_cb, xfer);
	jabber_si_xfer_bytestreams_send_read_again_resp_cb(xfer, source,
		GAIM_INPUT_WRITE);
}
Exemplo n.º 22
0
void
msn_user_set_buddy_icon(MsnUser *user, const char *filename)
{
	struct stat st;
	FILE *fp;
	MsnObject *msnobj = msn_user_get_object(user);

	g_return_if_fail(user != NULL);

	if (filename == NULL || g_stat(filename, &st) == -1)
	{
		msn_user_set_object(user, NULL);
	}
	else if ((fp = g_fopen(filename, "rb")) != NULL)
	{
		unsigned char *buf;
		SHA_CTX ctx;
		gsize len;
		char *base64;
		unsigned char digest[20];

		if (msnobj == NULL)
		{
			msnobj = msn_object_new(TRUE);
			msn_object_set_local(msnobj);
			msn_object_set_type(msnobj, MSN_OBJECT_USERTILE);
			msn_object_set_location(msnobj, "TFR2C2.tmp");
			msn_object_set_creator(msnobj, msn_user_get_passport(user));

			msn_user_set_object(user, msnobj);
		}

		msn_object_set_real_location(msnobj, filename);

		buf = g_malloc(st.st_size);
		len = fread(buf, 1, st.st_size, fp);

		fclose(fp);

		/* Compute the SHA1D field. */
		memset(digest, 0, sizeof(digest));

		shaInit(&ctx);
		shaUpdate(&ctx, buf, st.st_size);
		shaFinal(&ctx, digest);
		g_free(buf);

		base64 = gaim_base64_encode(digest, sizeof(digest));
		msn_object_set_sha1d(msnobj, base64);
		g_free(base64);

		msn_object_set_size(msnobj, st.st_size);

		/* Compute the SHA1C field. */
		buf = g_strdup_printf(
			"Creator%sSize%dType%dLocation%sFriendly%sSHA1D%s",
			msn_object_get_creator(msnobj),
			msn_object_get_size(msnobj),
			msn_object_get_type(msnobj),
			msn_object_get_location(msnobj),
			msn_object_get_friendly(msnobj),
			msn_object_get_sha1d(msnobj));

		memset(digest, 0, sizeof(digest));

		shaInit(&ctx);
		shaUpdate(&ctx, buf, strlen(buf));
		shaFinal(&ctx, digest);
		g_free(buf);

		base64 = gaim_base64_encode(digest, sizeof(digest));
		msn_object_set_sha1c(msnobj, base64);
		g_free(base64);
	}
	else
	{
		gaim_debug_error("msn", "Unable to open buddy icon %s!\n", filename);
		msn_user_set_object(user, NULL);
	}
}
Exemplo n.º 23
0
Arquivo: status.c Projeto: VoxOx/VoxOx
void
gaim_status_set_active_with_attrs_list(GaimStatus *status, gboolean active,
									   const GList *attrs)
{
	gboolean changed = FALSE;
	const GList *l;
	GList *specified_attr_ids = NULL;
	GaimStatusType *status_type;

	g_return_if_fail(status != NULL);

	if (!active && gaim_status_is_exclusive(status))
	{
		gaim_debug_error("status",
				   "Cannot deactivate an exclusive status (%s).\n",
				   gaim_status_get_id(status));
		return;
	}

	if (status->active != active)
	{
		changed = TRUE;
	}

	status->active = active;

	/* Set any attributes */
	l = attrs;
	while (l != NULL)
	{
		const gchar *id;
		GaimValue *value;

		id = l->data;
		l = l->next;
		value = gaim_status_get_attr_value(status, id);
		if (value == NULL)
		{
			gaim_debug_warning("status", "The attribute \"%s\" on the status \"%s\" is "
							   "not supported.\n", id, status->type->name);
			/* Skip over the data and move on to the next attribute */
			l = l->next;
			continue;
		}

		specified_attr_ids = g_list_prepend(specified_attr_ids, (gpointer)id);

		if (value->type == GAIM_TYPE_STRING)
		{
			const gchar *string_data = l->data;
			l = l->next;
			if (((string_data == NULL) && (value->data.string_data == NULL)) ||
				((string_data != NULL) && (value->data.string_data != NULL) &&
				!strcmp(string_data, value->data.string_data)))
			{
				continue;
			}
			gaim_status_set_attr_string(status, id, string_data);
			changed = TRUE;
		}
		else if (value->type == GAIM_TYPE_INT)
		{
			int int_data = GPOINTER_TO_INT(l->data);
			l = l->next;
			if (int_data == value->data.int_data)
				continue;
			gaim_status_set_attr_int(status, id, int_data);
			changed = TRUE;
		}
		else if (value->type == GAIM_TYPE_BOOLEAN)
		{
			gboolean boolean_data = GPOINTER_TO_INT(l->data);
			l = l->next;
			if (boolean_data == value->data.boolean_data)
				continue;
			gaim_status_set_attr_boolean(status, id, boolean_data);
			changed = TRUE;
		}
		else
		{
			/* We don't know what the data is--skip over it */
			l = l->next;
		}
	}

	/* Reset any unspecified attributes to their default value */
	status_type = gaim_status_get_type(status);
	l = gaim_status_type_get_attrs(status_type);
	while (l != NULL)
	{
		GaimStatusAttr *attr;

		attr = l->data;
		if (!g_list_find_custom(specified_attr_ids, attr->id, (GCompareFunc)strcmp))
		{
			GaimValue *default_value;
			default_value = gaim_status_attr_get_value(attr);
			if (default_value->type == GAIM_TYPE_STRING)
				gaim_status_set_attr_string(status, attr->id,
						gaim_value_get_string(default_value));
			else if (default_value->type == GAIM_TYPE_INT)
				gaim_status_set_attr_int(status, attr->id,
						gaim_value_get_int(default_value));
			else if (default_value->type == GAIM_TYPE_BOOLEAN)
				gaim_status_set_attr_boolean(status, attr->id,
						gaim_value_get_boolean(default_value));
			changed = TRUE;
		}

		l = l->next;
	}
	g_list_free(specified_attr_ids);

	if (!changed)
		return;
	status_has_changed(status);
}
Exemplo n.º 24
0
void synchronize_deny_list(GaimConnection * gc, GHashTable * confighash)
{
    char *srvdeny = NULL;
    gchar **srvdenylist = NULL;
    GSList *list;
    gint i = 0;
    gboolean needsync = FALSE;

    g_return_if_fail(confighash != NULL);

    srvdeny =
        g_hash_table_lookup(confighash, "connect-list.ignore.members");
    if (!srvdeny) {
        srvdeny = "";
    }
    srvdenylist = g_strsplit(srvdeny, ",", -1);

    /**
     * The nicks come in here as if they came from the IRC server
     * so they need to be converted to GayM format
     */
    for (i = 0; srvdenylist[i]; i++) {
        gcom_nick_to_gaym(srvdenylist[i]);
    }

    /* Add server deny list from config.txt to local deny list */
    for (i = 0; srvdenylist[i]; i++) {
        needsync = TRUE;
        for (list = gc->account->deny; list != NULL; list = list->next) {
            if (!gaim_utf8_strcasecmp
                (srvdenylist[i],
                 gaim_normalize(gc->account, (char *) list->data))) {
                needsync = FALSE;
                break;
            }
        }
        if (needsync) {
            if (!gaim_privacy_deny_add(gc->account, srvdenylist[i], TRUE)) {
                gaim_debug_error("gaym",
                                 "Failed to add %s to local deny list from server.\n",
                                 srvdenylist[i]);
            } else {
                gaim_debug_misc("gaym",
                                "Added %s to local deny list from server.\n",
                                srvdenylist[i]);
            }
        }
    }

    /* Add local deny list not found in config.txt to server deny list */
    for (list = gc->account->deny; list != NULL; list = list->next) {
        needsync = TRUE;
        for (i = 0; srvdenylist[i]; i++) {
            if (!gaim_utf8_strcasecmp
                (srvdenylist[i],
                 gaim_normalize(gc->account, (char *) list->data))) {
                needsync = FALSE;
                break;
            }
        }
        if (needsync) {
            gaym_server_store_deny(gc, (char *) list->data, TRUE);
        }
    }

    g_strfreev(srvdenylist);
    return;
}
Exemplo n.º 25
0
void
gaim_pounces_sync(void)
{
	FILE *fp;
	struct stat st;
	const char *user_dir = gaim_user_dir();
	char *filename;
	char *filename_real;

	if (!pounces_loaded) {
		gaim_debug(GAIM_DEBUG_WARNING, "pounces",
				   "Writing pounces to disk.\n");
		schedule_pounces_save();
		return;
	}

	if (user_dir == NULL)
		return;

	gaim_debug(GAIM_DEBUG_INFO, "pounces", "Writing pounces to disk.\n");

	fp = g_fopen(user_dir, "r");

	if (fp == NULL)
		g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR);
	else
		fclose(fp);

	filename = g_build_filename(user_dir, "pounces.xml.save", NULL);

	if ((fp = g_fopen(filename, "w")) != NULL) {
		GList *l;

		fprintf(fp, "<?xml version='1.0' encoding='UTF-8' ?>\n\n");
		fprintf(fp, "<pounces version='1.0'>\n");

		for (l = gaim_pounces_get_all(); l != NULL; l = l->next)
			gaim_pounces_write(fp, l->data);

		fprintf(fp, "</pounces>\n");

		fclose(fp);
		chmod(filename, S_IRUSR | S_IWUSR);
	}
	else {
		gaim_debug(GAIM_DEBUG_ERROR, "pounces", "Unable to write %s\n",
				   filename);
		g_free(filename);
		return;
	}

	if (g_stat(filename, &st) || (st.st_size == 0)) {
		gaim_debug_error("pounces", "Failed to save pounces\n");
		g_unlink(filename);
		g_free(filename);
		return;
	}

	filename_real = g_build_filename(user_dir, "pounces.xml", NULL);

	if (g_rename(filename, filename_real) < 0) {
		gaim_debug(GAIM_DEBUG_ERROR, "pounces", "Error renaming %s to %s\n",
				   filename, filename_real);
	}

	g_free(filename);
	g_free(filename_real);
}