示例#1
0
void GeneralMenu::fields_ok_cb(PurpleRequestFields *fields)
{
  LOG->debug(
      "fields_ok_cb: text0=%s, text1=%s, int0=%d, bool0=%d, choice0=%d\n",
      purple_request_fields_get_string(fields, "text0"),
      purple_request_fields_get_string(fields, "text1"),
      purple_request_fields_get_integer(fields, "int0"),
      purple_request_fields_get_bool(fields, "bool0"),
      purple_request_fields_get_choice(fields, "choice0"));

  for (GList *list = purple_request_field_list_get_selected(
        purple_request_fields_get_field(fields, "list0")); list;
      list = list->next)
    LOG->debug("fields_ok_cb: list0=%s",
        reinterpret_cast<const char*>(list->data));

  for (GList *list = purple_request_field_list_get_selected(
        purple_request_fields_get_field(fields, "list1")); list;
      list = list->next)
    LOG->debug("fields_ok_cb: list1=%s",
        reinterpret_cast<const char*>(list->data));

  PurpleAccount *account = purple_request_fields_get_account(fields,
      "account0");
  LOG->debug("fields_ok_cb: account0=[%s] %s",
      purple_account_get_protocol_name(account),
      purple_account_get_username(account));
}
示例#2
0
void BuddyList::add_buddy_ok_cb(PurpleRequestFields *fields)
{
  PurpleAccount *account = purple_request_fields_get_account(fields, "account");
  const char *name = purple_request_fields_get_string(fields, "name");
  const char *alias = purple_request_fields_get_string(fields, "alias");
  int selected = purple_request_fields_get_choice(fields, "group");
  GList *list = purple_request_field_choice_get_labels(
      purple_request_fields_get_field(fields, "group"));
  const char *group
    = reinterpret_cast<const char*>(g_list_nth_data(list, selected));

  bool err = false;
  if (!account) {
    LOG->Message(_("No account specified."));
    err = true;
  }
  else if (!purple_account_is_connected(account)) {
    LOG->Message(_("Selected account is not connected."));
    err = true;
  }
  if (!name || !name[0]) {
    LOG->Message(_("No buddy name specified."));
    err = true;
  }
  if (!group || !group[0]) {
    LOG->Message(_("No group name specified."));
    err = true;
  }
  if (err) {
    purple_blist_request_add_buddy(account, name, group, alias);
    return;
  }

  PurpleGroup *g = purple_find_group(group);
  if (!g) {
    g = purple_group_new(group);
    purple_blist_add_group(g, NULL);
  }
  PurpleBuddy *b = purple_find_buddy_in_group(account, name, g);
  if (b) {
    LOG->Message(_("Specified buddy is already in the list."));
    return;
  }

  if (alias && !alias[0])
    alias = NULL;
  b = purple_buddy_new(account, name, alias);
  purple_blist_add_buddy(b, NULL, g, NULL);
  purple_account_add_buddy(account, b);
}
示例#3
0
static void ggp_pubdir_set_info_request(PurpleConnection *gc,
	PurpleRequestFields *fields)
{
	gchar *url;
	uin_t uin = ggp_str_to_uin(purple_account_get_username(
		purple_connection_get_account(gc)));
	ggp_pubdir_record *record = g_new0(ggp_pubdir_record, 1);
	gchar *birth_s;

	purple_debug_info("gg", "ggp_pubdir_set_info_request\n");

	record->uin = uin;
	record->first_name = g_strdup(purple_request_fields_get_string(fields,
		"first_name"));
	record->last_name = g_strdup(purple_request_fields_get_string(fields,
		"last_name"));
	record->gender = GPOINTER_TO_INT(
		purple_request_fields_get_choice(fields, "gender"));
	record->city = g_strdup(purple_request_fields_get_string(fields,
		"city"));
	record->province = GPOINTER_TO_INT(
		purple_request_fields_get_choice(fields, "province"));

	birth_s = g_strdup_printf("%sT10:00:00+00:00",
		purple_request_fields_get_string(fields, "birth_date"));
	record->birth = ggp_date_from_iso8601(birth_s);
	g_free(birth_s);
	purple_debug_info("gg", "ggp_pubdir_set_info_request: birth [%lu][%s]\n",
		record->birth, purple_request_fields_get_string(
		fields, "birth_date"));

	url = g_strdup_printf("http://api.gadu-gadu.pl/users/%u.xml", uin);
	ggp_oauth_request(gc, ggp_pubdir_set_info_got_token, record,
		"PUT", url);
	g_free(url);
}
示例#4
0
static void ggp_pubdir_search_request(PurpleConnection *gc,
	PurpleRequestFields *fields)
{
	ggp_pubdir_search_form *form = g_new0(ggp_pubdir_search_form, 1);

	purple_debug_info("gg", "ggp_pubdir_search_request\n");

	form->nick = g_strdup(purple_request_fields_get_string(fields, "name"));
	form->city = g_strdup(purple_request_fields_get_string(fields, "city"));
	form->gender = GPOINTER_TO_INT(purple_request_fields_get_choice(fields,
		"gender"));
	form->offset = 0;
	form->limit = GGP_PUBDIR_SEARCH_PER_PAGE;

	ggp_pubdir_search_execute(gc, form, ggp_pubdir_search_results_display,
		form);
}
示例#5
0
/* parse fields and send info packet */
static void info_modify_ok_cb(modify_info_request *info_request, PurpleRequestFields *fields)
{
	PurpleConnection *gc;
	qq_data *qd;
	gchar **segments;
	int index;
	const char *utf8_str;
	gchar *value;
	int choice_num;

	gc = info_request->gc;
	g_return_if_fail(gc != NULL && info_request->gc);
	qd = (qq_data *) gc->proto_data;
	segments = info_request->segments;
	g_return_if_fail(segments != NULL);

	for (index = 1; segments[index] != NULL && index < QQ_INFO_LAST; index++) {
		if (field_infos[index].iclass == QQ_FIELD_UNUSED) {
			continue;
		}
		if (!purple_request_fields_exists(fields, field_infos[index].id)) {
			continue;
		}
		switch (field_infos[index].type) {
			case QQ_FIELD_BOOL:
				value = purple_request_fields_get_bool(fields, field_infos[index].id)
						? g_strdup("1") : g_strdup("0");
				g_free(segments[index]);
				segments[index] = value;
				break;
			case QQ_FIELD_CHOICE:
				choice_num = purple_request_fields_get_choice(fields, field_infos[index].id);
				if (choice_num < 0 || choice_num >= field_infos[index].choice_size)	choice_num = 0;

				if (index == QQ_INFO_GENDER) {
					/* QQ Server only recept gender in Chinese */
					value = g_strdup(genders_zh[choice_num]);
				} else {
					value = g_strdup_printf("%d", choice_num);
				}
				g_free(segments[index]);
				segments[index] = value;
				break;
			case QQ_FIELD_LABEL:
			case QQ_FIELD_STRING:
			case QQ_FIELD_MULTI:
			default:
				utf8_str = purple_request_fields_get_string(fields, field_infos[index].id);
				if (utf8_str == NULL) {
					value = g_strdup("-");
				} else {
					value = utf8_to_qq(utf8_str, QQ_CHARSET_DEFAULT);
					if (value == NULL) value = g_strdup("-");
				}
				g_free(segments[index]);
				segments[index] = value;
				break;
		}
	}
	request_change_info(gc, segments);

	g_strfreev(segments);
	g_free(info_request);
}
示例#6
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 );
	}
}
示例#7
0
文件: login.c 项目: Distrotech/pidgin
/*------------------------------------------------------------------------
 * Register a new account with MXit
 *
 * @param gc		The connection object
 * @param fields	This is the fields filled-in by the user
 */
