static void*
ggp_tcpsocket_connect(void *_gc, const char *host, int port, int is_tls,
	int is_async, void *priv)
{
	PurpleConnection *gc = _gc;
	PurpleSocket *ps;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
	g_return_val_if_fail(!purple_connection_is_disconnecting(gc), NULL);

	g_return_val_if_fail(host != NULL, NULL);
	g_return_val_if_fail(is_async, NULL);

	purple_debug_misc("gg", "ggp_tcpsocket_connect(%p, %s:%d, %s, %p)",
		gc, host, port, is_tls ? "tls" : "tcp", priv);

	ps = purple_socket_new(gc);
	purple_socket_set_tls(ps, is_tls);
	purple_socket_set_host(ps, host);
	purple_socket_set_port(ps, port);
	if (!purple_socket_connect(ps, ggp_tcpsocket_connected, priv)) {
		purple_socket_destroy(ps);
		return NULL;
	}

	return ps;
}
Beispiel #2
0
static void ggp_pubdir_search_got_token(PurpleConnection *gc,
	const gchar *token, gpointer _request)
{
	PurpleHttpRequest *req;
	ggp_pubdir_request *request = _request;
	gchar *query;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	if (!token) {
		request->cb(gc, -1, NULL, 0, request->user_data);
		ggp_pubdir_request_free(request);
		return;
	}

	purple_debug_misc("gg", "ggp_pubdir_search_got_token\n");

	query = ggp_pubdir_search_make_query(request->params.search_form);

	req = purple_http_request_new(NULL);
	purple_http_request_set_url_printf(req, "http://api.gadu-gadu.pl%s", query);
	purple_http_request_header_set(req, "Authorization", token);
	purple_http_request(gc, req, ggp_pubdir_got_data, request);
	purple_http_request_unref(req);

	g_free(query);
}
Beispiel #3
0
static void
auth_old_pass_cb(PurpleConnection *gc, PurpleRequestFields *fields)
{
	PurpleAccount *account;
	JabberStream *js;
	const char *entry;
	gboolean remember;

	/* TODO: the password prompt dialog doesn't get disposed if the account disconnects */
	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	account = purple_connection_get_account(gc);
	js = purple_connection_get_protocol_data(gc);

	entry = purple_request_fields_get_string(fields, "password");
	remember = purple_request_fields_get_bool(fields, "remember");

	if (!entry || !*entry)
	{
		purple_notify_error(account, NULL,
			_("Password is required to sign on."), NULL,
			purple_request_cpar_from_connection(gc));
		return;
	}

	if (remember)
		purple_account_set_remember_password(account, TRUE);

	purple_account_set_password(account, entry, NULL, NULL);

	/* Restart our connection */
	jabber_auth_start_old(js);
}
static void
ggp_tcpsocket_connected(PurpleSocket *ps, const gchar *error, gpointer priv_gg)
{
	PurpleConnection *gc = purple_socket_get_connection(ps);
	GGPInfo *info = purple_connection_get_protocol_data(gc);
	int fd = -1;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	if (error == NULL)
		fd = purple_socket_get_fd(ps);

	if (!gg_socket_manager_connected(ps, priv_gg, fd)) {
		purple_debug_error("gg", "socket not handled");
		purple_socket_destroy(ps);
	}

	if (info->inpa > 0)
		purple_input_remove(info->inpa);
	if (info->session->fd < 0)
		return;
	info->inpa = purple_input_add(info->session->fd,
		ggp_tcpsocket_inputcond_gg_to_purple(info->session->check),
		ggp_async_login_handler, gc);
}
Beispiel #5
0
static void
auth_no_pass_cb(PurpleConnection *gc, PurpleRequestFields *fields)
{
	/* TODO: the password prompt dialog doesn't get disposed if the account disconnects */
	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	/* Disable the account as the user has cancelled connecting */
	purple_account_set_enabled(purple_connection_get_account(gc), purple_core_get_ui(), FALSE);
}
Beispiel #6
0
static void ggp_pubdir_set_info_got_token(PurpleConnection *gc,
	const gchar *token, gpointer _record)
{
	PurpleHttpRequest *req;
	ggp_pubdir_record *record = _record;
	gchar *request_data;
	gchar *name, *surname, *city;
	uin_t uin = record->uin;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	if (!token) {
		/* TODO: notify about failure */
		ggp_pubdir_record_free(record, 1);
		return;
	}

	name = g_uri_escape_string(record->first_name, NULL, FALSE);
	surname = g_uri_escape_string(record->last_name, NULL, FALSE);
	city = g_uri_escape_string(record->city, NULL, FALSE);

	request_data = g_strdup_printf(
		"name=%s&"
		"surname=%s&"
		"birth=%sT10:00:00%%2B00:00&"
		"birth_priv=2&"
		"gender=%d&"
		"gender_priv=2&"
		"city=%s&"
		"province=%d",
		name, surname,
		ggp_date_strftime("%Y-%m-%d", record->birth),
		record->gender,
		city,
		record->province);

	if (purple_debug_is_verbose() && purple_debug_is_unsafe()) {
		purple_debug_misc("gg", "ggp_pubdir_set_info_got_token: "
			"query [%s]\n", request_data);
	}

	req = purple_http_request_new(NULL);
	purple_http_request_set_method(req, "PUT");
	purple_http_request_set_url_printf(req,
		"http://api.gadu-gadu.pl/users/%u.xml", uin);
	purple_http_request_header_set(req, "Authorization", token);
	purple_http_request_header_set(req, "Content-Type",
		"application/x-www-form-urlencoded");
	purple_http_request_set_contents(req, request_data, -1);
	purple_http_request(gc, req, ggp_pubdir_set_info_got_response, NULL);
	purple_http_request_unref(req);

	g_free(request_data);
	ggp_pubdir_record_free(record, 1);
}
Beispiel #7
0
static inline ggp_edisc_session_data *
ggp_edisc_get_sdata(PurpleConnection *gc)
{
	GGPInfo *accdata;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	accdata = purple_connection_get_protocol_data(gc);
	g_return_val_if_fail(accdata != NULL, NULL);

	return accdata->edisc_data;
}
/*------------------------------------------------------------------------
 * The user has selected to change their PIN.
 *
 *  @param gc		The connection object
 *  @param fields	The fields from the request pop-up
 */
