Ejemplo n.º 1
0
/*
 * helpers
 */
static PurpleConnection *get_nullprpl_gc(const char *username) {
  PurpleAccount *acct = purple_accounts_find(username, NULLPRPL_ID);
  if (acct && purple_account_is_connected(acct))
    return purple_account_get_connection(acct);
  else
    return NULL;
}
Ejemplo n.º 2
0
static void
purplemot_chat_invite(PurpleConnection *gc, int id, const char *message,
    const char *who)
{
  const char *username = gc->account->username;
  PurpleConversation *conv = purple_find_chat(gc, id);
  const char *room = conv->name;
  PurpleAccount *to_acct = purple_accounts_find(who, PURPLEMOT_ID);

  purple_debug_info("purplemot", "%s is inviting %s to join chat room %s\n",
                    username, who, room);

  if (to_acct) {
    PurpleConversation *to_conv = purple_find_chat(to_acct->gc, id);
    if (to_conv) {
      char *tmp = g_strdup_printf("%s is already in chat room %s.", who, room);
      purple_debug_info("purplemot",
                        "%s is already in chat room %s; "
                        "ignoring invitation from %s\n",
                        who, room, username);
      purple_notify_info(gc, _("Chat invitation"), _("Chat invitation"), tmp);
      g_free(tmp);
    } else {
      GHashTable *components;
      components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
      g_hash_table_replace(components, "room", g_strdup(room));
      g_hash_table_replace(components, "invited_by", g_strdup(username));
      serv_got_chat_invite(to_acct->gc, room, username, message, components);
    }
  }
}
Ejemplo n.º 3
0
static void
dologin_named(const char *name)
{
	PurpleAccount *account;
	char **names;
	int i;

	if (name != NULL) { /* list of names given */
		names = g_strsplit(name, ",", 64);
		for (i = 0; names[i] != NULL; i++) {
			account = purple_accounts_find(names[i], NULL);
			if (account != NULL) { /* found a user */
				purple_account_set_enabled(account, PIDGIN_UI, TRUE);
			}
		}
		g_strfreev(names);
	} else { /* no name given, use the first account */
		GList *accounts;

		accounts = purple_accounts_get_all();
		if (accounts != NULL)
		{
			account = (PurpleAccount *)accounts->data;
			purple_account_set_enabled(account, PIDGIN_UI, TRUE);
		}
	}
}
Ejemplo n.º 4
0
static void
message_source_activated(MessagingMenuApp *app, const gchar *id,
		gpointer user_data)
{
	gchar **sections = g_strsplit(id, ":", 0);
	PurpleConversation *conv = NULL;
	PurpleAccount *account;
	PidginConvWindow *purplewin = NULL;

	char *type     = sections[0];
	char *cname    = sections[1];
	char *aname    = sections[2];
	char *protocol = sections[3];

	account = purple_accounts_find(aname, protocol);

	if (g_strcmp0(type, "im") == 0)
		conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(cname, account));
	else if (g_strcmp0(type, "chat") == 0)
		conv = PURPLE_CONVERSATION(purple_conversations_find_chat_with_account(cname, account));
	else
		conv = purple_conversations_find_with_account(cname, account);

	if (conv) {
		unalert(conv);
		purplewin = PIDGIN_CONVERSATION(conv)->win;
		pidgin_conv_window_switch_gtkconv(purplewin, PIDGIN_CONVERSATION(conv));
		gdk_window_focus(gtk_widget_get_window(purplewin->window), time(NULL));
	}
	g_strfreev (sections);
}
Ejemplo n.º 5
0
static void nullprpl_chat_invite(PurpleConnection *gc, int id,
                                 const char *message, const char *who) {
  const char *username = purple_account_get_username(purple_connection_get_account(gc));
  PurpleChatConversation *chat = purple_conversations_find_chat(gc, id);
  const char *room = purple_conversation_get_name(PURPLE_CONVERSATION(chat));
  PurpleAccount *to_acct = purple_accounts_find(who, NULLPRPL_ID);

  purple_debug_info("nullprpl", "%s is inviting %s to join chat room %s\n",
                    username, who, room);

  if (to_acct) {
    PurpleChatConversation *to_conv = purple_conversations_find_chat(purple_account_get_connection(to_acct), id);
    if (to_conv) {
      char *tmp = g_strdup_printf("%s is already in chat room %s.", who, room);
      purple_debug_info("nullprpl",
                        "%s is already in chat room %s; "
                        "ignoring invitation from %s\n",
                        who, room, username);
      purple_notify_info(gc, _("Chat invitation"), _("Chat invitation"), tmp,
                         purple_request_cpar_from_conversation(PURPLE_CONVERSATION(to_conv)));
      g_free(tmp);
    } else {
      GHashTable *components;
      components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
      g_hash_table_replace(components, "room", g_strdup(room));
      g_hash_table_replace(components, "invited_by", g_strdup(username));
      purple_serv_got_chat_invite(purple_account_get_connection(to_acct), room, username, message, components);
    }
  }
}
Ejemplo n.º 6
0
static void nullprpl_get_info(PurpleConnection *gc, const char *username) {
  const char *body;
  PurpleNotifyUserInfo *info = purple_notify_user_info_new();
  PurpleAccount *acct;

  purple_debug_info("nullprpl", "Fetching %s's user info for %s\n", username,
                    purple_account_get_username(purple_connection_get_account(gc)));

  acct = purple_accounts_find(username, NULLPRPL_ID);

  if (!get_nullprpl_gc(username)) {
    char *msg = g_strdup_printf(_("%s is not logged in."), username);
    purple_notify_error(gc, _("User Info"), _("User info not available. "), msg,
                        purple_request_cpar_from_account(acct));
    g_free(msg);
  }

  if (acct)
    body = purple_account_get_user_info(acct);
  else
    body = _("No user info.");
  /* TODO: Check whether it's correct to call add_pair_html,
           or if we should be using add_pair_plaintext */
  purple_notify_user_info_add_pair_html(info, "Info", body);

  /* show a buddy's user info in a nice dialog box */
  purple_notify_userinfo(gc,        /* connection the buddy info came through */
                         username,  /* buddy's username */
                         info,      /* body */
                         NULL,      /* callback called when dialog closed */
                         NULL);     /* userdata for callback */
}
Ejemplo n.º 7
0
static void
purplemot_get_info(PurpleConnection *gc, const char *username)
{
  const char *body;
  PurpleNotifyUserInfo *info = purple_notify_user_info_new();
  PurpleAccount *acct;

  purple_debug_info("purplemot", "Fetching %s's user info for %s\n", username,
                    gc->account->username);

  if (!get_purplemot_gc(username)) {
    char *msg = g_strdup_printf(_("%s is not logged in."), username);
    purple_notify_error(gc, _("User Info"), _("User info not available. "), msg);
    g_free(msg);
  }

  acct = purple_accounts_find(username, PURPLEMOT_ID);
  if (acct)
    body = purple_account_get_user_info(acct);
  else
    body = _("No user info.");
  purple_notify_user_info_add_pair(info, "Info", body);

  /* show a buddy's user info in a nice dialog box */
  purple_notify_userinfo(gc,        /* connection the buddy info came through */
                         username,  /* buddy's username */
                         info,      /* body */
                         NULL,      /* callback called when dialog closed */
                         NULL);     /* userdata for callback */
}
Ejemplo n.º 8
0
PurpleAccount *flist_deserialize_account(const gchar *lookup) {
    const gchar *name;

    name = g_hash_table_lookup(string_to_account, lookup);
    if(!name) return NULL;

    return purple_accounts_find(name, FLIST_PLUGIN_ID);
}
Ejemplo n.º 9
0
static PurpleConnection *
get_purplemot_gc(const char *username)
{
  PurpleAccount *acct = purple_accounts_find(username, PURPLEMOT_ID);
  if (acct && purple_account_is_connected(acct))
    return acct->gc;
  else
    return NULL;
}
Ejemplo n.º 10
0
/* a timer based callback function that sends the next message in the queue */
static gboolean
send_message_timer_cb( message_to_conv *msg_to_conv ) {
	PurpleAccount *account;
	PurpleConversation *conv;
	gchar *msg;

	g_return_val_if_fail(msg_to_conv                     != NULL, FALSE);
	g_return_val_if_fail(msg_to_conv->messages           != NULL, FALSE);
	g_return_val_if_fail(msg_to_conv->sender_username    != NULL, FALSE);
	g_return_val_if_fail(msg_to_conv->sender_protocol_id != NULL, FALSE);

	msg = g_queue_pop_head(msg_to_conv->messages);

	if( msg == NULL )
	{
		/* clean up and terminate timer callback */
		g_queue_free(msg_to_conv->messages);
		g_free(msg_to_conv->sender_username);
		g_free(msg_to_conv->sender_protocol_id);
		if( msg_to_conv->type == PURPLE_CONV_TYPE_IM &&
			msg_to_conv->receiver != NULL )
		g_free(msg_to_conv->receiver);

		g_free(msg_to_conv);

		return FALSE;
	}
	else
	{
		/* find account info (it may have changed) and try and create a new
		   conversation window (it may have been closed) or find the existing
		   chat, and finally send the message */
		account = purple_accounts_find(msg_to_conv->sender_username,
					     msg_to_conv->sender_protocol_id);
		g_return_val_if_fail(account != NULL, FALSE);

		if( msg_to_conv->type == PURPLE_CONV_TYPE_IM && msg_to_conv->receiver != NULL )
			conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, msg_to_conv->receiver);
		else if( msg_to_conv->type == PURPLE_CONV_TYPE_CHAT )
			conv = purple_find_chat(account->gc, msg_to_conv->id);
		else
			conv = NULL;

		g_return_val_if_fail(conv != NULL, FALSE);

		splitter_common_send(conv, msg, PURPLE_MESSAGE_SEND);
		g_free(msg);

		return TRUE;
	}
}
Ejemplo n.º 11
0
static int
purplemot_send_im(PurpleConnection *gc, const char *who, const char *message,
    PurpleMessageFlags flags)
{
  const char *from_username = gc->account->username;
  PurpleMessageFlags receive_flags = ((flags & ~PURPLE_MESSAGE_SEND)
                                      | PURPLE_MESSAGE_RECV);
  PurpleAccount *to_acct = purple_accounts_find(who, PURPLEMOT_ID);
  PurpleConnection *to;

  purple_debug_info("purplemot", "sending message from %s to %s: %s\n",
                    from_username, who, message);

  /* is the sender blocked by the recipient's privacy settings? */
  if (to_acct && !purple_privacy_check(to_acct, gc->account->username)) {
    char *msg = g_strdup_printf(
      _("Your message was blocked by %s's privacy settings."), who);
    purple_debug_info("purplemot",
                      "discarding; %s is blocked by %s's privacy settings\n",
                      from_username, who);
    purple_conv_present_error(who, gc->account, msg);
    g_free(msg);
    return 0;
  }

  /* is the recipient online? */
  to = get_purplemot_gc(who);
  if (to) {  /* yes, send */

    serv_got_im(to, from_username, message, receive_flags, time(NULL));

  } else {  /* nope, store as an offline message */
    GOfflineMessage *offline_message;
    GList *messages;

    purple_debug_info("purplemot",
                      "%s is offline, sending as offline message\n", who);
    offline_message = g_new0(GOfflineMessage, 1);
    offline_message->from = g_strdup(from_username);
    offline_message->message = g_strdup(message);
    offline_message->mtime = time(NULL);
    offline_message->flags = receive_flags;

    messages = g_hash_table_lookup(goffline_messages, who);
    messages = g_list_append(messages, offline_message);
    g_hash_table_insert(goffline_messages, g_strdup(who), messages);
  }

   return 1;
}
void TestPidginIm::testSendIQ(PurplePluginAction* action) {
	const char* fromName = "test@localhost/QAS";
	const char* toName = "xuewen@localhost/winxp";
	const char* protocol = "prpl-jabber";
	PurpleAccount * account = purple_accounts_find(fromName, protocol);
	if (!account) {
		purple_debug_info("TestQAS Test file", "find accout faile");
		return;
	}

	PurpleConnection * conn = purple_account_get_connection(account);
	PurplePluginProtocolInfo * prpl = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(conn));
	prpl->send_raw(conn, msg, strlen(msg));
	prpl->send_raw(conn, iq, strlen(iq));
}
Ejemplo n.º 13
0
xmlnode * _h_elim_send_file ( 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"  );
    
    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" );
    }

    PurpleConnection *conn = purple_account_get_connection( acct );

    if( !conn )
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "account not online" );
    }

    // file can be NULL, but that's Ok, it just triggers a req to the user:
    const char *b_arg = ALIST_VAL_STRING( args, "recipient" );
    const char *file  = ALIST_VAL_STRING( args, "filename"  );

    serv_send_file( conn, b_arg, file );

    // bname is a static buf allocated in purple_normalize: don't free it!
    // also, this means that bname is volatile, so use it immediately after
    // acquiring it, if you make any calls into libpurple they might invalidate
    // its state:
    const char *bname = purple_normalize( acct, b_arg );
    xmlnode    *rval  = xnode_new( "alist" );
    AL_PTR( rval, "account-uid" , acct  );
    AL_STR( rval, "recipient"   , bname );

    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
