コード例 #1
0
ファイル: auth.c プロジェクト: ArmoredPidgin/pidgin-hardened
static void auth_old_result_cb(JabberStream *js, const char *from,
                               JabberIqType type, const char *id,
                               PurpleXmlNode *packet, gpointer data)
{
	if (type == JABBER_IQ_RESULT) {
		jabber_stream_set_state(js, JABBER_STREAM_POST_AUTH);
		jabber_disco_items_server(js);
	} else {
		PurpleAccount *account;
		PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
		char *msg = jabber_parse_error(js, packet, &reason);
		PurpleXmlNode *error;
		const char *err_code;

		account = purple_connection_get_account(js->gc);

		/* FIXME: Why is this not in jabber_parse_error? */
		if((error = purple_xmlnode_get_child(packet, "error")) &&
					(err_code = purple_xmlnode_get_attrib(error, "code")) &&
					g_str_equal(err_code, "401")) {
			reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
			/* Clear the pasword if it isn't being saved */
			if (!purple_account_get_remember_password(account))
				purple_account_set_password(account, NULL, NULL, NULL);
		}

		purple_connection_error(js->gc, reason, msg);
		g_free(msg);
	}
}
コード例 #2
0
ファイル: message.c プロジェクト: saljs/sndmsg
int main(int argc, char *argv[])
{

	if(argc < 4)
	{
		printf("Usage: %s [Gtalk username] [password] [recipient address] [message]\n", argv[0]);
		return 1;
	}	
	input_address = argv[3];
	input_message = argv[4];
	GMainLoop *loop = g_main_loop_new(NULL, FALSE);

	/* libpurple's built-in DNS resolution forks processes to perform
	 * blocking lookups without blocking the main process.  It does not
	 * handle SIGCHLD itself, so if the UI does not you quickly get an army
	 * of zombie subprocesses marching around.
	 */
	signal(SIGCHLD, SIG_IGN);

	init_libpurple();

	connect_to_signals();

	PurpleAccount *account = purple_account_new(argv[1], "prpl-jabber");
	purple_account_set_password(account, argv[2]);

	purple_accounts_add(account);
	purple_account_set_enabled(account, UI_ID, TRUE);

	g_main_loop_run(loop);

	return 0;

}
コード例 #3
0
ファイル: auth_cyrus.c プロジェクト: Lilitana/Pidgin
static void auth_pass_cb(PurpleConnection *gc, PurpleRequestFields *fields)
{
	PurpleAccount *account;
	JabberStream *js;
	const char *entry;
	gboolean remember;

	/* The password prompt dialog doesn't get disposed if the account disconnects */
	if (!PURPLE_CONNECTION_IS_VALID(gc))
		return;

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

	if (remember)
		purple_account_set_remember_password(account, TRUE);

	purple_account_set_password(account, entry);

	/* Rebuild our callbacks as we now have a password to offer */
	jabber_sasl_build_callbacks(js);

	/* Restart our negotiation */
	start_cyrus_wrapper(js);
}
コード例 #4
0
ファイル: basic.c プロジェクト: ghetzel/zee
int main(int argc, char *argv[])
{

	GMainLoop *loop = g_main_loop_new(NULL, FALSE);

	/* libpurple's built-in DNS resolution forks processes to perform
	 * blocking lookups without blocking the main process.  It does not
	 * handle SIGCHLD itself, so if the UI does not you quickly get an army
	 * of zombie subprocesses marching around.
	 */
	signal(SIGCHLD, SIG_IGN);

	init_libpurple();

	printf("libpurple initialized. Running version %s.\n", purple_core_get_version()); //I like to see the version number

	connect_to_signals();

	PurpleAccount *account = purple_account_new(PACCOUNT_NAME, "prpl-aim"); //this could be prpl-aim, prpl-yahoo, prpl-msn, prpl-icq, etc.
	purple_account_set_password(account, PACCOUNT_PASS);

	purple_accounts_add(account);
	purple_account_set_enabled(account, UI_ID, TRUE);

	g_main_loop_run(loop);

	return 0;

}
コード例 #5
0
static int account_set_password(LuaState *L)/*{{{*/
{
    PurpleAccount **account = ms_lua_checkclass(L, "purple.account", 1);
    const char *password    = luaL_checkstring(L, 2);
    purple_account_set_password(*account, password);
    return 0;
}/*}}}*/
コード例 #6
0
ファイル: purple.c プロジェクト: AaronVanGeffen/bitlbee
static void purple_login(account_t *acc)
{
	struct im_connection *ic = imcb_new(acc);
	struct purple_data *pd;

	if ((local_bee != NULL && local_bee != acc->bee) ||
	    (global.conf->runmode == RUNMODE_DAEMON && !getenv("BITLBEE_DEBUG"))) {
		imcb_error(ic,  "Daemon mode detected. Do *not* try to use libpurple in daemon mode! "
		           "Please use inetd or ForkDaemon mode instead.");
		imc_logout(ic, FALSE);
		return;
	}
	local_bee = acc->bee;

	/* For now this is needed in the _connected() handlers if using
	   GLib event handling, to make sure we're not handling events
	   on dead connections. */
	purple_connections = g_slist_prepend(purple_connections, ic);

	ic->proto_data = pd = g_new0(struct purple_data, 1);
	pd->account = purple_account_new(acc->user, (char *) acc->prpl->data);
	pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal,
	                                           NULL, g_free);
	pd->next_request_id = 0;
	purple_account_set_password(pd->account, acc->pass);
	purple_sync_settings(acc, pd->account);

	purple_account_set_enabled(pd->account, "BitlBee", TRUE);

	if (set_getbool(&acc->set, "mail_notifications") && set_getstr(&acc->set, "mail_notifications_handle")) {
		imcb_add_buddy(ic, set_getstr(&acc->set, "mail_notifications_handle"), NULL);
	}
}
コード例 #7
0
ファイル: purple.c プロジェクト: GRMrGecko/bitlbee
static void purple_login( account_t *acc )
{
	struct im_connection *ic = imcb_new( acc );
	PurpleAccount *pa;
	
	if( ( local_bee != NULL && local_bee != acc->bee ) ||
	    ( global.conf->runmode == RUNMODE_DAEMON && !getenv( "BITLBEE_DEBUG" ) ) )
	{
		imcb_error( ic,  "Daemon mode detected. Do *not* try to use libpurple in daemon mode! "
		                 "Please use inetd or ForkDaemon mode instead." );
		imc_logout( ic, FALSE );
		return;
	}
	local_bee = acc->bee;
	
	/* For now this is needed in the _connected() handlers if using
	   GLib event handling, to make sure we're not handling events
	   on dead connections. */
	purple_connections = g_slist_prepend( purple_connections, ic );
	
	ic->proto_data = pa = purple_account_new( acc->user, (char*) acc->prpl->data );
	purple_account_set_password( pa, acc->pass );
	purple_sync_settings( acc, pa );
	
	purple_account_set_enabled( pa, "BitlBee", TRUE );
}
コード例 #8
0
ファイル: auth.c プロジェクト: ArmoredPidgin/pidgin-hardened
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);
}
コード例 #9
0
ファイル: quetzalaccount.cpp プロジェクト: akahan/qutim
void QuetzalAccount::load(Config cfg)
{
	cfg.beginGroup(QLatin1String("general"));
	QByteArray password = cfg.value(QLatin1String("passwd"), QString(), Config::Crypted).toUtf8();
	if (!password.isEmpty()) {
		purple_account_set_password(m_account, password.constData());
		purple_account_set_remember_password(m_account, true);
	}
	purple_account_set_alias(m_account, cfg.value(QLatin1String("alias"),
												  QString()).toUtf8().constData());
	purple_account_set_user_info(m_account, cfg.value(QLatin1String("userInfo"),
													  QString()).toUtf8().constData());
	QMapIterator<QString, QVariant> it(cfg.value(QLatin1String("quetzal_settings")).toMap());
	while (it.hasNext()) {
		it.next();
		QByteArray key = it.key().toUtf8();
		QVariant::Type type = it.value().type();
		if (type == QVariant::Bool) {
			purple_account_set_bool(m_account, key.constData(), it.value().toBool());
		} else if (type == QVariant::Int || type == QVariant::UInt
				 || type == QVariant::LongLong || type == QVariant::ULongLong) {
			purple_account_set_int(m_account, key.constData(), it.value().toInt());
		} else {
			purple_account_set_string(m_account, key.constData(), it.value().toString().toUtf8());
		}
	}
	cfg.endGroup();
	
	RosterStorage::instance()->load(this);
	
	int size = cfg.beginArray(QLatin1String("chats"));
	QString name = QLatin1String("name");
	QString recent = QLatin1String("recent");
	QString data = QLatin1String("data");
	for (int i = 0; i < size; i++) {
		cfg.setArrayIndex(i);
		QByteArray alias = cfg.value(name, QString()).toUtf8();
		PurpleGroup *group = NULL;
		if (cfg.value(recent, false)) {
			group = purple_find_group("Recent");
			if (!group) {
				group = purple_group_new("Recent");
				purple_blist_add_group(group, NULL);
			}
		}
		GHashTable *comps = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
		QMapIterator<QString, QVariant> it(cfg.value(data).toMap());
		while (it.hasNext()) {
			it.next();
			QByteArray key = it.key().toUtf8();
			QByteArray value = it.value().toString().toUtf8();
			g_hash_table_insert(comps, g_strdup(key.constData()), g_strdup(value.constData()));
		}
		PurpleChat *pc = purple_chat_new(m_account, alias.constData(), comps);
		purple_blist_add_chat(pc, NULL, NULL);
	}
	
	_purple_buddy_icons_blist_loaded_cb();
}
コード例 #10
0
static void
hangouts_save_refresh_token_password(PurpleAccount *account, const gchar *password)
{
	purple_account_set_password(account, password, NULL, NULL);
	
	if (g_strcmp0(purple_core_get_ui(), "BitlBee") == 0) {
		save_bitlbee_password(account, password);
	}
}
コード例 #11
0
/*------------------------------------------------------------------------
 * 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 );
	}
}
コード例 #12
0
ファイル: purple_ruby.c プロジェクト: strelok1111/purple_ruby
static VALUE login(VALUE self, VALUE protocol, VALUE username, VALUE password)
{
  PurpleAccount* account = purple_account_new(RSTRING_PTR(username), RSTRING_PTR(protocol));
  if (NULL == account || NULL == account->presence) {
    rb_raise(rb_eRuntimeError, "No able to create account: %s", RSTRING_PTR(protocol));
  }
  purple_account_set_password(account, RSTRING_PTR(password));
  purple_account_set_remember_password(account, TRUE);
  purple_account_set_enabled(account, UI_ID, TRUE);
  PurpleSavedStatus *status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
	purple_savedstatus_activate(status);
	purple_accounts_add(account);
	return Data_Wrap_Struct(cAccount, NULL, NULL, account);
}
コード例 #13
0
ファイル: IMInvoker.cpp プロジェクト: juehv/uscxml
void IMInvoker::invoke(void *userdata, const std::string event) {
	_accountMutex.lock();

	EventContext* ctx = (EventContext*)userdata;
	IMInvoker* instance = ctx->instance;

	std::string username;
	Event::getParam(ctx->invokeReq.params, "username", username);
	std::string protocolId;
	Event::getParam(ctx->invokeReq.params, "protocol", protocolId);
	std::string password;
	Event::getParam(ctx->invokeReq.params, "password", password);

	instance->_account = purple_account_new(username.c_str(), protocolId.c_str());
	_accountInstances[instance->_account] = instance;

#if LIBPURPLE_VERSION_MAJOR >= 3
	purple_account_set_password(instance->_account, password.c_str(), NULL, NULL);
#else
	purple_account_set_password(instance->_account, password.c_str());
#endif
	purple_account_set_enabled(instance->_account, "uscxml", true);

	GSList* buddies = purple_blist_get_buddies();
	GSList *cur;
	for (cur = buddies; cur; cur = cur->next) {
		std::string buddyName = purple_buddy_get_name((PurpleBuddy *)cur->data);
		Data buddyData = buddyToData((PurpleBuddy *)cur->data);
		instance->_dataModelVars.compound["buddies"].compound[buddyName] = buddyData;
	}
	g_slist_free(buddies);



	delete(ctx);
	_accountMutex.unlock();
}
コード例 #14
0
ファイル: AccountWindow.cpp プロジェクト: jonyamo/centerim5
void AccountWindow::StringOption::responseHandler(
    CppConsUI::InputDialog& activator,
    AbstractDialog::ResponseType response)
{
  if (response != AbstractDialog::RESPONSE_OK)
    return;

  if (type == TYPE_PASSWORD)
    purple_account_set_password(account, activator.getText());
  else if (type == TYPE_ALIAS)
    purple_account_set_alias(account, activator.getText());
  else
    purple_account_set_string(account,
        purple_account_option_get_setting(option), activator.getText());

  updateValue();
}
コード例 #15
0
ファイル: prpl.c プロジェクト: Draghtnod/pidgin
static void
do_prpl_change_account_status(PurpleAccount *account,
								PurpleStatus *old_status, PurpleStatus *new_status)
{
	PurplePlugin *prpl;
	PurplePluginProtocolInfo *prpl_info;

	if (purple_status_is_online(new_status) &&
		purple_account_is_disconnected(account) &&
		purple_network_is_available())
	{
		purple_account_connect(account);
		return;
	}

	if (!purple_status_is_online(new_status))
	{
		if (!purple_account_is_disconnected(account))
			purple_account_disconnect(account);
		/* Clear out the unsaved password if we're already disconnected and we switch to offline status */
		else if (!purple_account_get_remember_password(account))
			purple_account_set_password(account, NULL);
		return;
	}

	if (purple_account_is_connecting(account))
		/*
		 * We don't need to call the set_status PRPL function because
		 * the PRPL will take care of setting its status during the
		 * connection process.
		 */
		return;

	prpl = purple_find_prpl(purple_account_get_protocol_id(account));

	if (prpl == NULL)
		return;

	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if (!purple_account_is_disconnected(account) && prpl_info->set_status != NULL)
	{
		prpl_info->set_status(account, new_status);
	}
}
コード例 #16
0
static gboolean
purple_connection_disconnect_cb(gpointer data)
{
	PurpleAccount *account;
	PurpleConnection *gc;
	char *password;

	account = data;
	gc = purple_account_get_connection(account);

	if (gc != NULL)
		gc->disconnect_timeout = 0;

	password = g_strdup(purple_account_get_password(account));
	purple_account_disconnect(account);
	purple_account_set_password(account, password);
	g_free(password);

	return FALSE;
}
コード例 #17
0
ファイル: gtkconn.c プロジェクト: Draghtnod/pidgin
static void pidgin_connection_network_disconnected (void)
{
	GList *list, *l;
	PidginBuddyList *gtkblist = pidgin_blist_get_default_gtk_blist();

	if(gtkblist)
		pidgin_status_box_set_network_available(PIDGIN_STATUS_BOX(gtkblist->statusbox), FALSE);

	l = list = purple_accounts_get_all_active();
	while (l) {
		PurpleAccount *a = (PurpleAccount*)l->data;
		if (!purple_account_is_disconnected(a)) {
			char *password = g_strdup(purple_account_get_password(a));
			purple_account_disconnect(a);
			purple_account_set_password(a, password);
			g_free(password);
		}
		l = l->next;
	}
	g_list_free(list);
}
コード例 #18
0
static void
pb_oauth_set_access_token_cb(gpointer data, const gchar *access_token)
{
	PurpleAccount *account = data;
	gchar *real_access_token;
	const gchar *access_token_start;
	const gchar *access_token_end;
	gchar *strtmp;
	
	if (!access_token || !(*access_token)) {
		return;
	}
	
	if((access_token_start = strstr(access_token, "access_token=")))
	{
		access_token_start += 13;
		access_token_end = strchr(access_token_start, '&');
		if (access_token_end)
			real_access_token = g_strndup(access_token_start, access_token_end - access_token_start);
		else
			real_access_token = g_strdup(access_token_start);
		
		strtmp = g_strdup(purple_url_decode(real_access_token));
		g_free(real_access_token);
		real_access_token = strtmp;
	} else {
		real_access_token = g_strdup(access_token);
	}
	
	if (real_access_token && *real_access_token) {
		purple_account_set_remember_password(account, TRUE);
		purple_account_set_password(account, real_access_token);
		
		purple_account_set_enabled(account, purple_core_get_ui(), TRUE);
		purple_account_connect(account);
	}
	
	g_free(real_access_token);
}
コード例 #19
0
ファイル: clientaccount.c プロジェクト: 4N7HR4X/kamailio
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;
}
コード例 #20
0
ファイル: nullclient.c プロジェクト: kristopolous/taim
int parse(char*toParse, char*ret_buffer, char**uid)
{
  char command = -1,
       *pCur,
       *pPrev;

  int ix,
      Bound = TK__LAST;

  taim_session *ses;

  pCur = toParse;

  for(ix = 0; ix < Bound; ix++)
  {
    if(!strncmp(pCur, g_commands[ix], strlen(g_commands[ix])))
    {
      command = ix;
      pCur += strlen(g_commands[ix]);
      break;
    }
  }

  switch(command) {
    case TK_UID:
      if(*pCur == ' ') {
        pCur++;
        pPrev = pCur;
        while(*pCur > 32) {
          pCur ++;
        }
        *uid = (char*) malloc(pCur - pPrev);
        memcpy(*uid, pPrev, pCur - pPrev);
        (*uid)[pCur - pPrev] = 0;
      } else {
        *uid = 0;

        do {
          if(*uid != 0)
          {
            free(*uid);
          }
          *uid = (char*) malloc(KEY_LENGTH + 1);
          memcpy(*uid, generate_uid(), KEY_LENGTH);
        } while(uid_addsession(*uid) == 0);
      }

      memcpy(ret_buffer, *uid, strlen(*uid));
      sprintf(ret_buffer + strlen(*uid) + 1, "\n");
      return RET_NODATA;
      break;

    case TK_USER:
      pCur++;

      pPrev = pCur;
      while(*pCur > 32 ) {
        pCur++;
      }
      *uid = (char*)malloc(pCur - pPrev + 1);
      memcpy(*uid, pPrev, pCur - pPrev);
      (*uid)[pCur - pPrev] = 0;
      ses = uid_find(*uid);
      pCur ++;

      {
        char *username = pCur;

        for(	ix = 0;
            username[ix] > ' ';
            ix++);

        username[ix] = 0;

        GList *iter = purple_plugins_get_protocols();
        PurplePlugin *plugin = iter->data;
        PurplePluginInfo *info = plugin->info;
        printf("<%x>", (unsigned int)ses);
        fflush(0);

        if(ses->pses->account == 0) {
          taim_new_account(ses);
        }
        d(username);
        ses->pses->account->account = purple_account_new(username, info->id);
      }
      return RET_NODATA;
      break;

    case TK_PASS:
      pCur++;

      pPrev = pCur;
      while(*pCur > 32 ) {
        pCur++;
      }
      *uid = (char*)malloc(pCur - pPrev + 1);
      memcpy(*uid, pPrev, pCur - pPrev);
      (*uid)[pCur - pPrev] = 0;
      pCur ++;
      ses = uid_find(*uid);

      {
        PurpleSavedStatus *status;

        char	*password = pCur,
              hash[20];

        for(ix = 0; password[ix] > ' '; ix++);

        password[ix] = 0;

        if(ses->pses->account->hash_have == 1) {
          // See if the hashes match
          if(!memcmp(SHA1(password, strlen(password), hash), ses->pses->account->hash, 20)) {
            // If so, then bond the stuff
          }
          else
            // Otherwise, try to auth anyway
          {
            strcpy(ses->pses->account->password_try, password);
          }
          purple_account_set_password(ses->pses->account->account, password);
          purple_account_set_enabled(ses->pses->account->account, UI_ID, TRUE);
          // Either way, this password is replaced with the new one
        } else {
          strcpy(ses->pses->account->password_try, password);
          purple_account_set_password(ses->pses->account->account, password);
          purple_account_set_enabled(ses->pses->account->account, UI_ID, TRUE);
        }

        // Now, to connect the account(s), create a status and activate it. 
        status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
        purple_savedstatus_activate(status);
        pthread_mutex_unlock(&g_mutex_init);
      }	
      return RET_NODATA;
      break;

    case TK_GET:
      pCur++;

      pPrev = pCur;
      while(*pCur > 32 ) {
        pCur++;
      }

      *uid = (char*)malloc(pCur - pPrev + 1);
      memcpy(*uid, pPrev, pCur - pPrev);
      (*uid)[pCur - pPrev] = 0;
      pCur ++;

      if((*uid)[0]) {
        d(*uid);
        drecurse(g_blist->root, *uid);
        return RET_DATA;
      } else {
        return RET_NODATA;
      }
      break;

    case TK_SEND:
      pCur++;

      pPrev = pCur;
      while(*pCur > 32 ) {
        pCur++;
      }

      *uid = (char*)malloc(pCur - pPrev + 1);
      memcpy(*uid, pPrev, pCur - pPrev);
      (*uid)[pCur - pPrev] = 0;
      pCur ++;

      pCur[strlen(pCur) - 1] = 0;
      taim_send(pCur, *uid, ret_buffer);
      return RET_NODATA;
      break;

    case TK_QUIT:
      do_exit();
      break;

    default:
      return RET_ERROR;
      // unknown command
      break;
  }
  return RET_ERROR;
}
コード例 #21
0
ファイル: account.c プロジェクト: crater2150/mimoc
void mimoc_account_save_pass(PurpleAccount *account, char *password)
{
	purple_account_set_password(account, password);
	purple_account_set_remember_password(account, TRUE);
}
コード例 #22
0
ファイル: session.c プロジェクト: N8Fear/purple-facebook
void
msn_session_set_error(MsnSession *session, MsnErrorType error,
					  const char *info)
{
	PurpleConnection *gc;
	PurpleConnectionError reason;
	char *msg;

	if (session->destroying)
		return;

	gc = purple_account_get_connection(session->account);

	switch (error)
	{
		case MSN_ERROR_SERVCONN:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(info);
			break;
		case MSN_ERROR_UNSUPPORTED_PROTOCOL:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("Our protocol is not supported by the "
							 "server"));
			break;
		case MSN_ERROR_HTTP_MALFORMED:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("Error parsing HTTP"));
			break;
		case MSN_ERROR_SIGN_OTHER:
			reason = PURPLE_CONNECTION_ERROR_NAME_IN_USE;
			msg = g_strdup(_("You have signed on from another location"));
			if (!purple_account_get_remember_password(session->account))
				purple_account_set_password(session->account, NULL, NULL, NULL);
			break;
		case MSN_ERROR_SERV_UNAVAILABLE:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("The MSN servers are temporarily "
							 "unavailable. Please wait and try "
							 "again."));
			break;
		case MSN_ERROR_SERV_DOWN:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("The MSN servers are going down "
							 "temporarily"));
			break;
		case MSN_ERROR_AUTH:
			reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
			msg = g_strdup_printf(_("Unable to authenticate: %s"),
								  (info == NULL ) ?
								  _("Unknown error") : info);
			/* Clear the password if it isn't being saved */
			if (!purple_account_get_remember_password(session->account))
				purple_account_set_password(session->account, NULL, NULL, NULL);
			break;
		case MSN_ERROR_BAD_BLIST:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup_printf(_("Your MSN buddy list is temporarily "
			                        "unavailable: %s"),
			                      (info == NULL) ? _("Unknown error") : info);
			break;
		default:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("Unknown error"));
			break;
	}

	msn_session_disconnect(session);

	purple_connection_error(gc, reason, msg);

	g_free(msg);
}
コード例 #23
0
ファイル: clientlogin.c プロジェクト: jrcjc/chimein
/**
 * This function parses the given response from a clientLogin request
 * and extracts the useful information.
 *
 * @param gc           The PurpleConnection.  If the response data does
 *                     not indicate then purple_connection_error_reason()
 *                     will be called to close this connection.
 * @param response     The response data from the clientLogin request.
 * @param response_len The length of the above response, or -1 if
 *                     @response is NUL terminated.
 * @param token        If parsing was successful then this will be set to
 *                     a newly allocated string containing the token.  The
 *                     caller should g_free this string when it is finished
 *                     with it.  On failure this value will be untouched.
 * @param secret       If parsing was successful then this will be set to
 *                     a newly allocated string containing the secret.  The
 *                     caller should g_free this string when it is finished
 *                     with it.  On failure this value will be untouched.
 * @param hosttime     If parsing was successful then this will be set to
 *                     the time on the OpenAuth Server in seconds since the
 *                     Unix epoch.  On failure this value will be untouched.
 *
 * @return TRUE if the request was successful and we were able to
 *         extract all info we need.  Otherwise FALSE.
 */
