Exemple #1
0
static TCHAR* parseLastSeenStatus(ARGUMENTSINFO *ai)
{
	if (ai->argc != 2)
		return NULL;

	MCONTACT hContact = NULL;
	CONTACTSINFO ci = { 0 };
	ci.cbSize = sizeof(ci);
	ci.tszContact = ai->targv[1];
	ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
	int count = getContactFromString(&ci);
	if ((count == 1) && (ci.hContacts != NULL)) {
		hContact = ci.hContacts[0];
		mir_free(ci.hContacts);
	}
	else {
		mir_free(ci.hContacts);
		return NULL;
	}
	char *szModule = SEEN_MODULE;
	int status = db_get_w(hContact, szModule, "Status", 0);
	if (status == 0)
		return NULL;

	TCHAR *szStatus = pcli->pfnGetStatusModeDescription(status, 0);
	if (szStatus != NULL)
		return mir_tstrdup(szStatus);

	return NULL;
}
Exemple #2
0
static TCHAR* parseContact(ARGUMENTSINFO *ai)
{
	if (ai->argc < 3 || ai->argc > 4)
		return NULL;

	int n = 0;
	if (ai->argc == 4 && *ai->targv[3] != 'r')
		n = ttoi(ai->targv[3]) - 1;

	CONTACTSINFO ci = { 0 };
	ci.cbSize = sizeof(ci);
	ci.tszContact = ai->targv[1];
	ci.flags = getContactInfoFlags(ai->targv[2]);
	int count = getContactFromString(&ci);
	if (count == 0 || ci.hContacts == NULL)
		return NULL;

	if (ai->argc == 4 && *ai->targv[3] == 'r')
		n = rand() % count;

	if (count != 1 && ai->argc != 4) {
		mir_free(ci.hContacts);
		return NULL;
	}
	MCONTACT hContact = ci.hContacts[n];
	log_debugA("contact: %x", hContact);
	mir_free(ci.hContacts);

	return encodeContactToString(hContact);
}
Exemple #3
0
static TCHAR* parseContactInfo(ARGUMENTSINFO *ai)
{
	if (ai->argc != 3)
		return NULL;

	MCONTACT hContact = NULL;
	CONTACTSINFO ci = { 0 };
	ci.cbSize = sizeof(ci);
	ci.tszContact = ai->targv[1];
	ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
	int count = getContactFromString(&ci);
	if (count == 1 && ci.hContacts != NULL) {
		hContact = ci.hContacts[0];
		mir_free(ci.hContacts);
	}
	else {
		mir_free(ci.hContacts);
		return NULL;
	}
	BYTE type = getContactInfoType(ai->targv[2]);
	if (type == 0)
		return NULL;

	return getContactInfoT(type, hContact);
}
static TCHAR *parseGetDefault(ARGUMENTSINFO *ai)
{
	if (ai->argc != 2)
		return NULL;

	MCONTACT hContact = NULL;

	CONTACTSINFO ci = { 0 };
	ci.cbSize = sizeof(ci);
	ci.tszContact = ai->targv[1];
	ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
	int count = getContactFromString(&ci);
	if (count == 1 && ci.hContacts != NULL) {
		hContact = ci.hContacts[0];
		mir_free(ci.hContacts);
	}
	else {
		mir_free(ci.hContacts);
		return NULL;
	}

	hContact = db_mc_getDefault(hContact);
	if (hContact == NULL)
		return NULL;

	TCHAR* szUniqueID = NULL;
	char* szProto = GetContactProto(hContact);
	if (szProto != NULL)
		szUniqueID = getContactInfoT(CNF_UNIQUEID, hContact);

	if (szUniqueID == NULL) {
		szProto = PROTOID_HANDLE;
		szUniqueID = (TCHAR *)mir_alloc(32);
		mir_sntprintf(szUniqueID, 32, _T("%p"), hContact);
		if (szProto == NULL || szUniqueID == NULL)
			return NULL;
	}

	size_t size = strlen(szProto) + _tcslen(szUniqueID) + 4;
	TCHAR *res = (TCHAR *)mir_alloc(size * sizeof(TCHAR));
	if (res == NULL) {
		mir_free(szUniqueID);
		return NULL;
	}

	TCHAR *tszProto = mir_a2t(szProto);
	if (tszProto != NULL && szUniqueID != NULL) {
		mir_sntprintf(res, size, _T("<%s:%s>"), tszProto, szUniqueID);
		mir_free(szUniqueID);
		mir_free(tszProto);
	}

	return res;
}
Exemple #5
0
static TCHAR* parseLastSeenTime(ARGUMENTSINFO *ai)
{
	if (ai->argc <= 1)
		return NULL;

	MCONTACT hContact = NULL;

	CONTACTSINFO ci = { 0 };
	ci.cbSize = sizeof(ci);
	ci.tszContact = ai->targv[1];
	ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
	int count = getContactFromString(&ci);
	if (count == 1 && ci.hContacts != NULL) {
		hContact = ci.hContacts[0];
		mir_free(ci.hContacts);
	}
	else {
		mir_free(ci.hContacts);
		return NULL;
	}

	TCHAR *szFormat;
	if (ai->argc == 2 || (ai->argc > 2 && mir_tstrlen(ai->targv[2]) == 0))
		szFormat = NULL;
	else
		szFormat = ai->targv[2];

	SYSTEMTIME lsTime = { 0 };
	char *szModule = SEEN_MODULE;
	lsTime.wYear = db_get_w(hContact, szModule, "Year", 0);
	if (lsTime.wYear == 0)
		return NULL;

	lsTime.wMilliseconds = 0;
	lsTime.wSecond = db_get_w(hContact, szModule, "Seconds", 0);
	lsTime.wMinute = db_get_w(hContact, szModule, "Minutes", 0);
	lsTime.wHour = db_get_w(hContact, szModule, "Hours", 0);
	lsTime.wDay = db_get_w(hContact, szModule, "Day", 0);
	lsTime.wDayOfWeek = db_get_w(hContact, szModule, "WeekDay", 0);
	lsTime.wMonth = db_get_w(hContact, szModule, "Month", 0);
	lsTime.wYear = db_get_w(hContact, szModule, "Year", 0);

	int len = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &lsTime, szFormat, NULL, 0);
	TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR));
	if (res == NULL)
		return NULL;

	if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, &lsTime, szFormat, res, len) == 0) {
		mir_free(res);
		return NULL;
	}

	return res;
}
Exemple #6
0
static TCHAR* parseContactCount(ARGUMENTSINFO *ai)
{
	if (ai->argc != 3)
		return NULL;

	CONTACTSINFO ci = { 0 };
	ci.cbSize = sizeof(ci);
	ci.tszContact = ai->targv[1];
	ci.flags = getContactInfoFlags(ai->targv[2]);
	int count = getContactFromString(&ci);
	if (count != 0 && ci.hContacts != NULL)
		mir_free(ci.hContacts);

	return itot(count);
}
Exemple #7
0
// returns a contact from a string in the form <PROTOID:UNIQUEID>
// returns INVALID_HANDLE_VALUE in case of an error.
MCONTACT decodeContactFromString(TCHAR *tszContact)
{
	MCONTACT hContact = INVALID_CONTACT_ID;
	CONTACTSINFO ci = { sizeof(ci) };
	ci.tszContact = tszContact;
	ci.flags = CI_PROTOID|CI_TCHAR;
	int count = getContactFromString( &ci );
	if (count != 1) {
		mir_free(ci.hContacts);
		return hContact;
	}

	if (ci.hContacts != NULL) {
		hContact = ci.hContacts[0];
		mir_free(ci.hContacts);
	}

	return hContact;
}
static TCHAR *parseGetParent(ARGUMENTSINFO *ai)
{
	if (ai->argc != 2)
		return NULL;

	MCONTACT hContact = NULL;

	CONTACTSINFO ci = { sizeof(ci) };
	ci.tszContact = ai->targv[1];
	ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
	int count = getContactFromString(&ci);
	if (count == 1 && ci.hContacts != NULL) {
		hContact = ci.hContacts[0];
		mir_free(ci.hContacts);
	}
	else {
		mir_free(ci.hContacts);
		return NULL;
	}

	hContact = db_mc_getMeta(hContact);
	if (hContact == NULL)
		return NULL;

	ptrT szUniqueID;
	char* szProto = GetContactProto(hContact);
	if (szProto != NULL)
		szUniqueID = getContactInfoT(CNF_UNIQUEID, hContact);

	if (szUniqueID == NULL) {
		szProto = PROTOID_HANDLE;
		TCHAR tszID[40];
		mir_sntprintf(tszID, SIZEOF(tszID), _T("%p"), hContact);
		szUniqueID = mir_tstrdup(tszID);
	}

	if (szUniqueID == NULL)
		return NULL;

	return mir_tstrdup(CMString(FORMAT, _T("<%S:%s>"), szProto, szUniqueID));
}
Exemple #9
0
static TCHAR* parseDBSetting(ARGUMENTSINFO *ai)
{
	if (ai->argc < 4)
		return NULL;

	MCONTACT hContact = NULL;
	if (mir_tstrlen(ai->targv[1]) > 0) {
		CONTACTSINFO ci = { 0 };
		ci.cbSize = sizeof(ci);
		ci.tszContact = ai->targv[1];
		ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
		int count = getContactFromString(&ci);
		if (count == 1 && ci.hContacts != NULL) {
			hContact = ci.hContacts[0];
			mir_free(ci.hContacts);
		}
		else {
			mir_free(ci.hContacts);
			return NULL;
		}
	}

	char *szModule = mir_t2a(ai->targv[2]);
	if (szModule == NULL)
		return NULL;

	char *szSetting = mir_t2a(ai->targv[3]);
	if (szSetting == NULL) {
		mir_free(szModule);
		return NULL;
	}

	TCHAR *szDefaultValue = ((ai->argc > 4 && mir_tstrlen(ai->targv[4]) > 0) ? mir_tstrdup(ai->targv[4]) : NULL);
	TCHAR *res = getDBSetting(hContact, szModule, szSetting, szDefaultValue);
	mir_free(szDefaultValue);
	mir_free(szSetting);
	mir_free(szModule);
	return res;
}
Exemple #10
0
// ?message(%subject%,last|first,sent|recv,read|unread)
static TCHAR* parseDbEvent(ARGUMENTSINFO *ai)
{
	if (ai->argc != 5)
		return NULL;

	int flags = DBE_MESSAGE;
	switch (*ai->targv[2]) {
	case 'f':
		flags |= DBE_FIRST;
		break;
	default:
		flags |= DBE_LAST;
		break;
	}
	switch (*ai->targv[3]) {
	case 's':
		flags |= DBE_SENT;
		break;
	case 'r':
		flags |= DBE_RCVD;
		break;
	default:
		flags |= DBE_RCVD | DBE_SENT;
		break;
	}
	switch (*ai->targv[4]) {
	case 'r':
		flags |= DBE_READ;
		break;
	case 'u':
		flags |= DBE_UNREAD;
		break;
	default:
		flags |= DBE_READ | DBE_UNREAD;
		break;
	}

	MCONTACT hContact = NULL;

	CONTACTSINFO ci = { 0 };
	ci.cbSize = sizeof(ci);
	ci.tszContact = ai->targv[1];
	ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
	int count = getContactFromString(&ci);
	if ((count == 1) && (ci.hContacts != NULL)) {
		hContact = ci.hContacts[0];
		mir_free(ci.hContacts);
	}
	else if (ci.hContacts != NULL)
		mir_free(ci.hContacts);

	MEVENT hDbEvent = findDbEvent(hContact, NULL, flags);
	if (hDbEvent == NULL)
		return NULL;

	DBEVENTINFO dbe = { sizeof(dbe) };
	dbe.cbBlob = db_event_getBlobSize(hDbEvent);
	dbe.pBlob = (PBYTE)mir_calloc(dbe.cbBlob);
	if (db_event_get(hDbEvent, &dbe)) {
		mir_free(dbe.pBlob);
		return NULL;
	}

	TCHAR *res = DbGetEventTextT(&dbe, CP_ACP);
	mir_free(dbe.pBlob);
	return res;
}