Ejemplo n.º 14
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 );
}
Ejemplo n.º 15
0
static void
dropdown_changed_cb(GtkComboBox *widget, gpointer nul)
{
	PurpleAccount *account;

	if (!console)
		return;

	account = purple_accounts_find(gtk_combo_box_get_active_text(GTK_COMBO_BOX(console->dropdown)),
				    "prpl-jabber");
	if (!account || !account->gc)
		return;

	console->gc = account->gc;
	gtk_imhtml_clear(GTK_IMHTML(console->imhtml));
}
Ejemplo n.º 16
0
static int account_find(LuaState *L)/*{{{*/
{
    luaL_checktype(L, 1, LUA_TTABLE);
    const char *name     = luaL_checkstring(L, 2);
    const char *protocol = luaL_checkstring(L, 3);

    PurpleAccount *account = purple_accounts_find(name, protocol);
    if (account) {
        lua_pushlightuserdata(L, account);
        lua_gettable(L, LUA_REGISTRYINDEX);
    }
    else {
        lua_pushboolean(L, FALSE);
    }

    return 1;
}/*}}}*/
Ejemplo n.º 17
0
PurpleAccount *client_find_account(extern_account_t *account) {
	PurpleAccount *r;

	char* plugin;
	char username[255];
	memset(username, 0, 255);

	if (strcmp(account->protocol, "gtalk") == 0) {
		sprintf(username, "%s%s", account->username, "/sip");
		plugin = "prpl-jabber";
	}
	else {
		sprintf(username, "%s", account->username);
		plugin = account->protocol;
	}
	

	LM_DBG("searching purple account for %s with plugin %s \n", username, plugin);
	r = purple_accounts_find(username, plugin);
	if (r) {
		LM_DBG("account %s found\n", username);
		return r;
	}

	LM_DBG("account %s not found, creating.\n", username);
	r = purple_account_new(username, plugin);
	purple_account_set_password(r, account->password);
	purple_account_set_remember_password(r, TRUE);

	if (proxy != NULL)
		purple_account_set_proxy_info(r, proxy);

	if (strcmp(account->protocol, "gtalk") == 0)
		purple_account_set_string(r, "connect_server", "talk.google.com");

	purple_accounts_add(r);
	
	return r;
}
Ejemplo n.º 18
0
/* Send an OTR Query Message to attempt to start a connection */
void otrg_ui_connect_connection(ConnContext *context)
{
    /* Send an OTR Query to the other side. */
    PurpleAccount *account;
    char *msg;
	
    /* Don't do this if we're already ENCRYPTED */
    if (context == NULL || context->msgstate == OTRL_MSGSTATE_ENCRYPTED)
	return;
	
    account = purple_accounts_find(context->accountname, context->protocol);
    if (!account) {
	PurplePlugin *p = purple_find_prpl(context->protocol);
	msg = g_strdup_printf(_("Account %s (%s) could not be found"),
		  context->accountname,
		  (p && p->info->name) ? p->info->name : _("Unknown"));
	otrg_dialog_notify_error(context->accountname, context->protocol,
		context->username, _("Account not found"), msg, NULL);
	g_free(msg);
	return;
    }
    otrg_plugin_send_default_query(context, account);	
}
Ejemplo n.º 19
0
static PurpleAccount *find_acct(const char *prpl, const char *acct_id)
{
	PurpleAccount *acct = NULL;

	/* If we have a specific acct, use it */
	if (acct_id) {
		acct = purple_accounts_find(acct_id, prpl);
		if (acct && !purple_account_is_connected(acct))
			acct = NULL;
	} else { /* Otherwise find an active account for the protocol */
		GList *l = purple_accounts_get_all();
		while (l) {
			if (!strcmp(prpl, purple_account_get_protocol_id(l->data))
					&& purple_account_is_connected(l->data)) {
				acct = l->data;
				break;
			}
			l = l->next;
		}
	}

	return acct;
}
Ejemplo n.º 20
0
static void
end_element_handler(GMarkupParseContext *context, const gchar *element_name,
					gpointer user_data,  GError **error)
{
	PounceParserData *data = user_data;
	gchar *buffer = NULL;

	if (data->buffer != NULL) {
		buffer = g_string_free(data->buffer, FALSE);
		data->buffer = NULL;
	}

	if (purple_strequal(element_name, "account")) {
		g_free(data->account_name);
		data->account_name = g_strdup(buffer);
	}
	else if (purple_strequal(element_name, "pouncee")) {
		g_free(data->pouncee);
		data->pouncee = g_strdup(buffer);
	}
	else if (purple_strequal(element_name, "option")) {
		if (purple_strequal(data->option_type, "on-away"))
			data->options |= PURPLE_POUNCE_OPTION_AWAY;

		g_free(data->option_type);
		data->option_type = NULL;
	}
	else if (purple_strequal(element_name, "event")) {
		if (purple_strequal(data->event_type, "sign-on"))
			data->events |= PURPLE_POUNCE_SIGNON;
		else if (purple_strequal(data->event_type, "sign-off"))
			data->events |= PURPLE_POUNCE_SIGNOFF;
		else if (purple_strequal(data->event_type, "away"))
			data->events |= PURPLE_POUNCE_AWAY;
		else if (purple_strequal(data->event_type, "return-from-away"))
			data->events |= PURPLE_POUNCE_AWAY_RETURN;
		else if (purple_strequal(data->event_type, "idle"))
			data->events |= PURPLE_POUNCE_IDLE;
		else if (purple_strequal(data->event_type, "return-from-idle"))
			data->events |= PURPLE_POUNCE_IDLE_RETURN;
		else if (purple_strequal(data->event_type, "start-typing"))
			data->events |= PURPLE_POUNCE_TYPING;
		else if (purple_strequal(data->event_type, "typed"))
			data->events |= PURPLE_POUNCE_TYPED;
		else if (purple_strequal(data->event_type, "stop-typing"))
			data->events |= PURPLE_POUNCE_TYPING_STOPPED;
		else if (purple_strequal(data->event_type, "message-received"))
			data->events |= PURPLE_POUNCE_MESSAGE_RECEIVED;

		g_free(data->event_type);
		data->event_type = NULL;
	}
	else if (purple_strequal(element_name, "action")) {
		if (data->pounce != NULL) {
			purple_pounce_action_register(data->pounce, data->action_name);
			purple_pounce_action_set_enabled(data->pounce, data->action_name, TRUE);
		}

		g_free(data->action_name);
		data->action_name = NULL;
	}
	else if (purple_strequal(element_name, "param")) {
		if (data->pounce != NULL) {
			purple_pounce_action_set_attribute(data->pounce, data->action_name,
											 data->param_name, buffer);
		}

		g_free(data->param_name);
		data->param_name = NULL;
	}
	else if (purple_strequal(element_name, "events")) {
		PurpleAccount *account;

		account = purple_accounts_find(data->account_name, data->protocol_id);

		g_free(data->account_name);
		g_free(data->protocol_id);

		data->account_name = NULL;
		data->protocol_id  = NULL;

		if (account == NULL) {
			purple_debug(PURPLE_DEBUG_ERROR, "pounce",
					   "Account for pounce not found!\n");
			/*
			 * This pounce has effectively been removed, so make
			 * sure that we save the changes to pounces.xml
			 */
			schedule_pounces_save();
		}
		else {
			purple_debug(PURPLE_DEBUG_INFO, "pounce",
					   "Creating pounce: %s, %s\n", data->ui_name,
					   data->pouncee);

			data->pounce = purple_pounce_new(data->ui_name, account,
										   data->pouncee, data->events,
										   data->options);
		}

		g_free(data->pouncee);
		data->pouncee = NULL;
	}
	else if (purple_strequal(element_name, "save")) {
		if (data->pounce != NULL)
			purple_pounce_set_save(data->pounce, TRUE);
	}
	else if (purple_strequal(element_name, "pounce")) {
		data->pounce  = NULL;
		data->events  = 0;
		data->options = 0;

		g_free(data->ui_name);
		g_free(data->pouncee);
		g_free(data->protocol_id);
		g_free(data->event_type);
		g_free(data->option_type);
		g_free(data->action_name);
		g_free(data->param_name);
		g_free(data->account_name);

		data->ui_name      = NULL;
		data->pounce       = NULL;
		data->protocol_id  = NULL;
		data->event_type   = NULL;
		data->option_type  = NULL;
		data->action_name  = NULL;
		data->param_name   = NULL;
		data->account_name = NULL;
	}

	g_free(buffer);
}
Ejemplo n.º 21
0
static PurpleAccount* get_account_from_ruby_object(VALUE acc){
	PurpleAccount* account = NULL;
	Data_Get_Struct( acc, PurpleAccount, account );
	return purple_accounts_find(account->username,account->protocol_id);
}
Ejemplo n.º 22
0
/*------------------------------------------------------------------------
 * Handle an URI clicked on the UI
 *
 * @param link	the link name which has been clicked
 */