static gboolean parse_client_login_response(PurpleConnection *gc, const gchar *response, gsize response_len, char **token, char **secret, time_t *hosttime)
{
    xmlnode *response_node, *tmp_node, *data_node;
    xmlnode *secret_node = NULL, *hosttime_node = NULL, *token_node = NULL, *tokena_node = NULL;
    char *tmp;

    /* Parse the response as XML */
    response_node = xmlnode_from_str(response, response_len);
    if (response_node == NULL)
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin could not parse "
                           "response as XML: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        return FALSE;
    }

    /* Grab the necessary XML nodes */
    tmp_node = xmlnode_get_child(response_node, "statusCode");
    data_node = xmlnode_get_child(response_node, "data");
    if (data_node != NULL) {
        secret_node = xmlnode_get_child(data_node, "sessionSecret");
        hosttime_node = xmlnode_get_child(data_node, "hostTime");
        token_node = xmlnode_get_child(data_node, "token");
        if (token_node != NULL)
            tokena_node = xmlnode_get_child(token_node, "a");
    }

    /* Make sure we have a status code */
    if (tmp_node == NULL || (tmp = xmlnode_get_data_unescaped(tmp_node)) == NULL) {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was "
                           "missing statusCode: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        xmlnode_free(response_node);
        return FALSE;
    }

    /* Make sure the status code was 200 */
    if (strcmp(tmp, "200") != 0)
    {
        int status_code, status_detail_code = 0;

        status_code = atoi(tmp);
        g_free(tmp);
        tmp_node = xmlnode_get_child(response_node, "statusDetailCode");
        if (tmp_node != NULL && (tmp = xmlnode_get_data_unescaped(tmp_node)) != NULL) {
            status_detail_code = atoi(tmp);
            g_free(tmp);
        }

        purple_debug_error("oscar", "clientLogin response statusCode "
                           "was %d (%d): %s\n", status_code, status_detail_code, response);

        if (status_code == 330 && status_detail_code == 3011) {
            PurpleAccount *account = purple_connection_get_account(gc);
            if (!purple_account_get_remember_password(account))
                purple_account_set_password(account, NULL);
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
                                           _("Incorrect password"));
        } else if (status_code == 330 && status_detail_code == 3015) {
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
                                           _("Server requested that you fill out a CAPTCHA in order to "
                                             "sign in, but this client does not currently support CAPTCHAs."));
        } else if (status_code == 401 && status_detail_code == 3019) {
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_OTHER_ERROR,
                                           _("AOL does not allow your screen name to authenticate here"));
        } else {
            char *msg;
            msg = generate_error_message(response_node,
                                         URL_CLIENT_LOGIN);
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_OTHER_ERROR, msg);
            g_free(msg);
        }

        xmlnode_free(response_node);
        return FALSE;
    }
    g_free(tmp);

    /* Make sure we have everything else */
    if (data_node == NULL || secret_node == NULL ||
            token_node == NULL || tokena_node == NULL)
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was missing "
                           "something: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        xmlnode_free(response_node);
        return FALSE;
    }

    /* Extract data from the XML */
    *token = xmlnode_get_data_unescaped(tokena_node);
    *secret = xmlnode_get_data_unescaped(secret_node);
    tmp = xmlnode_get_data_unescaped(hosttime_node);
    if (*token == NULL || **token == '\0' || *secret == NULL || **secret == '\0' || tmp == NULL || *tmp == '\0')
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was missing "
                           "something: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        g_free(*token);
        g_free(*secret);
        g_free(tmp);
        xmlnode_free(response_node);
        return FALSE;
    }

    *hosttime = strtol(tmp, NULL, 10);
    g_free(tmp);

    xmlnode_free(response_node);

    return TRUE;
}
コード例 #24
0
ファイル: flap_connection.c プロジェクト: Draghtnod/pidgin
static gboolean
flap_connection_destroy_cb(gpointer data)
{
	FlapConnection *conn;
	OscarData *od;
	PurpleAccount *account;
	aim_rxcallback_t userfunc;

	conn = data;
	/* Explicitly added for debugging #5927.  Don't re-order this, only
	 * consider removing it.
	 */
	purple_debug_info("oscar", "Destroying FLAP connection %p\n", conn);

	od = conn->od;
	account = purple_connection_get_account(od->gc);

	purple_debug_info("oscar", "Destroying oscar connection (%p) of "
			"type 0x%04hx.  Disconnect reason is %d\n", conn,
			conn->type, conn->disconnect_reason);

	od->oscar_connections = g_slist_remove(od->oscar_connections, conn);

	if ((userfunc = aim_callhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR)))
		userfunc(od, conn, NULL, conn->disconnect_code, conn->error_message);

	/*
	 * TODO: If we don't have a SNAC_FAMILY_LOCATE connection then
	 * we should try to request one instead of disconnecting.
	 */
	if (!account->disconnecting && ((od->oscar_connections == NULL)
			|| (!flap_connection_getbytype(od, SNAC_FAMILY_LOCATE))))
	{
		/* No more FLAP connections!  Sign off this PurpleConnection! */
		gchar *tmp;
		PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;

		if (conn->disconnect_code == 0x0001) {
			reason = PURPLE_CONNECTION_ERROR_NAME_IN_USE;
			tmp = g_strdup(_("You have signed on from another location"));
			if (!purple_account_get_remember_password(account))
				purple_account_set_password(account, NULL);
		} else if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED)
			tmp = g_strdup(_("Server closed the connection"));
		else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION)
			tmp = g_strdup_printf(_("Lost connection with server: %s"),
					conn->error_message);
		else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA)
			tmp = g_strdup(_("Received invalid data on connection with server"));
		else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT)
			tmp = g_strdup_printf(_("Unable to connect: %s"),
					conn->error_message);
		else
			/*
			 * We shouldn't print a message for some disconnect_reasons.
			 * Like OSCAR_DISCONNECT_LOCAL_CLOSED.
			 */
			tmp = NULL;

		if (tmp != NULL)
		{
			purple_connection_error_reason(od->gc, reason, tmp);
			g_free(tmp);
		}
	}

	flap_connection_close(od, conn);

	g_free(conn->error_message);
	g_free(conn->cookie);

	/*
	 * Free conn->internal, if necessary
	 */
	if (conn->type == SNAC_FAMILY_CHAT)
		flap_connection_destroy_chat(od, conn);

	g_slist_free(conn->groups);
	while (conn->rateclasses != NULL)
	{
		g_free(conn->rateclasses->data);
		conn->rateclasses = g_slist_delete_link(conn->rateclasses, conn->rateclasses);
	}

	g_hash_table_destroy(conn->rateclass_members);

	if (conn->queued_snacs) {
		while (!g_queue_is_empty(conn->queued_snacs))
		{
			QueuedSnac *queued_snac;
			queued_snac = g_queue_pop_head(conn->queued_snacs);
			flap_frame_destroy(queued_snac->frame);
			g_free(queued_snac);
		}
		g_queue_free(conn->queued_snacs);
	}

	if (conn->queued_lowpriority_snacs) {
		while (!g_queue_is_empty(conn->queued_lowpriority_snacs))
		{
			QueuedSnac *queued_snac;
			queued_snac = g_queue_pop_head(conn->queued_lowpriority_snacs);
			flap_frame_destroy(queued_snac->frame);
			g_free(queued_snac);
		}
		g_queue_free(conn->queued_lowpriority_snacs);
	}

	if (conn->queued_timeout > 0)
		purple_timeout_remove(conn->queued_timeout);

	g_free(conn);

	return FALSE;
}
コード例 #25
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 );
	}
}
コード例 #26
0
int main(int argc, char *argv[])
{
	GList *iter;
	int i, num;
	GList *names = NULL;
	const char *prpl;
	char name[128];
	char *password;
	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
	PurpleAccount *account;
	PurpleSavedStatus *status;
	char *res;

#ifndef _WIN32
	/* libpurple's built-in DNS resolution forks processes to perform
	 * blocking lookups without blocking the main process.  It does not
	 * handle SIGCHLD itself, so if the UI does not you quickly get an army
	 * of zombie subprocesses marching around.
	 */
	signal(SIGCHLD, SIG_IGN);
#endif

	init_libpurple();

	printf("libpurple initialized.\n");

	iter = purple_plugins_get_protocols();
	for (i = 0; iter; iter = iter->next) {
		PurplePlugin *plugin = iter->data;
		PurplePluginInfo *info = plugin->info;
		if (info && info->name) {
			printf("\t%d: %s\n", i++, info->name);
			names = g_list_append(names, info->id);
		}
	}
	printf("Select the protocol [0-%d]: ", i-1);
	res = fgets(name, sizeof(name), stdin);
	if (!res) {
		fprintf(stderr, "Failed to gets protocol selection.");
		abort();
	}
	sscanf(name, "%d", &num);
	prpl = g_list_nth_data(names, num);

	printf("Username: "******"Failed to read user name.");
		abort();
	}
	name[strlen(name) - 1] = 0;  /* strip the \n at the end */


	/* Create the account */
	account = purple_account_new(name, prpl);

	/* Get the password for the account */
	password = getpass("Password: ");
	purple_account_set_password(account, password);

	/* It's necessary to enable the account first. */
	purple_account_set_enabled(account, UI_ID, TRUE);

	/* Now, to connect the account(s), create a status and activate it. */
	status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
	purple_savedstatus_activate(status);

	connect_to_signals_for_demonstration_purposes_only();

	g_main_loop_run(loop);

	return 0;
}