Esempio n. 1
0
static void discover_status(PurpleConnection *from, PurpleConnection *to,
                            gpointer userdata) {
  const char *from_username = purple_account_get_username(purple_connection_get_account(from));
  const char *to_username = purple_account_get_username(purple_connection_get_account(to));

  if (purple_blist_find_buddy(purple_connection_get_account(from), to_username)) {
    PurpleStatus *status = purple_account_get_active_status(purple_connection_get_account(to));
    const char *status_id = purple_status_get_id(status);
    const char *message = purple_status_get_attr_string(status, "message");

    if (!strcmp(status_id, NULL_STATUS_ONLINE) ||
        !strcmp(status_id, NULL_STATUS_AWAY) ||
        !strcmp(status_id, NULL_STATUS_OFFLINE)) {
      purple_debug_info("nullprpl", "%s sees that %s is %s: %s\n",
                        from_username, to_username, status_id, message);
      purple_prpl_got_user_status(purple_connection_get_account(from), to_username, status_id,
                                  (message) ? "message" : NULL, message, NULL);
    } else {
      purple_debug_error("nullprpl",
                         "%s's buddy %s has an unknown status: %s, %s",
                         from_username, to_username, status_id, message);
    }
  }
}
Esempio n. 2
0
static void
signing_on_cb(PurpleConnection *gc)
{
	if (!console)
		return;

	gtk_combo_box_append_text(GTK_COMBO_BOX(console->dropdown), purple_account_get_username(gc->account));
	console->accounts = g_list_append(console->accounts, gc);
	console->count++;

	if (console->count == 1)
		console->gc = gc;
	else
		gtk_widget_show_all(console->hbox);
}
Esempio n. 3
0
static PurpleRoomlist *nullprpl_roomlist_get_list(PurpleConnection *gc) {
  const char *username = purple_account_get_username(purple_connection_get_account(gc));
  PurpleRoomlist *roomlist = purple_roomlist_new(purple_connection_get_account(gc));
  GList *fields = NULL;
  PurpleRoomlistField *field;
  GList *chats;
  GList *seen_ids = NULL;

  purple_debug_info("nullprpl", "%s asks for room list; returning:\n", username);

  /* set up the room list */
  field = purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING, "room",
                                    "room", TRUE /* hidden */);
  fields = g_list_append(fields, field);

  field = purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_INT, "Id", "Id", FALSE);
  fields = g_list_append(fields, field);

  purple_roomlist_set_fields(roomlist, fields);

  /* add each chat room. the chat ids are cached in seen_ids so that each room
   * is only returned once, even if multiple users are in it. */
  for (chats  = purple_conversations_get_chats(); chats; chats = g_list_next(chats)) {
    PurpleChatConversation *chat = PURPLE_CHAT_CONVERSATION(chats->data);
    PurpleRoomlistRoom *room;
    const char *name = purple_conversation_get_name(PURPLE_CONVERSATION(chat));
    int id = purple_chat_conversation_get_id(chat);

    /* have we already added this room? */
    if (g_list_find_custom(seen_ids, name, (GCompareFunc)strcmp))
      continue;                                /* yes! try the next one. */

    /* This cast is OK because this list is only staying around for the life
     * of this function and none of the conversations are being deleted
     * in that timespan. */
    seen_ids = g_list_prepend(seen_ids, (char *)name); /* no, it's new. */
    purple_debug_info("nullprpl", "%s (%d), ", name, id);

    room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM, name, NULL);
    purple_roomlist_room_add_field(roomlist, room, name);
    purple_roomlist_room_add_field(roomlist, room, &id);
    purple_roomlist_room_add(roomlist, room);
  }

  g_list_free(seen_ids);
  purple_timeout_add(1 /* ms */, nullprpl_finish_get_roomlist, g_object_ref(roomlist));
  return roomlist;
}
Esempio n. 4
0
xmlnode * _h_elim_set_icon ( const char *name , 
                             const char *id   ,
                             SEXP_VALUE *args , 
                             gpointer    data )
{
    ASSERT_ALISTP( args, id, name );

    elim_ping();
    
    const char *aname = ALIST_VAL_STR ( args, "account-name" );
    const char *proto = ALIST_VAL_STR ( args, "im-protocol"  );
    gpointer    auid  = ALIST_VAL_PTR ( args, "account-uid"  );
    const char *file  = ALIST_VAL_STR ( args, "icon-file"    );
    GString    *img   = ALIST_VAL_DATA( args, "icon-data"    );
    gchar      *bytes = NULL;
    gsize       len   = 0;
    gpointer    set   = NULL;
    PurpleAccount *acct =
      auid ? find_acct_by_uid( auid ) : purple_accounts_find( aname, proto );

    if( !acct )
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "unknown account" );
    }

    if( !img && file && *file )
    {
        g_file_get_contents( file, &bytes, &len, NULL );
    }
    else if( img )
    {
        bytes = g_memdup( img->str, img->len );
        len   = img->len;
    }

    // the imgstore owns `bytes' after this, don't free it:
    set = purple_buddy_icons_set_account_icon( acct, (guchar *)bytes, len );

    xmlnode *rval = xnode_new( "alist" );
    AL_PTR ( rval, "account-uid" , acct );
    AL_STR ( rval, "account-name", purple_account_get_username   ( acct ) );
    AL_STR ( rval, "im-protocol" , purple_account_get_protocol_id( acct ) );
    AL_BOOL( rval, "has-icon"    , set ? TRUE : FALSE );

    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