static void mxit_cb_register_ok( PurpleConnection *gc, PurpleRequestFields *fields )
{
	struct MXitSession*		session		= purple_connection_get_protocol_data( gc );
	struct MXitProfile*		profile		= session->profile;
	const char*				str;
	const char*				pin;
	const char*				err			= NULL;
	int						len;
	int						i;

	purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_register_ok\n" );

	if ( !PURPLE_CONNECTION_IS_VALID( gc ) ) {
		purple_debug_error( MXIT_PLUGIN_ID, "Unable to register; account offline.\n" );
		return;
	}

	/* nickname */
	str = purple_request_fields_get_string( fields, "nickname" );
	if ( ( !str ) || ( strlen( str ) < 3 ) ) {
		err = _( "The Display Name you entered is too short." );
		goto out;
	}
	g_strlcpy( profile->nickname, str, sizeof( profile->nickname ) );

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

	/* gender */
	profile->male = ( purple_request_fields_get_choice( fields, "male" ) != 0 );

	/* 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 < 7 ) || ( len > 10 ) ) {
		err = _( "The PIN you entered has an invalid length [7-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;
		}
	}
	str = purple_request_fields_get_string( fields, "pin2" );
	if ( ( !str ) || ( strcmp( pin, str ) != 0 ) ) {
		err = _( "The two PINs you entered do not match." );
		goto out;
	}
	g_strlcpy( profile->pin, pin, sizeof( profile->pin ) );

out:
	if ( !err ) {
		purple_account_set_password( session->acc, session->profile->pin, NULL, NULL );
		mxit_login_connect( session );
	}
	else {
		/* show error to user */
		mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "Registration Error" ), err );
		mxit_register_view( session );
	}
}
示例#8
0
void BuddyList::add_chat_ok_cb(PurpleRequestFields *fields)
{
  PurpleAccount *account = purple_request_fields_get_account(fields, "account");
  const char *name = purple_request_fields_get_string(fields, "name");
  const char *alias = purple_request_fields_get_string(fields, "alias");
  int selected = purple_request_fields_get_choice(fields, "group");
  GList *list = purple_request_field_choice_get_labels(
      purple_request_fields_get_field(fields, "group"));
  const char *group
    = reinterpret_cast<const char*>(g_list_nth_data(list, selected));
  bool autojoin = purple_request_fields_get_bool(fields, "autojoin");

  bool err = false;
  if (!account) {
    LOG->Message(_("No account specified."));
    err = true;
  }
  else if (!purple_account_is_connected(account)) {
    LOG->Message(_("Selected account is not connected."));
    err = true;
  }
  else {
    PurpleConnection *gc = purple_account_get_connection(account);
    PurplePluginProtocolInfo *info = PURPLE_PLUGIN_PROTOCOL_INFO(
        purple_connection_get_prpl(gc));
    if (!info->join_chat) {
      LOG->Message(_("This protocol does not support chat rooms."));
      account = NULL;
      err = true;
    }
  }
  if (!name || !name[0]) {
    LOG->Message(_("No buddy name specified."));
    err = true;
  }
  if (!group || !group[0]) {
    LOG->Message(_("No group name specified."));
    err = true;
  }
  if (err) {
    purple_blist_request_add_chat(account, purple_find_group(group), alias, name);
    return;
  }

  PurpleConnection *gc = purple_account_get_connection(account);
  PurplePluginProtocolInfo *info = PURPLE_PLUGIN_PROTOCOL_INFO(
      purple_connection_get_prpl(gc));
  GHashTable *hash = NULL;
  if (info->chat_info_defaults)
    hash = info->chat_info_defaults(gc, name);

  PurpleChat *chat = purple_chat_new(account, name, hash);

  if (chat) {
    PurpleGroup* g = purple_find_group(group);
    if (!g) {
      g = purple_group_new(group);
      purple_blist_add_group(g, NULL);
    }
    purple_blist_add_chat(chat, g, NULL);
    if (alias && alias[0])
      purple_blist_alias_chat(chat, alias);
    purple_blist_node_set_bool(reinterpret_cast<PurpleBlistNode*>(chat),
        PACKAGE_NAME "-autojoin", autojoin);
  }
}