static void* mxit_link_click( const char* link64 )
{
	PurpleAccount*		account;
	PurpleConnection*	gc;
	gchar**				parts		= NULL;
	gchar*				link		= NULL;
	gsize				len;
	gboolean			is_command	= FALSE;

	purple_debug_info( MXIT_PLUGIN_ID, "mxit_link_click (%s)\n", link64 );

	if ( g_ascii_strncasecmp( link64, MXIT_LINK_PREFIX, strlen( MXIT_LINK_PREFIX ) ) != 0 ) {
		/* this is not for us */
		goto skip;
	}

	/* decode the base64 payload */
	link = (gchar*) purple_base64_decode( link64 + strlen( MXIT_LINK_PREFIX ), &len );
	purple_debug_info( MXIT_PLUGIN_ID, "Clicked Link: '%s'\n", link );

	parts = g_strsplit( link, "|", 6 );

	/* check if this is a valid mxit link */
	if ( ( !parts ) || ( !parts[0] ) || ( !parts[1] ) || ( !parts[2] ) || ( !parts[3] ) || ( !parts[4] ) || ( !parts[5] ) ) {
		/* this is not for us */
		goto skip;
	}
	else if ( g_ascii_strcasecmp( parts[0], MXIT_LINK_KEY ) != 0 ) {
		/* this is not for us */
		goto skip;
	}

	/* find the account */
	account = purple_accounts_find( parts[1], parts[2] );
	if ( !account )
		goto skip;
	gc = purple_account_get_connection( account );
	if ( !gc )
		goto skip;

	/* determine if it's a command-response to send */
	is_command = ( atoi( parts[4] ) == 1 );

	/* send click message back to MXit */
	mxit_send_message( purple_connection_get_protocol_data( gc ), parts[3], parts[5], FALSE, is_command );

	g_free( link );
	link = NULL;
	g_strfreev( parts );
	parts = NULL;

	return (void*) link64;

skip:
	/* this is not an internal mxit link */

	if ( link )
		g_free( link );
	link = NULL;

	if ( parts )
		g_strfreev( parts );
	parts = NULL;

	if ( mxit_pidgin_uri_cb )
		return mxit_pidgin_uri_cb( link64 );
	else
		return (void*) link64;
}
Ejemplo n.º 23
0
xmlnode * _h_elim_add_buddy ( const char *name ,
                              const char *id   ,
                              SEXP_VALUE *args ,
                              gpointer data    )
{
    ASSERT_ALISTP( args, id, name );

    elim_ping();
    
    int         loopc = 0;
    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"  );

    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" );
    }

    const char *b_arg = ALIST_VAL_STRING( args, "bnode-name" );
    const char *bname = purple_normalize( acct, b_arg        );
    const char *gname = ALIST_VAL_STRING( args, "group"      );
    if( !gname || !*gname ) gname = "Buddies";

    PurpleGroup *group = purple_group_new( gname );
    PurpleBuddy *buddy = purple_buddy_new( acct, bname, b_arg );
    PurpleBuddy *clone = NULL;
    //fprintf( stderr, "add-buddy( b: %p, g: %p )\n", buddy, group );
    // remove other references to this buddy
    purple_blist_add_buddy  ( buddy, NULL, group, NULL );
    purple_account_add_buddy( acct , buddy );
    while( ( clone = (PurpleBuddy*)find_blist_node_clone( buddy ) ) )
    {
        if( loopc++ > 99   ) 
        {
            fprintf( stderr, "ARGH! clone reaping looped: %d\n", loopc );
            break;
        }
        if( clone == buddy ) 
        { 
            fprintf( stderr, "ARGH! %p not a clone of %p\n", buddy, clone );
            break;
        }
        fprintf( stderr, "(removing clone %p %ld (of buddy: %p)\n", 
                 clone, (long)clone, buddy );
        fprintf( stderr, "   name : %s\n", purple_buddy_get_name(clone) );
        fprintf( stderr, "   group: %s)\n", 
                 purple_group_get_name( purple_buddy_get_group(clone) ) );
        purple_blist_remove_buddy( clone );
    }

    xmlnode *rval = xnode_new( "alist" );
    AL_PTR( rval, "account-uid" , acct  );
    AL_PTR( rval, "bnode-uid"   , buddy );
    AL_PTR( rval, "group-uid"   , group );
    AL_STR( rval, "bnode-name"  , purple_buddy_get_name         ( buddy ) );
    AL_STR( rval, "bnode-alias" , purple_buddy_get_alias        ( buddy ) );
    AL_STR( rval, "account-name", purple_account_get_username   ( acct  ) );
    AL_STR( rval, "im-protocol" , purple_account_get_protocol_id( acct  ) );
    AL_STR( rval, "group-name"  , purple_group_get_name         ( group ) );

    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