Esempio n. 5
0
static void
set_account_idle(PurpleAccount *account, int time_idle)
{
	PurplePresence *presence;

	presence = purple_account_get_presence(account);

	if (purple_presence_is_idle(presence))
		/* This account is already idle! */
		return;

	purple_debug_info("idle", "Setting %s idle %d seconds\n",
			   purple_account_get_username(account), time_idle);
	purple_presence_set_idle(presence, TRUE, time(NULL) - time_idle);
	idled_accts = g_list_prepend(idled_accts, account);
}
Esempio n. 6
0
qq_account* qq_account_new(PurpleAccount* account)
{
   qq_account* ac = g_malloc0(sizeof(qq_account));
   ac->account = account;
   ac->magic = QQ_MAGIC;
   ac->flag = 0;
   // this is auto increment sized array . so don't worry about it.
   const char* username = purple_account_get_username(account);
   const char* password = purple_account_get_password(account);
   ac->qq = lwqq_client_new(username, password);
   ac->js = lwqq_js_init();
   ac->sys_log = purple_log_new(PURPLE_LOG_SYSTEM, "system", account, NULL,
                                time(NULL), NULL);
   // add ~/.config/lwqq into search path
   lwqq_util_add_path(lwdb_get_config_dir());
#ifdef WITH_MOZJS
   lwqq_hash_add_entry(ac->qq, "hash_local", (LwqqHashFunc)hash_with_local_file,
                       ac->js);
   lwqq_hash_add_entry(ac->qq, "hash_url", (LwqqHashFunc)hash_with_remote_file,
                       ac->js);
   lwqq_hash_add_entry(ac->qq, "hash_db", (LwqqHashFunc)hash_with_db_url, ac);
#endif

   ac->font.family = s_strdup("宋体");
   ac->font.size = 12;
   ac->font.style = 0;

// lwqq_async_set(ac->qq,1);
#if QQ_USE_FAST_INDEX
   ac->qq->find_buddy_by_uin = find_buddy_by_uin;
   ac->qq->find_buddy_by_qqnumber = find_buddy_by_qqnumber;
   ac->fast_index.uin_index
       = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
   ac->fast_index.qqnum_index
       = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
#endif
   ac->qq->dispatch = qq_dispatch;

   char cookie[256];
   snprintf(cookie, sizeof(cookie), "%s/%s.cookie", lwdb_get_config_dir(),
            username);
   LwqqExtension* ext = lwqq_make_cookie_extension(ac->qq, cookie);
   ext->init(ac->qq, ext);

   return ac;
}
Esempio n. 7
0
static void
set_account_unidle(PurpleAccount *account)
{
	PurplePresence *presence;

	presence = purple_account_get_presence(account);

	idled_accts = g_list_remove(idled_accts, account);

	if (!purple_presence_is_idle(presence))
		/* This account is already unidle! */
		return;

	purple_debug_info("idle", "Setting %s unidle\n",
			   purple_account_get_username(account));
	purple_presence_set_idle(presence, FALSE, 0);
}
Esempio n. 8
0
void twitter_send_request(PurpleAccount *account, gboolean post,
		const char *url, const char *query_string, 
		TwitterSendRequestSuccessFunc success_callback, TwitterSendRequestErrorFunc error_callback,
		gpointer data)
{
	gchar *request;
	const char *pass = purple_connection_get_password(purple_account_get_connection(account));
	const char *sn = purple_account_get_username(account);
	char *auth_text = g_strdup_printf("%s:%s", sn, pass);
	char *auth_text_b64 = purple_base64_encode((guchar *) auth_text, strlen(auth_text));
	gboolean use_https = purple_account_get_bool(account, "use_https", FALSE) && purple_ssl_is_supported();
	char *host = "twitter.com";
	TwitterSendRequestData *request_data = g_new0(TwitterSendRequestData, 1);
	char *full_url = g_strdup_printf("%s://%s%s",
			use_https ? "https" : "http",
			host,
			url);
	request_data->account = account;
	request_data->user_data = data;
	request_data->success_func = success_callback;
	request_data->error_func = error_callback;

	g_free(auth_text);

	request = g_strdup_printf(
			"%s %s%s%s HTTP/1.0\r\n"
			"User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n"
			"Host: %s\r\n"
			"Authorization: Basic %s\r\n"
			"Content-Length: %d\r\n\r\n"
			"%s",
			post ? "POST" : "GET",
			full_url,
			(!post && query_string ? "?" : ""), (!post && query_string ? query_string : ""),
			host,
			auth_text_b64,
			query_string  && post ? strlen(query_string) : 0,
			query_string && post ? query_string : "");

	g_free(auth_text_b64);
	purple_util_fetch_url_request(full_url, TRUE,
			"Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, request, FALSE,
			twitter_send_request_cb, request_data);
	g_free(full_url);
	g_free(request);
}
Esempio n. 9
0
xmlnode * _h_elim_buddy_info ( const char *name ,
                               const char *id   ,
                               SEXP_VALUE *args ,
                               gpointer data    )
{
    ASSERT_ALISTP( args, id, name );
    
    PurpleAccount    *acct  = NULL;
    PurpleConnection *conn  = NULL;
    gpointer          a_uid = NULL;
    gpointer          b_uid = ALIST_VAL_PTR( args, "bnode-uid" );
    PurpleBlistNode  *bnode = find_blist_node_by_uid( b_uid, TRUE );
    PurpleBlistNodeType  bt = PURPLE_BLIST_OTHER_NODE;

    if( !bnode )
        HANDLER_FAIL( args, id, name, ENOENT, "no such buddy" );

    bt = purple_blist_node_get_type( bnode );
    switch( bt )
    {
      case PURPLE_BLIST_BUDDY_NODE:
        a_uid = purple_buddy_get_account( (PurpleBuddy *)bnode );
        break;
      default:
        HANDLER_FAIL( args, id, name, EINVAL, "unsupported buddy type" );
        break;
    }

    FETCH_ACCOUNT( args, id, name, acct, a_uid );
    
    conn = purple_account_get_connection( acct  );

    if( !conn )
        HANDLER_FAIL( args, id, name, ENXIO, "account disconnected" );

    xmlnode *rval = xnode_new( "alist" );
    AL_PTR ( rval, "bnode-uid"   , bnode );
    AL_PTR ( rval, "account-uid" , acct  );
    AL_STR ( rval, "account-name", purple_account_get_username   ( acct ) );
    AL_STR ( rval, "im-protocol" , purple_account_get_protocol_id( acct ) );

    serv_get_info( conn, purple_buddy_get_name( (PurpleBuddy *)bnode ) );

    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
Esempio n. 10
0
static void insert_cap_failure(CapStatistics *stats) {
	gchar *buddy_name = stats->buddy->name;
	const gchar *protocol_id = purple_account_get_protocol_id(stats->buddy->account);
	const gchar *account_id = purple_account_get_username(stats->buddy->account);
	const gchar *status_id = (stats->last_message_status_id) ?
		stats->last_message_status_id :
		purple_status_get_id(get_status_for(stats->buddy));
	struct tm *current_time = localtime(&stats->last_message);
	int minute = current_time->tm_min + current_time->tm_hour * 60;

	insert_cap_msg_count_failed(buddy_name, account_id, protocol_id, minute);

	insert_cap_status_count_failed(buddy_name, account_id, protocol_id, status_id);

	stats->last_message = -1;
	stats->last_message_status_id = NULL;
}
Esempio n. 11
0
void
msn_show_sync_issue(MsnSession *session, const char *passport,
					const char *group_name)
{
	PurpleConnection *gc;
	PurpleAccount *account;
	MsnAddRemData *data;
	char *msg, *reason;

	account = session->account;
	gc = purple_account_get_connection(account);

	data        = g_new0(MsnAddRemData, 1);
	data->who   = g_strdup(passport);
	data->group = g_strdup(group_name);
	data->gc    = gc;

	msg = g_strdup_printf(_("Buddy list synchronization issue in %s (%s)"),
						  purple_account_get_username(account),
						  purple_account_get_protocol_name(account));

	if (group_name != NULL)
	{
		reason = g_strdup_printf(_("%s on the local list is "
								   "inside the group \"%s\" but not on "
								   "the server list. "
								   "Do you want this buddy to be added?"),
								 passport, group_name);
	}
	else
	{
		reason = g_strdup_printf(_("%s is on the local list but "
								   "not on the server list. "
								   "Do you want this buddy to be added?"),
								 passport);
	}

	purple_request_action(gc, NULL, msg, reason, PURPLE_DEFAULT_ACTION_NONE, 
						purple_connection_get_account(gc), data->who, NULL,
						data, 2,
						_("Yes"), G_CALLBACK(msn_add_cb),
						_("No"), G_CALLBACK(msn_rem_cb));

	g_free(reason);
	g_free(msg);
}
Esempio n. 12
0
static void tgprpl_login (PurpleAccount * acct) {
  debug ("tgprpl_login()\n");
  PurpleConnection *gc = purple_account_get_connection(acct);
  char const *username = purple_account_get_username(acct);
  
  struct tgl_state *TLS = tgl_state_alloc ();
  
  const char *dir = config_dir;
  struct passwd *pw = getpwuid(getuid());
  size_t len = strlen (dir) + strlen (pw->pw_dir) + 2 + strlen (username);
  TLS->base_path = malloc (len);
  snprintf (TLS->base_path, len, "%s/%s/%s", pw->pw_dir, dir, username);
  debug ("base configuration path: '%s'", TLS->base_path);
  g_mkdir_with_parents(TLS->base_path, 0700);
  
  len += strlen ("/downloads");
  char *ddir = malloc (len);
  sprintf (ddir, "%s/downloads", TLS->base_path);
  tgl_set_download_directory (TLS, ddir);
  g_mkdir_with_parents(ddir, 0700);
  free (ddir);
  
  tgl_set_verbosity (TLS, 4);
  tgl_set_rsa_key (TLS, pk_path);
  
  // create handle to store additional info for libpurple in
  // the new telegram instance
  telegram_conn *conn = g_new0(telegram_conn, 1);
  conn->TLS = TLS;
  conn->gc = gc;
  conn->pa = acct;
  conn->new_messages = g_queue_new ();
  conn->joining_chats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
  purple_connection_set_protocol_data (gc, conn);
  
  tgl_set_ev_base (TLS, conn);
  tgl_set_net_methods (TLS, &tgp_conn_methods);
  tgl_set_timer_methods (TLS, &tgp_timers);
  tgl_set_callback (TLS, &tgp_callback);
  tgl_register_app_id (TLS, TGP_APP_ID, TGP_APP_HASH); 
  
  tgl_init (TLS);
  purple_connection_set_state (conn->gc, PURPLE_CONNECTING);
  
  telegram_login (TLS);
}
Esempio n. 13
0
/*------------------------------------------------------------------------
 * Create a new mxit session object
 *
 * @return The MXit session object
 */
static struct MXitSession* mxit_create_object( PurpleAccount* account )
{
	PurpleConnection*	con			= purple_account_get_connection( account );
	struct MXitSession*	session		= NULL;

	/* currently the wapsite does not handle a '+' in front of the username (mxitid) so we just strip it */
	{
		const char* username	= purple_account_get_username( account );

		if ( username[0] == '+' ) {
			char* fixed = g_strdup( &username[1] );
			purple_account_set_username( account, fixed );
			g_free( fixed );
		}
	}

	session = g_new0( struct MXitSession, 1 );
	session->con = con;
	session->acc = account;

	/* configure the connection (reference: "libpurple/connection.h") */
	purple_connection_set_protocol_data( con, session );
	purple_connection_set_flags( con,
			  PURPLE_CONNECTION_FLAG_NO_BGCOLOR
			| PURPLE_CONNECTION_FLAG_NO_URLDESC
			| PURPLE_CONNECTION_FLAG_HTML
			| PURPLE_CONNECTION_FLAG_SUPPORT_MOODS
	);

	/* configure the session (reference: "libpurple/account.h") */
	g_strlcpy( session->server, purple_account_get_string( account, MXIT_CONFIG_SERVER_ADDR, DEFAULT_SERVER ), sizeof( session->server ) );
	g_strlcpy( session->http_server, purple_account_get_string( account, MXIT_CONFIG_HTTPSERVER, DEFAULT_HTTP_SERVER ), sizeof( session->http_server ) );
	session->port = purple_account_get_int( account, MXIT_CONFIG_SERVER_PORT, DEFAULT_PORT );
	g_strlcpy( session->distcode, purple_account_get_string( account, MXIT_CONFIG_DISTCODE, "" ), sizeof( session->distcode ) );
	g_strlcpy( session->clientkey, purple_account_get_string( account, MXIT_CONFIG_CLIENTKEY, "" ), sizeof( session->clientkey ) );
	g_strlcpy( session->dialcode, purple_account_get_string( account, MXIT_CONFIG_DIALCODE, "" ), sizeof( session->dialcode ) );
	session->http = purple_account_get_bool( account, MXIT_CONFIG_USE_HTTP, FALSE );
	session->iimages = g_hash_table_new( g_str_hash, g_str_equal );
	session->rx_state = RX_STATE_RLEN;
	session->http_interval = MXIT_HTTP_POLL_MIN;
	session->http_last_poll = mxit_now_milli();
	session->async_http_reqs = purple_http_connection_set_new();

	return session;
}
Esempio n. 14
0
static void set_chat_topic_fn(PurpleChatConversation *from, PurpleChatConversation *to,
                              int id, const char *room, gpointer userdata) {
  const char *topic = (const char *)userdata;
  const char *username = purple_account_get_username(purple_conversation_get_account(PURPLE_CONVERSATION(from)));
  char *msg;

  purple_chat_conversation_set_topic(to, username, topic);

  if (topic && *topic)
    msg = g_strdup_printf(_("%s sets topic to: %s"), username, topic);
  else
    msg = g_strdup_printf(_("%s clears topic"), username);

  purple_conversation_write_message(PURPLE_CONVERSATION(to), username, msg,
                                    PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,
                                    time(NULL));
  g_free(msg);
}
Esempio n. 15
0
static void
connection_error_cb(PurpleConnection *gc, PurpleConnectionError err,
                    const gchar *desc, void *data)
{
	char* growl_msg;
	PurpleAccount* account = purple_connection_get_account(gc);
	const gchar *username =	purple_account_get_username(account);
	int len = s_strlen((char*)desc) + s_strlen((char*)username) + 2 ;
	
	DEBUG_MSG("connection_error_cb\n");
	
	growl_msg = malloc( len);
	g_snprintf(growl_msg, len, "%s\n%s", desc, username);
	
	gntp_notify("connection-error", NULL, "Connection Error", growl_msg, NULL);
	
	free(growl_msg);
}
int main (int argc, char **argv)
{
	GList *alist, *node;

	purple_init();

	alist = purple_accounts_get_all();
	for (node = alist; node != NULL; node = node->next)
	{
		PurpleAccount *account = (PurpleAccount*) node->data;
		char *name = purple_account_get_username(account);
		g_print("Name: %s\n", name);
		g_free(name);
	}
	g_list_free(alist);

	return 0;
}
Esempio n. 17
0
void PurpleContactListMngr::UpdateBuddy(PurpleBuddyList *list, PurpleBuddy *gBuddy)
{
	IMAccount *account = NULL;
	PurpleAccount	*gAccount = purple_buddy_get_account(gBuddy);
	PurplePresence *gPresence = purple_buddy_get_presence(gBuddy);
	const char *gPrclId = purple_account_get_protocol_id(gAccount);
	
	account = _accountMngr->FindIMAccount(purple_account_get_username(gAccount),
		PurpleIMPrcl::GetEnumIMProtocol(gPrclId));
	
	if (account)
	{
		PurpleIMContactList *mIMBList = FindIMContactList(*account);
		PurpleIMPresence *mIMPresence = _presenceMngr->FindIMPresence(*account);
	

		if (mIMBList)
		{
			const char * groupName = FindBuddyGroup(gBuddy);
			if (groupName)
			{
				mIMBList->contactMovedEvent(*mIMBList,
					groupName, purple_buddy_get_name(gBuddy));
			}
		}

		if (mIMPresence)
		{
			const char* buddy_alias   = gBuddy->server_alias && *gBuddy->server_alias ? gBuddy->server_alias : gBuddy->alias;
			const char* statusMessage = PurpleIMPresence::getPurpleBuddyStatusMessage(gBuddy);
			const char* gPresenceId   = PurpleIMPresence::getPurplePresenceId(gPresence);

			//VOXOX - JRT - 2009.07.20 - COE in this method.  Is there a way to alert libpurple that we are quitting?
			//VOXOX - JRT - 2009.09.21 - Still here.  Let's see if we can catch problem in the parameters.
			EnumPresenceState::PresenceState presenceState = PurplePreState::GetPresenceState(gPresenceId);

			std::string   alias     = !buddy_alias   ? String::null : buddy_alias;
			std::string   statusMsg = !statusMessage ? String::null : statusMessage;
			const char*   from		= purple_buddy_get_name(gBuddy);

			mIMPresence->presenceStateChangedEvent(*mIMPresence, presenceState, alias, statusMsg, from );
		}
	}
}
Esempio n. 18
0
void
msn_session_finish_login(MsnSession *session)
{
	PurpleAccount *account;
	PurpleConnection *gc;
	PurpleStoredImage *img;
	const char *passport;

	if (session->logged_in) {
		/* We are probably here because of a mid-session notification server XFR
		 * We must send a CHG now, otherwise the servers default to invisible,
		 * and prevent things happening, like sending IMs */
		msn_change_status(session);
		return;
	}

	account = session->account;
	gc = purple_account_get_connection(account);

	img = purple_buddy_icons_find_account_icon(session->account);
	msn_user_set_buddy_icon(session->user, img);
	purple_imgstore_unref(img);

	session->logged_in = TRUE;

	msn_change_status(session);

	purple_connection_set_state(gc, PURPLE_CONNECTED);

	/* Sync users */
	msn_session_sync_users(session);
	/* It seems that some accounts that haven't accessed hotmail for a while
	 * and @msn.com accounts don't automatically get the initial email
	 * notification so we always request it on login
	 */

	passport = purple_normalize(account, purple_account_get_username(account));

	if ((strstr(passport, "@hotmail.") != NULL) ||
		(strstr(passport, "@msn.com") != NULL))
	{
		msn_cmdproc_send(session->notification->cmdproc, "URL", "%s", "INBOX");
	}
}
Esempio n. 19
0
static void nullprpl_set_chat_topic(PurpleConnection *gc, int id,
                                    const char *topic) {
  PurpleChatConversation *chat = purple_conversations_find_chat(gc, id);
  const char *last_topic;

  if (!chat)
    return;

  purple_debug_info("nullprpl", "%s sets topic of chat room '%s' to '%s'\n",
                    purple_account_get_username(purple_connection_get_account(gc)),
                    purple_conversation_get_name(PURPLE_CONVERSATION(chat)), topic);

  last_topic = purple_chat_conversation_get_topic(chat);
  if ((!topic && !last_topic) ||
      (topic && last_topic && !strcmp(topic, last_topic)))
    return;  /* topic is unchanged, this is a noop */

  foreach_gc_in_chat(set_chat_topic_fn, gc, id, (gpointer)topic);
}
Esempio n. 20
0
void
msn_request_user_display(MsnUser *user)
{
	PurpleAccount *account;
	MsnSession *session;
	MsnSlpLink *slplink;
	MsnObject *obj;
	const char *info;

	session = user->userlist->session;
	account = session->account;

	slplink = msn_session_get_slplink(session, user->passport);

	obj = msn_user_get_object(user);

	info = msn_object_get_sha1(obj);

	if (g_ascii_strcasecmp(user->passport,
						   purple_account_get_username(account)))
	{
		const char *url = msn_object_get_url1(obj);
		if (url) {
			PurpleHttpRequest *req;
			MsnFetchUserDisplayData *data = g_new0(MsnFetchUserDisplayData, 1);
			data->session = session;
			data->remote_user = user->passport;
			data->sha1 = info;

			req = purple_http_request_new(url);
			purple_http_request_set_max_len(req, 200*1024);
			purple_http_connection_set_add(session->http_reqs,
				purple_http_request(NULL, req,
					fetched_user_display, data));
			purple_http_request_unref(req);
		} else {
			msn_slplink_request_object(slplink, info, got_user_display,
			                           end_user_display, obj);
		}
	}
	else
		request_own_user_display(user);
}
Esempio n. 21
0
MsnSession *
msn_session_new(PurpleAccount *account)
{
	MsnSession *session;

	g_return_val_if_fail(account != NULL, NULL);

	session = g_new0(MsnSession, 1);

	session->account = account;
	session->notification = msn_notification_new(session);
	session->userlist = msn_userlist_new(session);

	session->user = msn_user_new(session->userlist,
								 purple_account_get_username(account), NULL);

	session->protocol_ver = 9;

	return session;
}
Esempio n. 22
0
static void _elim_notify_added ( PurpleAccount *account    ,
                                 const char    *remote_user,
                                 const char    *id         ,
                                 const char    *alias      ,
                                 const char    *message    )
{
    xmlnode *alist = xnode_new( "alist" );
    char    *ID    = new_elim_id();
    fprintf( stderr, "(_elim_notify_added)\n" );

    AL_STR( alist, "user"         , remote_user  );
    AL_STR( alist, "alias"        , alias        );
    AL_STR( alist, "message"      , message      );
    AL_PTR( alist, "account-uid"  , account      );
    AL_STR( alist, "account-name" , purple_account_get_username   ( account ) );
    AL_STR( alist, "im-protocol"  , purple_account_get_protocol_id( account ) );
    xmlnode *mcall = func_call( "elim-account-notify-added", ID, alist );
    g_free( ID );
    add_outbound_sexp( mcall );
}
Esempio n. 23
0
static void
ggp_avatar_own_got_token(PurpleConnection *gc, const gchar *token,
                         gpointer _img)
{
    PurpleHttpRequest *req;
    PurpleImage *img = _img;
    ggp_avatar_own_data *own_data = ggp_avatar_get_avdata(gc)->own_data;
    gchar *img_data, *img_data_e, *request_data;
    PurpleAccount *account = purple_connection_get_account(gc);
    uin_t uin = ggp_str_to_uin(purple_account_get_username(account));

    if (img != own_data->img) {
        purple_debug_warning("gg", "ggp_avatar_own_got_token: "
                             "avatar was changed in meantime\n");
        return;
    }
    own_data->img = NULL;

    img_data = purple_base64_encode(purple_image_get_data(img),
                                    purple_image_get_size(img));
    img_data_e = g_uri_escape_string(img_data, NULL, FALSE);
    g_free(img_data);
    request_data = g_strdup_printf("uin=%d&photo=%s", uin, img_data_e);
    g_free(img_data_e);

    purple_debug_misc("gg", "ggp_avatar_own_got_token: "
                      "uploading new avatar...\n");

    req = purple_http_request_new("http://avatars.nowe.gg/upload");
    purple_http_request_set_max_len(req, GGP_AVATAR_RESPONSE_MAX);
    purple_http_request_set_method(req, "POST");
    purple_http_request_header_set(req, "Authorization", token);
    purple_http_request_header_set(req, "From", "avatars to avatars");
    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_avatar_own_sent, NULL);
    purple_http_request_unref(req);

    g_free(request_data);
}
Esempio n. 24
0
static void
connect_cb(MsnServConn *servconn)
{
	MsnSwitchBoard *swboard;
	MsnTransaction *trans;
	MsnCmdProc *cmdproc;
	PurpleAccount *account;
	char *username;

	cmdproc = servconn->cmdproc;
	g_return_if_fail(cmdproc != NULL);

	account = cmdproc->session->account;
	swboard = cmdproc->data;
	g_return_if_fail(swboard != NULL);

	username = g_strdup_printf("%s;{%s}",
	                           purple_account_get_username(account),
	                           servconn->session->guid);

	if (msn_switchboard_is_invited(swboard))
	{
		swboard->empty = FALSE;

		trans = msn_transaction_new(cmdproc, "ANS", "%s %s %s",
									username,
									swboard->auth_key, swboard->session_id);
	}
	else
	{
		trans = msn_transaction_new(cmdproc, "USR", "%s %s",
									username,
									swboard->auth_key);
	}

	msn_transaction_set_error_cb(trans, ans_usr_error);
	msn_transaction_set_data(trans, swboard);
	msn_cmdproc_send_trans(cmdproc, trans);

	g_free(username);
}
Esempio n. 25
0
static int nullprpl_chat_send(PurpleConnection *gc, int id, const char *message,
                              PurpleMessageFlags flags) {
  const char *username = purple_account_get_username(purple_connection_get_account(gc));
  PurpleChatConversation *chat = purple_conversations_find_chat(gc, id);

  if (chat) {
    purple_debug_info("nullprpl",
                      "%s is sending message to chat room %s: %s\n", username,
                      purple_conversation_get_name(PURPLE_CONVERSATION(chat)), message);

    /* send message to everyone in the chat room */
    foreach_gc_in_chat(receive_chat_message, gc, id, (gpointer)message);
    return 0;
  } else {
    purple_debug_info("nullprpl",
                      "tried to send message from %s to chat room #%d: %s\n"
                      "but couldn't find chat room",
                      username, id, message);
    return -1;
  }
}
Esempio n. 26
0
void on_ready (struct tgl_state *TLS) {
  debug ("on_ready().\n");
  telegram_conn *conn = TLS->ev_base;
  
  purple_connection_set_state(conn->gc, PURPLE_CONNECTED);
  purple_connection_set_display_name(conn->gc, purple_account_get_username(conn->pa));
  purple_blist_add_account(conn->pa);
  tggroup = purple_find_group("Telegram");
  if (tggroup == NULL) {
    debug ("PurpleGroup = NULL, creating");
    tggroup = purple_group_new ("Telegram");
    purple_blist_add_group (tggroup, NULL);
  }
  
  debug ("seq = %d, pts = %d\n", TLS->seq, TLS->pts);
  tgl_do_get_difference (TLS, 0, 0, 0);
  tgl_do_get_dialog_list (TLS, 0, 0);
  tgl_do_update_contact_list (TLS, 0, 0);
  
  conn->timer = purple_timeout_add (5000, queries_timerfunc, conn);
}
Esempio n. 27
0
void PurpleContactListMngr::NewBuddyAdded(PurpleBuddy *gBuddy)
{
	PurpleAccount *gAccount = purple_buddy_get_account(gBuddy);
	const char *gPrclId = purple_account_get_protocol_id(gAccount);
	IMAccount *account = _accountMngr->FindIMAccount(purple_account_get_username(gAccount),
		PurpleIMPrcl::GetEnumIMProtocol(gPrclId));
	
	if (account == NULL)
		return;

	PurpleIMContactList *mIMContactList = FindIMContactList(*account);
	if (mIMContactList)
	{
		const char *groupName = FindBuddyGroup(gBuddy);

		if (groupName) 
		{
			mIMContactList->newContactAddedEvent(*mIMContactList, groupName, purple_buddy_get_name(gBuddy));
		}
	}
}
Esempio n. 28
0
static
void cb_custom_edited(GtkCellRendererText *renderer, char *path, char *str, gpointer data)
{
	GtkTreeIter iter;
	GtkTreeModel *model = (GtkTreeModel*) data;
	if (gtk_tree_model_get_iter_from_string(model, &iter, path)) {
                PurpleAccount *account;
                GValue value;
                memset(&value, 0, sizeof(value));
                gtk_tree_model_get_value(model, &iter, 5, &value);
                assert(G_VALUE_HOLDS_POINTER(&value));
                account = g_value_get_pointer(&value);
                g_value_unset(&value);

		char pref[STRLEN];
		build_pref(pref, PREF_CUSTOM_FORMAT, purple_account_get_username(account), purple_account_get_protocol_name(account));

		gtk_list_store_set(GTK_LIST_STORE(model), &iter, 2, str, -1);
		purple_prefs_set_string(pref, str);
	}
}
Esempio n. 29
0
static void _elim_conv_args ( xmlnode *alist, PurpleConversation *conv )
{
    PurpleAccount *acct  = purple_conversation_get_account( conv );
    const char    *aname = purple_account_get_username    ( acct );
    const char    *proto = purple_account_get_protocol_id ( acct );
    const char    *title = purple_conversation_get_title  ( conv );
    const char    *cname = purple_conversation_get_name   ( conv );
    PurpleConnectionFlags  cflag = purple_conversation_get_features( conv );
    PurpleConversationType ctype = purple_conversation_get_type    ( conv );

    fprintf( stderr, "(_elim_conv_args)\n" );
    
    AL_STR ( alist, "account-name" , aname );
    AL_STR ( alist, "im-protocol"  , proto );
    AL_PTR ( alist, "account-uid"  , acct  );
    AL_PTR ( alist, "conv-uid"     , conv  );
    AL_STR ( alist, "conv-name"    , cname );
    AL_STR ( alist, "conv-title"   , title ? title : cname );
    AL_ENUM( alist, "conv-type"    , ctype , ":conversation-type" );
    AL_ENUM( alist, "conv-features", cflag , ":connection-flags"  );    
}
static gchar *
yahoo_ft_url_gen(PurpleXfer *xfer, const gchar *host)
{
	struct yahoo_xfer_data *xfer_data;
	PurpleAccount *account;

	g_return_val_if_fail(host != NULL, NULL);

	xfer_data = purple_xfer_get_protocol_data(xfer);
	account = purple_connection_get_account(xfer_data->gc);

	if (!xfer_data->is_relay) {
		purple_debug_fatal("yahoo", "Non-relay FT aren't tested yet\n");
		return NULL;
	}

	return g_strdup_printf("http://%s/relay?token=%s&sender=%s&recver=%s",
		host, purple_url_encode(xfer_data->xfer_idstring_for_relay),
		purple_normalize(account, purple_account_get_username(account)),
		purple_xfer_get_remote_user(xfer));
}