static void mxit_change_pin_cb( PurpleConnection* gc, PurpleRequestFields* fields )
{
	struct MXitSession*		session	= purple_connection_get_protocol_data( gc );
	const char*				pin		= NULL;
	const char*				pin2	= NULL;
	const char*				err		= NULL;
	int						len;
	int						i;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	/* validate pin */
	pin = purple_request_fields_get_string( fields, "pin" );
	if ( !pin ) {
		err = _( "The PIN you entered is invalid." );
		goto out;
	}
	len = strlen( pin );
	if ( ( len < 4 ) || ( len > 10 ) ) {
		err = _( "The PIN you entered has an invalid length [4-10]." );
		goto out;
	}
	for ( i = 0; i < len; i++ ) {
		if ( !g_ascii_isdigit( pin[i] ) ) {
			err = _( "The PIN is invalid. It should only consist of digits [0-9]." );
			goto out;
		}
	}
	pin2 = purple_request_fields_get_string( fields, "pin2" );
	if ( ( !pin2 ) || ( strcmp( pin, pin2 ) != 0 ) ) {
		err = _( "The two PINs you entered do not match." );
		goto out;
	}

out:
	if ( !err ) {
		/* update PIN in account */
		purple_account_set_password( session->acc, pin, NULL, NULL );

		/* update session object */
		g_free( session->encpwd );
		session->encpwd = mxit_encrypt_password( session );

		/* send the update request to MXit */
		mxit_send_extprofile_update( session, session->encpwd, 0, NULL );
	}
	else {
		/* show error to user */
		mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "PIN Update Error" ), err );
	}
}
Beispiel #9
0
static void ggp_avatar_buddy_update_received(PurpleHttpConnection *http_conn,
        PurpleHttpResponse *response, gpointer _pending_update)
{
    ggp_avatar_buddy_update_req *pending_update = _pending_update;
    PurpleBuddy *buddy;
    PurpleAccount *account;
    PurpleConnection *gc = pending_update->gc;
    ggp_avatar_session_data *avdata;
    gchar timestamp_str[20];
    const gchar *got_data;
    size_t got_len;

    PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

    avdata = ggp_avatar_get_avdata(gc);
    g_assert(pending_update == avdata->current_update);
    avdata->current_update = NULL;

    if (!purple_http_response_is_successful(response)) {
        purple_debug_error("gg", "ggp_avatar_buddy_update_received: bad"
                           " response while getting avatar for %u: %s\n",
                           pending_update->uin,
                           purple_http_response_get_error(response));
        g_free(pending_update);
        return;
    }

    account = purple_connection_get_account(gc);
    buddy = purple_blist_find_buddy(account, ggp_uin_to_str(pending_update->uin));

    if (!buddy) {
        purple_debug_warning("gg", "ggp_avatar_buddy_update_received: "
                             "buddy %u disappeared\n", pending_update->uin);
        g_free(pending_update);
        return;
    }

    g_snprintf(timestamp_str, sizeof(timestamp_str), "%lu",
               pending_update->timestamp);
    got_data = purple_http_response_get_data(response, &got_len);
    purple_buddy_icons_set_for_user(account, purple_buddy_get_name(buddy),
                                    g_memdup(got_data, got_len), got_len, timestamp_str);

    purple_debug_info("gg", "ggp_avatar_buddy_update_received: "
                      "got avatar for buddy %u [ts=%lu]\n", pending_update->uin,
                      pending_update->timestamp);
    g_free(pending_update);
}
Beispiel #10
0
static void ggp_avatar_own_sent(PurpleHttpConnection *http_conn,
                                PurpleHttpResponse *response, gpointer user_data)
{
    PurpleConnection *gc =
        purple_http_conn_get_purple_connection(http_conn);

    PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

    if (!purple_http_response_is_successful(response)) {
        purple_debug_error("gg", "ggp_avatar_own_sent: "
                           "avatar not sent. %s\n",
                           purple_http_response_get_error(response));
        return;
    }
    purple_debug_info("gg", "ggp_avatar_own_sent: %s\n",
                      purple_http_response_get_data(response, NULL));
}
Beispiel #11
0
void ggp_avatar_own_set(PurpleConnection *gc, PurpleImage *img)
{
    ggp_avatar_own_data *own_data;

    PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

    purple_debug_info("gg", "ggp_avatar_own_set(%p, %p)", gc, img);

    own_data = ggp_avatar_get_avdata(gc)->own_data;

    if (img == NULL) {
        purple_debug_warning("gg", "ggp_avatar_own_set: avatar removing"
                             " is probably not possible within old protocol");
        return;
    }

    own_data->img = img;

    ggp_oauth_request(gc, ggp_avatar_own_got_token, img, NULL, NULL);
}
Beispiel #12
0
static gboolean ggp_avatar_timer_cb(gpointer _gc)
{
    PurpleConnection *gc = _gc;
    ggp_avatar_session_data *avdata;

    PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

    avdata = ggp_avatar_get_avdata(gc);
    if (avdata->current_update != NULL) {
        if (purple_debug_is_verbose()) {
            purple_debug_misc("gg", "ggp_avatar_timer_cb(%p): "
                              "there is already an update running\n", gc);
        }
        return TRUE;
    }

    while (!ggp_avatar_buddy_update_next(gc));

    return TRUE;
}
Beispiel #13
0
static void ggp_pubdir_get_info_got_token(PurpleConnection *gc,
	const gchar *token, gpointer _request)
{
	PurpleHttpRequest *req;
	ggp_pubdir_request *request = _request;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	if (!token) {
		request->cb(gc, -1, NULL, 0, request->user_data);
		ggp_pubdir_request_free(request);
		return;
	}

	req = purple_http_request_new(NULL);
	purple_http_request_set_url_printf(req,
		"http://api.gadu-gadu.pl/users/%u",
		request->params.user_info.uin);
	purple_http_request_header_set(req, "Authorization", token);
	purple_http_request(gc, req, ggp_pubdir_got_data, request);
	purple_http_request_unref(req);
}
Beispiel #14
0
/*------------------------------------------------------------------------
 * The user has selected to change their profile.
 *
 *  @param gc		The connection object
 *  @param fields	The fields from the request pop-up
 */