Ejemplo n.º 24
0
xmlnode * _h_elim_add_chat( 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"  );
    const char *alias   = ALIST_VAL_STR  ( args, "chat-alias"   );
    gpointer    auid    = ALIST_VAL_PTR  ( args, "account-uid"  );
    GHashTable *opts    = ALIST_VAL_ALIST( args, "chat-options" );
    GHashTable *options = __ghash_str_sexp__str_str( opts );
    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" );
    }

    // cook up a chat node. if it's already on our buddy list, uncook it
    // and use the old one instead (name should be unique per account
    // so the operation is reasonable - we cannot supply a name as this
    // parameter can be delegated to the plugin to generate automatically):
    // this will trigger a new_node call, and possibly a remove call 
    PurpleChat *chat = purple_chat_new( acct, alias, options );
    const char *chn  = purple_chat_get_name( chat );
    PurpleChat *ch_2 = purple_blist_find_chat( acct, chn );
    if( ch_2 )
    {
        fprintf( stderr, "(elim-debug chat already exists)\n" );
        purple_blist_remove_chat( chat );
        chat = ch_2;
        chn  = purple_chat_get_name( chat );
        purple_blist_alias_chat( chat, alias );
    }

    fprintf( stderr, "(elim-debug adding chat to blist)\n" );
    purple_blist_add_chat( chat, NULL, NULL );

    // if we have a conversation already, prod the client to show it
    fprintf( stderr, "(elim-debug looking for conversation)\n" );
    PurpleConversation *conv =
      purple_find_conversation_with_account( PURPLE_CONV_TYPE_CHAT, chn, acct );
    if( conv )
        purple_conversation_present( conv );

    xmlnode *rval = xnode_new( "alist" );

    AL_STR( rval, "account-name", purple_account_get_username   (acct) );
    AL_STR( rval, "im-protocol" , purple_account_get_protocol_id(acct) );
    AL_PTR( rval, "account-uid" , acct );
    AL_STR( rval, "chat-name"   , chn  );

    if( conv )
    {
        PurpleConversationType pct = purple_conversation_get_type    ( conv );
        PurpleConnectionFlags  pcf = purple_conversation_get_features( conv );

        AL_PTR ( rval, "conv-uid"     , conv );
        AL_STR ( rval, "conv-name"    , purple_conversation_get_name (conv) );
        AL_STR ( rval, "conv-title"   , purple_conversation_get_title(conv) );
        AL_ENUM( rval, "conv-type"    , pct, ":conversation-type" );
        AL_ENUM( rval, "conv-features", pcf, ":connection-flags"  );
    }

    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
