コード例 #1
0
ファイル: clientpipe.c プロジェクト: mattvv/kamailio
static void pipe_handle_publish(struct purple_publish *publish) {
	PurpleAccount *account = NULL;
	extern_account_t *accounts = NULL;
	int naccounts = 0;
	int i;

	LM_DBG("calling find_accounts(\"%s\", &naccoutns)\n", publish->from);
	accounts = find_accounts(publish->from, &naccounts);
	LM_DBG("found %d extra account(s) for <%s>", naccounts, publish->from);

	for (i = 0; i < naccounts; i++) {
		LM_DBG("calling client_find_account(\"%s\")\n", accounts[i].username);
		account = client_find_account(&accounts[i]);
		if (account) {
		
			if (publish->basic == PURPLE_BASIC_OPEN) {
				client_enable_account(account);
				LM_DBG("basic = open, setting up new status... %s,%d,%s\n", account[i].username, publish->primitive, publish->note);
				PurpleStatusType *type = purple_account_get_status_type_with_primitive(account, publish->primitive);
				if (purple_status_type_get_attr(type, "message")) {
					purple_account_set_status(account, purple_status_type_get_id(type), TRUE, "message", publish->note, NULL);
				} else {
					purple_account_set_status(account, purple_status_type_get_id(type), TRUE, NULL);
				}
			}

			else if (publish->basic == PURPLE_BASIC_CLOSED){
				LM_DBG("basic = closed, setting up new status to offline... %s\n", account[i].username);
				PurpleStatusType *type = purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_OFFLINE);
				purple_account_set_status(account, purple_status_type_get_id(type), TRUE, NULL);
			}
			
		}
	}

	if (accounts)
		extern_account_free(accounts, naccounts);

}
コード例 #2
0
ファイル: musicinfo.c プロジェクト: rbalik/musicinfo
// update the info for the connection gc
// prevInfo and prevStat are the previously set data for that account (so we don't keep setting the same thing over)
char* updateInfo(PurpleConnection *gc, char* prevInfo, char* title, char* artist, gboolean isPlaying, gboolean updateStatus)
{
	PurpleAccount* account;

	char* curAcct;
	char* statusText = NULL;
	char* servStatusText = NULL;
	const char* sid = NULL;
	const char* acctInfo = NULL;
	gboolean hasStatus = FALSE;

	account = purple_connection_get_account(gc);

	acctInfo = purple_account_get_user_info(account);

	if(acctInfo != NULL)
	{
		curAcct = g_strdup(acctInfo);
	}
	else
	{
		curAcct = g_strdup("\0");
	}

	hasStatus = getStatusText(&statusText, &servStatusText, account, &sid);

	if(isPlaying)
	{
		//replace the appropriate text
		replaceText(&curAcct, start_songText, "\0");
		replaceText(&curAcct, end_songText, "\0");
		replaceText(&curAcct, artist_replace, artist);
		replaceText(&curAcct, title_replace, title);

		//hide everything in the "no song" tag
		hideBetween(&curAcct, start_noSongText, end_noSongText);

		//and do it for the status
		if(hasStatus)
		{
			replaceText(&statusText, start_songText, "\0");
			replaceText(&statusText, end_songText, "\0");
			replaceText(&statusText, artist_replace, artist);
			replaceText(&statusText, title_replace, title);

			hideBetween(&statusText, start_noSongText, end_noSongText);
		}
	}
	else
	{
		//replace the appropriate text
		replaceText(&curAcct, start_noSongText, "\0");
		replaceText(&curAcct, end_noSongText, "\0");

		//hide everything in the song tag
		hideBetween(&curAcct, start_songText, end_songText);

		//and for the status:
		if(hasStatus)
		{
			replaceText(&statusText, start_noSongText, "\0");
			replaceText(&statusText, end_noSongText, "\0");

			hideBetween(&statusText, start_songText, end_songText);
		}
	}


	//this is so we don't update the server if we don't have to
	if(strcmp(curAcct, prevInfo) != 0)
	{
		serv_set_info(gc, curAcct);
	}
	if(hasStatus)
	{
		if(updateStatus || strcmp(statusText, servStatusText) != 0)
		{
			under_recursion = TRUE;
			purple_account_set_status(account, sid, TRUE, "message", statusText, NULL);
			under_recursion = FALSE;
		}
		g_free(statusText);
		g_free(servStatusText);
	}
	return curAcct;
}