static void mxit_profile_cb( PurpleConnection* gc, PurpleRequestFields* fields )
{
	struct MXitSession*		session	= purple_connection_get_protocol_data( gc );
	PurpleRequestField*		field	= NULL;
	const char*				name	= NULL;
	const char*				bday	= NULL;
	const char*				err		= NULL;
	GList*					entry	= NULL;

	purple_debug_info( MXIT_PLUGIN_ID, "mxit_profile_cb\n" );

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	/* validate name */
	name = purple_request_fields_get_string( fields, "name" );
	if ( ( !name ) || ( strlen( name ) < 3 ) ) {
		err = _( "The Display Name you entered is invalid." );
		goto out;
	}

	/* validate birthdate */
	bday = purple_request_fields_get_string( fields, "bday" );
	if ( ( !bday ) || ( strlen( bday ) < 10 ) || ( !validateDate( bday ) ) ) {
		err = _( "The birthday you entered is invalid. The correct format is: 'YYYY-MM-DD'." );
		goto out;
	}

out:
	if ( !err ) {
		struct MXitProfile*	profile		= session->profile;
		GString*			attributes	= g_string_sized_new( 128 );
		char				attrib[512];
		unsigned int		acount		= 0;


		/* update name */
		g_strlcpy( profile->nickname, name, sizeof( profile->nickname ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_FULLNAME, CP_PROFILE_TYPE_UTF8, profile->nickname );
		g_string_append( attributes, attrib );
		acount++;

		/* update birthday */
		g_strlcpy( profile->birthday, bday, sizeof( profile->birthday ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_BIRTHDATE, CP_PROFILE_TYPE_UTF8, profile->birthday );
		g_string_append( attributes, attrib );
		acount++;

		/* update gender */
		profile->male = ( purple_request_fields_get_choice( fields, "male" ) != 0 );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_GENDER, CP_PROFILE_TYPE_BOOL, ( profile->male ) ? "1" : "0" );
		g_string_append( attributes, attrib );
		acount++;

		/* update title */
		name = purple_request_fields_get_string( fields, "title" );
		if ( !name )
			profile->title[0] = '\0';
		else
			g_strlcpy( profile->title, name, sizeof( profile->title ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_TITLE, CP_PROFILE_TYPE_UTF8, profile->title );
		g_string_append( attributes, attrib );
		acount++;

		/* update firstname */
		name = purple_request_fields_get_string( fields, "firstname" );
		if ( !name )
			profile->firstname[0] = '\0';
		else
			g_strlcpy( profile->firstname, name, sizeof( profile->firstname ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_FIRSTNAME, CP_PROFILE_TYPE_UTF8, profile->firstname );
		g_string_append( attributes, attrib );
		acount++;

		/* update lastname */
		name = purple_request_fields_get_string( fields, "lastname" );
		if ( !name )
			profile->lastname[0] = '\0';
		else
			g_strlcpy( profile->lastname, name, sizeof( profile->lastname ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_LASTNAME, CP_PROFILE_TYPE_UTF8, profile->lastname );
		g_string_append( attributes, attrib );
		acount++;

		/* update email address */
		name = purple_request_fields_get_string( fields, "email" );
		if ( !name )
			profile->email[0] = '\0';
		else
			g_strlcpy( profile->email, name, sizeof( profile->email ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_EMAIL, CP_PROFILE_TYPE_UTF8, profile->email );
		g_string_append( attributes, attrib );
		acount++;

		/* update mobile number */
		name = purple_request_fields_get_string( fields, "mobilenumber" );
		if ( !name )
			profile->mobilenr[0] = '\0';
		else
			g_strlcpy( profile->mobilenr, name, sizeof( profile->mobilenr ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_MOBILENR, CP_PROFILE_TYPE_UTF8, profile->mobilenr );
		g_string_append( attributes, attrib );
		acount++;

		/* update about me */
		name = purple_request_fields_get_string( fields, "aboutme" );
		if ( !name )
			profile->aboutme[0] = '\0';
		else
			g_strlcpy( profile->aboutme, name, sizeof( profile->aboutme ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_ABOUTME, CP_PROFILE_TYPE_UTF8, profile->aboutme );
		g_string_append( attributes, attrib );
		acount++;

		/* update where am i */
		name = purple_request_fields_get_string( fields, "whereami" );
		if ( !name )
			profile->whereami[0] = '\0';
		else
			g_strlcpy( profile->whereami, name, sizeof( profile->whereami ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_WHEREAMI, CP_PROFILE_TYPE_UTF8, profile->whereami );
		g_string_append( attributes, attrib );
		acount++;

		/* relationship status */
		field = purple_request_fields_get_field( fields, "relationship" );
		entry = g_list_first( purple_request_field_list_get_selected( field ) );
		profile->relationship = atoi( purple_request_field_list_get_data( field, entry->data ) );
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%i", CP_PROFILE_RELATIONSHIP, CP_PROFILE_TYPE_SHORT, profile->relationship );
		g_string_append( attributes, attrib );
		acount++;

		/* update flags */
		field = purple_request_fields_get_field( fields, "searchable" );
		if ( purple_request_field_bool_get_value( field ) )		/* is searchable -> clear not-searchable flag */
			profile->flags &= ~CP_PROF_NOT_SEARCHABLE;
		else
			profile->flags |= CP_PROF_NOT_SEARCHABLE;
		field = purple_request_fields_get_field( fields, "suggestable" );
		if ( purple_request_field_bool_get_value( field ) )		/* is suggestable -> clear not-suggestable flag */
			profile->flags &= ~CP_PROF_NOT_SUGGESTABLE;
		else
			profile->flags |= CP_PROF_NOT_SUGGESTABLE;
		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%" G_GINT64_FORMAT, CP_PROFILE_FLAGS, CP_PROFILE_TYPE_LONG, profile->flags);
		g_string_append( attributes, attrib );
		acount++;

		/* send the profile update to MXit */
		mxit_send_extprofile_update( session, NULL, acount, attributes->str );
		g_string_free( attributes, TRUE );
	}
	else {
		/* show error to user */
		mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "Profile Update Error" ), err );
	}
}