Ejemplo n.º 25
0
xmlnode * _h_elim_message ( const char *name ,
                            const char *id   ,
                            SEXP_VALUE *args ,
                            gpointer data    )
{
    fprintf(stderr, "(elim-debug entered _h_elim_message)");
    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"  );

    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" );
    }

    PurpleConversationType pt = PURPLE_CONV_TYPE_UNKNOWN;
    gpointer             cuid = ALIST_VAL_PTR( args, "conv-uid"  );
    const char         *cname = ALIST_VAL_STR( args, "conv-name" );
    PurpleConversation    *pc = find_conv_by_acct_uid( acct, cuid );

    if  ( pc ) pt = purple_conversation_get_type( pc );
    else
    {
        pt = PURPLE_CONV_TYPE_ANY;
        pc = purple_find_conversation_with_account( pt, cname, acct );
        if( !pc )
        {
            pt = PURPLE_CONV_TYPE_IM;
            pc = purple_conversation_new( pt, acct, cname );
        }
        else { pt = purple_conversation_get_type( pc ); }
    }

    if( !pc )
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "new conversation failed" );
    }

    PurpleConvIm   *pci = NULL;
    PurpleConvChat *pcc = NULL;
    const char     *msg = ALIST_VAL_STRING( args, "text" );
    char           *esc = g_markup_escape_text( msg, -1 );
    int             len = strlen( esc );

    switch( pt )
    {
      case PURPLE_CONV_TYPE_IM:
        pci = purple_conversation_get_im_data( pc );
        purple_conv_im_send( pci, esc );
        break;
      case PURPLE_CONV_TYPE_CHAT:
        pcc = purple_conversation_get_chat_data( pc );
        purple_conv_chat_send( pcc, esc );
        break;
      default:
        g_free       ( esc  );
        sexp_val_free( args );
        return response_error( EINVAL, id, name, "unknown conversation type" );
    }

    xmlnode *rval = xnode_new( "alist" );
    AL_INT( rval, "bytes"    , len     );
    AL_PTR( rval, "conv-uid" , pc      );
    AL_STR( rval, "conv-name", purple_conversation_get_name(pc) );

    g_free       ( esc  );
    sexp_val_free( args );
    fprintf(stderr, "(elim-debug leaving _h_elim_message)");
    return response_value( 0, id, name, rval );
}
Ejemplo n.º 26
0
//-----------------------------------------------------------------------------
//static
PurpleAccount* PurpleIMChat::getPurpleAccount( const IMAccount& imAccount )
{
	return purple_accounts_find( imAccount.getLogin().c_str(), PurpleIMPrcl::GetPrclId( imAccount.getProtocol() ) );
}
Ejemplo n.º 27
0
xmlnode * _h_elim_command ( const char *name ,
                            const char *id   ,
                            SEXP_VALUE *args ,
                            gpointer data    )
{
    fprintf(stderr, "(elim-debug entered _h_elim_command)");
    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"  );

    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" );
    }

    PurpleConversationType pt = PURPLE_CONV_TYPE_UNKNOWN;
    gpointer             cuid = ALIST_VAL_PTR( args, "conv-uid"  );
    const char         *cname = ALIST_VAL_STR( args, "conv-name" );
    PurpleConversation    *pc = find_conv_by_acct_uid( acct, cuid );

    if  ( pc ) pt = purple_conversation_get_type( pc );
    else
    {
        pt = PURPLE_CONV_TYPE_ANY;
        pc = purple_find_conversation_with_account( pt, cname, acct );
        if( !pc )
        {
            sexp_val_free( args );
            return response_error( ENOENT, id, name, "conversation not found" );
        }
        else { pt = purple_conversation_get_type( pc ); }
    }

    PurpleCmdStatus c_s = PURPLE_CMD_STATUS_FAILED;
    const char     *cmd = ALIST_VAL_STRING( args, "command" );
    char           *esc = g_markup_escape_text( cmd, -1 );
    char           *err = NULL;
    const char   *error = NULL;
    c_s = purple_cmd_do_command( pc, cmd, esc, &err );

    if( c_s != PURPLE_CMD_STATUS_OK && (!err || !*err) )
        switch( c_s )
        {
          case PURPLE_CMD_STATUS_FAILED    :
            error = "Command failed";
            break;
          case PURPLE_CMD_STATUS_NOT_FOUND :
            error = "Command not found";
            break;
          case PURPLE_CMD_STATUS_WRONG_ARGS:
            error = "Bad command arguments";
            break;
          case PURPLE_CMD_STATUS_WRONG_PRPL:
            error = "Command not valid for this IM protocol";
            break;
          case PURPLE_CMD_STATUS_WRONG_TYPE:
            error = "Command not valid in this conversation";
            break;
          default:
            error = "Unknown command error";
        }

    xmlnode *rval = xnode_new( "alist" );
    AL_PTR ( rval, "conv-uid"      , pc  );
    AL_STR ( rval, "conv-name"     , purple_conversation_get_name(pc) );

    AL_ENUM( rval, "command-status", c_s , ":cmd-status" );
    AL_STR ( rval, "command-error" , err ? err : error   );
    AL_STR ( rval, "command-line"  , cmd );

    g_free       ( err  );
    g_free       ( esc  );
    sexp_val_free( args );

    fprintf(stderr, "(elim-debug leaving _h_elim_command)");
    return response_value( 0, id, name, rval );
}
Ejemplo n.º 28
0
PurpleAccount* PurpleIMContactList::getPurpleAccount( PurpleIMContactList* imContactList )
{
	return purple_accounts_find( imContactList->getIMAccount().getLogin().c_str(), 
							     PurpleIMPrcl::GetPrclId(imContactList->getIMAccount().getProtocol()));
}
Ejemplo n.º 29
0
bool GlooxRegisterHandler::unregisterUser(const std::string &barejid) {
	UserRow res = Transport::instance()->sql()->getUserByJid(barejid);
	// This user is already registered
	if (res.id == -1)
		return false;

	Log("GlooxRegisterHandler", "removing user " << barejid << " from database and disconnecting from legacy network");
	PurpleAccount *account = NULL;
	
	AbstractUser *user = Transport::instance()->userManager()->getUserByJID(barejid);
	if (user && user->hasFeature(GLOOX_FEATURE_ROSTERX) && false) {
		std::cout << "* sending rosterX\n";
		Tag *tag = new Tag("message");
		tag->addAttribute( "to", barejid );
		std::string _from;
		_from.append(Transport::instance()->jid());
		tag->addAttribute( "from", _from );
		tag->addChild(new Tag("body","removing users"));
		Tag *x = new Tag("x");
		x->addAttribute("xmlns","http://jabber.org/protocol/rosterx");

		std::list <std::string> roster;
		roster = Transport::instance()->sql()->getBuddies(res.id);

		Tag *item;
		for(std::list<std::string>::iterator u = roster.begin(); u != roster.end() ; u++){
			std::string name = *u;
			item = new Tag("item");
			item->addAttribute("action", "delete");
			item->addAttribute("jid", name + "@" + Transport::instance()->jid());
			x->addChild(item);
		}

		tag->addChild(x);
		Transport::instance()->send(tag);
	}
	else {
		std::list <std::string> roster;
		// roster contains already escaped jids
		roster = Transport::instance()->sql()->getBuddies(res.id);

		Tag *tag;
		for(std::list<std::string>::iterator u = roster.begin(); u != roster.end() ; u++){
			std::string name = *u;

			tag = new Tag("presence");
			tag->addAttribute( "to", barejid );
			tag->addAttribute( "type", "unsubscribe" );
			tag->addAttribute( "from", name + "@" + Transport::instance()->jid());
			Transport::instance()->send( tag );

			tag = new Tag("presence");
			tag->addAttribute( "to", barejid );
			tag->addAttribute( "type", "unsubscribed" );
			tag->addAttribute( "from", name + "@" + Transport::instance()->jid());
			Transport::instance()->send( tag );
		}
	}

	// Remove user from database
	if (res.id != -1) {
		Transport::instance()->sql()->removeUser(res.id);
	}

	// Disconnect the user
	if (user != NULL) {
		account = user->account();
		Transport::instance()->userManager()->removeUser(user);	
	}

	if (!account) {
		account = purple_accounts_find(res.uin.c_str(), Transport::instance()->protocol()->protocol().c_str());
	}

#ifndef TESTS
	// Remove account from memory
	if (account)
		Transport::instance()->collector()->collectNow(account, true);
#endif

	Tag *reply = new Tag( "presence" );
	reply->addAttribute( "type", "unsubscribe" );
	reply->addAttribute( "from", Transport::instance()->jid() );
	reply->addAttribute( "to", barejid );
	Transport::instance()->send( reply );

	reply = new Tag("presence");
	reply->addAttribute( "type", "unsubscribed" );
	reply->addAttribute( "from", Transport::instance()->jid() );
	reply->addAttribute( "to", barejid );
	Transport::instance()->send( reply );

	return true;
}