Пример #1
0
HANDLE GGPROTO::SearchBasic(const TCHAR *id)
{
	if (!isonline())
		return 0;

	gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);
	if (!req) {
#ifdef DEBUGMODE
		debugLogA("SearchBasic(): ForkThread 10 GGPROTO::searchthread");
#endif
		ForkThread(&GGPROTO::searchthread, NULL);
		return (HANDLE)1;
	}

	// Add uin and search it
	gg_pubdir50_add(req, GG_PUBDIR50_UIN, T2Utf(id));
	gg_pubdir50_seq_set(req, GG_SEQ_SEARCH);

	gg_EnterCriticalSection(&sess_mutex, "SearchBasic", 50, "sess_mutex", 1);
	if (!gg_pubdir50(sess, req))
	{
		gg_LeaveCriticalSection(&sess_mutex, "SearchBasic", 50, 1, "sess_mutex", 1);
#ifdef DEBUGMODE
		debugLogA("SearchBasic(): ForkThread 11 GGPROTO::searchthread");
#endif
		ForkThread(&GGPROTO::searchthread, NULL);
		return (HANDLE)1;
	}
	gg_LeaveCriticalSection(&sess_mutex, "SearchBasic", 50, 2, "sess_mutex", 1);
	debugLogA("SearchBasic(): Seq %d.", req->seq);
	gg_pubdir50_free(req);

	return (HANDLE)1;
}
Пример #2
0
void GaduSearchService::searchNext()
{
	if (!Connection || !Connection->hasSession())
		return;

	Stopped = false;
	gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);

	if (Query.SearchBuddy.hasContact(account()))
		gg_pubdir50_add(req, GG_PUBDIR50_UIN, Query.SearchBuddy.id(account()).toUtf8().constData());
	if (!Query.SearchBuddy.firstName().isEmpty())
		gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, Query.SearchBuddy.firstName().toUtf8().constData());
	if (!Query.SearchBuddy.lastName().isEmpty())
		gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, Query.SearchBuddy.lastName().toUtf8().constData());
	if (!Query.SearchBuddy.nickName().isEmpty())
		gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, Query.SearchBuddy.nickName().toUtf8().constData());
	if (!Query.SearchBuddy.city().isEmpty())
		gg_pubdir50_add(req, GG_PUBDIR50_CITY, Query.SearchBuddy.city().toUtf8().constData());
	if (!Query.BirthYearFrom.isEmpty())
	{
		QString bufYear = Query.BirthYearFrom + ' ' + Query.BirthYearTo;
		gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, bufYear.toUtf8().constData());
	}

	switch (Query.SearchBuddy.gender())
	{
		case GenderMale:
			gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_MALE);
			break;
		case GenderFemale:
			gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_FEMALE);
			break;
		case GenderUnknown:
			// do nothing
			break;
	}

	if (Query.Active)
		gg_pubdir50_add(req, GG_PUBDIR50_ACTIVE, GG_PUBDIR50_ACTIVE_TRUE);

	gg_pubdir50_add(req, GG_PUBDIR50_START, QString::number(From).toUtf8().constData());

	auto writableSessionToken = Connection->writableSessionToken();
	SearchSeq = gg_pubdir50(writableSessionToken.rawSession(), req);
	gg_pubdir50_free(req);
}
Пример #3
0
bool
GaduSession::publishPersonalInformation( ResLine& d )
{
	gg_pubdir50_t r;
	
	if ( !session_ ) {
		return 0;
        }		
	
	r = gg_pubdir50_new( GG_PUBDIR50_WRITE );

	if ( d.firstname.length() )
		gg_pubdir50_add( r, GG_PUBDIR50_FIRSTNAME, 
			 (const char *)((const char*)textcodec->fromUnicode( d.firstname ) ) );
        if ( d.surname.length() )
		gg_pubdir50_add( r, GG_PUBDIR50_LASTNAME,
			(const char *)((const char*)textcodec->fromUnicode( d.surname ) ) );
	if ( d.nickname.length() )
		gg_pubdir50_add( r, GG_PUBDIR50_NICKNAME,
			(const char *)((const char*)textcodec->fromUnicode( d.nickname ) ) );
	if ( d.age.length() )
		gg_pubdir50_add( r, GG_PUBDIR50_BIRTHYEAR,
			(const char *)((const char*)textcodec->fromUnicode( d.age ) ) );
        if ( d.city.length() )
        	gg_pubdir50_add( r, GG_PUBDIR50_CITY,
			(const char *)((const char*)textcodec->fromUnicode( d.city ) ) );
	if ( d.meiden.length() )
		gg_pubdir50_add( r, GG_PUBDIR50_FAMILYNAME,
			(const char *)((const char*)textcodec->fromUnicode( d.meiden ) ) );
        if ( d.orgin.length() )
		gg_pubdir50_add( r, GG_PUBDIR50_FAMILYCITY,
			(const char *)((const char*)textcodec->fromUnicode( d.orgin ) ) );
	if ( d.gender.length() == 1 )
		gg_pubdir50_add( r, GG_PUBDIR50_GENDER, 
			(const char *)((const char*)textcodec->fromUnicode( d.gender ) ) );
        
	gg_pubdir50( session_, r );
        
	gg_pubdir50_free( r );

	return true;
}
Пример #4
0
unsigned int
GaduSession::getPersonalInformation()
{
	gg_pubdir50_t searchRequest;
	unsigned int seqNr;

	if ( isConnected() == false ) {
		return 0;
	}

	searchRequest = gg_pubdir50_new( GG_PUBDIR50_READ );
	if ( !searchRequest ) {
		return 0;
	}

	seqNr = gg_pubdir50( session_, searchRequest );
	gg_pubdir50_free( searchRequest );

	return seqNr;
}
Пример #5
0
void GaduSearchService::searchNext()
{
	Stopped = false;

	gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);

// 	if (!Query.Uin.isEmpty()) TODO: 0.6.6
// 		gg_pubdir50_add(req, GG_PUBDIR50_UIN, (const char *)unicode2cp(searchRecord.Uin).data());
	if (!Query.firstName().isEmpty())
		gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, (const char *)unicode2cp(Query.firstName()).data());
	if (!Query.lastName().isEmpty())
		gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, (const char *)unicode2cp(Query.lastName()).data());
	if (!Query.nickName().isEmpty())
		gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, (const char *)unicode2cp(Query.nickName()).data());
	if (!Query.city().isEmpty())
		gg_pubdir50_add(req, GG_PUBDIR50_CITY, (const char *)unicode2cp(Query.city()).data());
// 	if (!Query.BirthYearFrom.isEmpty()) TODO: 0.6.6
	if (0 != Query.birthYear())
		gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, (const char *)unicode2cp(QString::number(Query.birthYear())).data());

	switch (Query.gender())
	{
		case ContactData::GenderMale:
			gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_MALE);
			break;
		case ContactData::GenderFemale:
			gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_FEMALE);
			break;
	}

	// TODO: 0.6.6
// 	if (searchRecord.Active)
// 		gg_pubdir50_add(req, GG_PUBDIR50_ACTIVE, GG_PUBDIR50_ACTIVE_TRUE);

	gg_pubdir50_add(req, GG_PUBDIR50_START, qPrintable(QString::number(From)));

	SearchSeq = gg_pubdir50(Protocol->gaduSession(), req);
	gg_pubdir50_free(req);
}
Пример #6
0
HWND GGPROTO::SearchAdvanced(HWND hwndDlg)
{
	gg_pubdir50_t req;
	TCHAR text[64];
	char data[800] = "\0";
	unsigned long crc;

	// Check if connected
	if (!isonline()) return (HWND)0;

	if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH)))
	{
#ifdef DEBUGMODE
		debugLogA("SearchAdvanced(): ForkThread 14 GGPROTO::searchthread");
#endif
		ForkThread(&GGPROTO::searchthread, NULL);
		return (HWND)1;
	}

	// Fetch search data
	GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, sizeof(text));
	if (_tcslen(text))
	{
		char *firstName_utf8 = mir_utf8encodeT(text);
		gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, firstName_utf8);
		strncat(data, firstName_utf8, sizeof(data) - strlen(data));
		mir_free(firstName_utf8);
	}
	/* 1 */ strncat(data, ".", sizeof(data) - strlen(data));

	GetDlgItemText(hwndDlg, IDC_LASTNAME, text, sizeof(text));
	if (_tcslen(text))
	{
		char *lastName_utf8 = mir_utf8encodeT(text);
		gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, lastName_utf8);
		strncat(data, lastName_utf8, sizeof(data) - strlen(data));
		mir_free(lastName_utf8);
	}
	/* 2 */ strncat(data, ".", sizeof(data) - strlen(data));

	GetDlgItemText(hwndDlg, IDC_NICKNAME, text, sizeof(text));
	if (_tcslen(text))
	{
		char *nickName_utf8 = mir_utf8encodeT(text);
		gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, nickName_utf8);
		strncat(data, nickName_utf8, sizeof(data) - strlen(data));
		mir_free(nickName_utf8);
	}
	/* 3 */ strncat(data, ".", sizeof(data) - strlen(data));

	GetDlgItemText(hwndDlg, IDC_CITY, text, sizeof(text));
	if (_tcslen(text))
	{
		char *city_utf8 = mir_utf8encodeT(text);
		gg_pubdir50_add(req, GG_PUBDIR50_CITY, city_utf8);
		strncat(data, city_utf8, sizeof(data) - strlen(data));
		mir_free(city_utf8);
	}
	/* 4 */ strncat(data, ".", sizeof(data) - strlen(data));

	GetDlgItemText(hwndDlg, IDC_AGEFROM, text, sizeof(text));
	if (_tcslen(text))
	{
		int yearTo = _tstoi(text);
		int yearFrom;
		time_t t = time(NULL);
		struct tm *lt = localtime(&t);
		int ay = lt->tm_year + 1900;
		char age[16];

		GetDlgItemTextA(hwndDlg, IDC_AGETO, age, sizeof(age));
		yearFrom = atoi(age);

		// Count & fix ranges
		if (!yearTo)
			yearTo = ay;
		else
			yearTo = ay - yearTo;
		if (!yearFrom)
			yearFrom = 0;
		else
			yearFrom = ay - yearFrom;
		mir_sntprintf(text, sizeof(text), _T("%d %d"), yearFrom, yearTo);

		char *age_utf8 = mir_utf8encodeT(text);
		gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, age_utf8);
		strncat(data, age_utf8, sizeof(data) - strlen(data));
		mir_free(age_utf8);
	}
	/* 5 */ strncat(data, ".", sizeof(data) - strlen(data));

	switch(SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0))
	{
		case 1:
			gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_FEMALE);
			strncat(data, GG_PUBDIR50_GENDER_MALE, sizeof(data) - strlen(data));
			break;
		case 2:
			gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_MALE);
			strncat(data, GG_PUBDIR50_GENDER_FEMALE, sizeof(data) - strlen(data));
			break;
	}
	/* 6 */ strncat(data, ".", sizeof(data) - strlen(data));

	if (IsDlgButtonChecked(hwndDlg, IDC_ONLYCONNECTED))
	{
		gg_pubdir50_add(req, GG_PUBDIR50_ACTIVE, GG_PUBDIR50_ACTIVE_TRUE);
		strncat(data, GG_PUBDIR50_ACTIVE_TRUE, sizeof(data) - strlen(data));
	}
	/* 7 */ strncat(data, ".", sizeof(data) - strlen(data));

	// No data entered
	if (strlen(data) <= 7 || (strlen(data) == 8 && IsDlgButtonChecked(hwndDlg, IDC_ONLYCONNECTED))) return (HWND)0;

	// Count crc & check if the data was equal if yes do same search with shift
	crc = crc_get(data);

	if (crc == last_crc && next_uin)
		gg_pubdir50_add(req, GG_PUBDIR50_START, ditoa(next_uin));
	else
		last_crc = crc;

	gg_pubdir50_seq_set(req, GG_SEQ_SEARCH);

	if (isonline())
	{
		gg_EnterCriticalSection(&sess_mutex, "SearchAdvanced", 52, "sess_mutex", 1);
		if (!gg_pubdir50(sess, req))
		{
			gg_LeaveCriticalSection(&sess_mutex, "SearchAdvanced", 52, 1, "sess_mutex", 1);
#ifdef DEBUGMODE
			debugLogA("SearchAdvanced(): ForkThread 15 GGPROTO::searchthread");
#endif
			ForkThread(&GGPROTO::searchthread, NULL);
			return (HWND)1;
		}
		gg_LeaveCriticalSection(&sess_mutex, "SearchAdvanced", 52, 2, "sess_mutex", 1);
	}
	debugLogA("SearchAdvanced(): Seq %d.", req->seq);
	gg_pubdir50_free(req);

	return (HWND)1;
}
Пример #7
0
HANDLE GGPROTO::SearchByName(const PROTOCHAR *nick, const PROTOCHAR *firstName, const PROTOCHAR *lastName)
{
	gg_pubdir50_t req;
	unsigned long crc;
	char data[512] = "\0";

	// Check if connected and if there's a search data
	if (!isonline())
		return 0;

	if (!nick && !firstName && !lastName)
		return 0;

	if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH)))
	{
#ifdef DEBUGMODE
		debugLogA("SearchByName(): ForkThread 12 GGPROTO::searchthread");
#endif
		ForkThread(&GGPROTO::searchthread, NULL);
		return (HANDLE)1;
	}

	// Add nick,firstName,lastName and search it
	if (nick)
	{
		char *nick_utf8 = mir_utf8encodeT(nick);
		gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, nick_utf8);
		strncat(data, nick_utf8, sizeof(data) - strlen(data));
		mir_free(nick_utf8);
	}
	strncat(data, ".", sizeof(data) - strlen(data));

	if (firstName)
	{
		char *firstName_utf8 = mir_utf8encodeT(firstName);
		gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, firstName_utf8);
		strncat(data, firstName_utf8, sizeof(data) - strlen(data));
		mir_free(firstName_utf8);
	}
	strncat(data, ".", sizeof(data) - strlen(data));

	if (lastName)
	{
		char *lastName_utf8 = mir_utf8encodeT(lastName);
		gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, lastName_utf8);
		strncat(data, lastName_utf8, sizeof(data) - strlen(data));
		mir_free(lastName_utf8);
	}
	strncat(data, ".", sizeof(data) - strlen(data));

	// Count crc & check if the data was equal if yes do same search with shift
	crc = crc_get(data);

	if (crc == last_crc && next_uin)
		gg_pubdir50_add(req, GG_PUBDIR50_START, ditoa(next_uin));
	else
		last_crc = crc;

	gg_pubdir50_seq_set(req, GG_SEQ_SEARCH);
	gg_EnterCriticalSection(&sess_mutex, "SearchByName", 51, "sess_mutex", 1);
	if (!gg_pubdir50(sess, req))
	{
		gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 1, "sess_mutex", 1);
#ifdef DEBUGMODE
		debugLogA("SearchByName(): ForkThread 13 GGPROTO::searchthread");
#endif
		ForkThread(&GGPROTO::searchthread, NULL);
		return (HANDLE)1;
	}
	gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 2, "sess_mutex", 1);
	debugLogA("SearchByName(): Seq %d.", req->seq);
	gg_pubdir50_free(req);

	return (HANDLE)1;
}
Пример #8
0
int GGPROTO::GetInfo(HANDLE hContact, int infoType)
{
	gg_pubdir50_t req;

	// Custom contact info
	if (hContact)
	{
		if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH)))
		{
#ifdef DEBUGMODE
			debugLogA("GetInfo(): ForkThread 6 GGPROTO::cmdgetinfothread");
#endif
			ForkThread(&GGPROTO::cmdgetinfothread, hContact);
			return 1;
		}

		// Add uin and search it
		gg_pubdir50_add(req, GG_PUBDIR50_UIN, ditoa((uin_t)getDword(hContact, GG_KEY_UIN, 0)));
		gg_pubdir50_seq_set(req, GG_SEQ_INFO);

		debugLogA("GetInfo(): Requesting user info.", req->seq);
		if (isonline())
		{
			gg_EnterCriticalSection(&sess_mutex, "GetInfo", 48, "sess_mutex", 1);
			if (!gg_pubdir50(sess, req))
			{
				gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 48, 1, "sess_mutex", 1);
#ifdef DEBUGMODE
				debugLogA("GetInfo(): ForkThread 7 GGPROTO::cmdgetinfothread");
#endif
				ForkThread(&GGPROTO::cmdgetinfothread, hContact);
				return 1;
			}
			gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 48, 2, "sess_mutex", 1);
		}
	}
	// Own contact info
	else
	{
		if (!(req = gg_pubdir50_new(GG_PUBDIR50_READ)))
		{
#ifdef DEBUGMODE
			debugLogA("GetInfo(): ForkThread 8 GGPROTO::cmdgetinfothread");
#endif
			ForkThread(&GGPROTO::cmdgetinfothread, hContact);
			return 1;
		}

		// Add seq
		gg_pubdir50_seq_set(req, GG_SEQ_CHINFO);

		debugLogA("GetInfo(): Requesting owner info.", req->seq);
		if (isonline())
		{
			gg_EnterCriticalSection(&sess_mutex, "GetInfo", 49, "sess_mutex", 1);
			if (!gg_pubdir50(sess, req))
			{
				gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 49, 1, "sess_mutex", 1);
#ifdef DEBUGMODE
				debugLogA("GetInfo(): ForkThread 9 GGPROTO::cmdgetinfothread");
#endif
				ForkThread(&GGPROTO::cmdgetinfothread, hContact);
				return 1;
			}
			gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 49, 2, "sess_mutex", 1);
		}
	}
	debugLogA("GetInfo(): Seq %d.", req->seq);
	gg_pubdir50_free(req);

	return 1;
}
Пример #9
0
/*
 * \internal Analizuje przychodzący pakiet odpowiedzi i zapisuje wynik
 * w strukturze \c gg_event.
 *
 * \param sess Struktura sesji
 * \param e Struktura zdarzenia
 * \param packet Pakiet odpowiedzi
 * \param length Długość pakietu odpowiedzi
 *
 * \return 0 jeśli się powiodło, -1 w przypadku błędu
 */
int gg_pubdir50_handle_reply_sess(struct gg_session *sess, struct gg_event *e, const char *packet, int length)
{
	const char *end = packet + length, *p;
	struct gg_pubdir50_reply *r = (struct gg_pubdir50_reply*) packet;
	gg_pubdir50_t res;
	int num = 0;
	
	gg_debug(GG_DEBUG_FUNCTION, "** gg_pubdir50_handle_reply_sess(%p, %p, %p, %d);\n", sess, e, packet, length);

	if (!sess || !e || !packet) {
		gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_handle_reply() invalid arguments\n");
		errno = EFAULT;
		return -1;
	}

	if (length < 5) {
		gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_handle_reply() packet too short\n");
		errno = EINVAL;
		return -1;
	}

	if (!(res = gg_pubdir50_new(r->type))) {
		gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_handle_reply() unable to allocate reply\n");
		return -1;
	}

	e->event.pubdir50 = res;

	res->seq = gg_fix32(r->seq);

	switch (res->type) {
		case GG_PUBDIR50_READ:
			e->type = GG_EVENT_PUBDIR50_READ;
			break;

		case GG_PUBDIR50_WRITE:
			e->type = GG_EVENT_PUBDIR50_WRITE;
			break;

		default:
			e->type = GG_EVENT_PUBDIR50_SEARCH_REPLY;
			break;
	}

	/* brak wyników? */
	if (length == 5)
		return 0;

	/* pomiń początek odpowiedzi */
	p = packet + 5;

	while (p < end) {
		const char *field, *value;

		field = p;

		/* sprawdź, czy nie mamy podziału na kolejne pole */
		if (!*field) {
			num++;
			field++;
		}

		value = NULL;
		
		for (p = field; p < end; p++) {
			/* jeśli mamy koniec tekstu... */
			if (!*p) {
				/* ...i jeszcze nie mieliśmy wartości pola to
				 * wiemy, że po tym zerze jest wartość... */
				if (!value)
					value = p + 1;
				else
					/* ...w przeciwym wypadku koniec
					 * wartości i możemy wychodzić
					 * grzecznie z pętli */
					break;
			}
		}
		
		/* sprawdźmy, czy pole nie wychodzi poza pakiet, żeby nie
		 * mieć segfaultów, jeśli serwer przestanie zakańczać pakietów
		 * przez \0 */

		if (p == end) {
			gg_debug(GG_DEBUG_MISC, "// gg_pubdir50_handle_reply() premature end of packet\n");
			goto failure;
		}

		p++;

		/* jeśli dostaliśmy namier na następne wyniki, to znaczy że
		 * mamy koniec wyników i nie jest to kolejna osoba. */
		if (!strcasecmp(field, "nextstart")) {
			res->next = atoi(value);
			num--;
		} else {
			if (sess->encoding == GG_ENCODING_CP1250) {
				if (gg_pubdir50_add_n(res, num, field, value) == -1)
					goto failure;
			} else {
				char *tmp;

				tmp = gg_cp_to_utf8(value);

				if (tmp == NULL)
					goto failure;

				if (gg_pubdir50_add_n(res, num, field, tmp) == -1) {
					free(tmp);
					goto failure;
				}

				free(tmp);
			}
		}
	}	

	res->count = num + 1;
	
	return 0;

failure:
	gg_pubdir50_free(res);
	return -1;
}
Пример #10
0
////////////////////////////////////////////////////////////////////////////////
// Info Page : Proc
static INT_PTR CALLBACK gg_detailsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct GGDETAILSDLGDATA *dat = (struct GGDETAILSDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch(msg)
	{
		case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			dat = (struct GGDETAILSDLGDATA *)mir_alloc(sizeof(struct GGDETAILSDLGDATA));
			dat->hContact=(HANDLE)lParam;
			dat->disableUpdate = FALSE;
			dat->updating = FALSE;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
			// Add genders
			if(!dat->hContact)
			{
				SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)_T(""));				// 0
				SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)Translate("Female"));	// 1
				SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)Translate("Male"));	// 2
			}
			break;
		}

		case WM_NOTIFY:
			switch (((LPNMHDR)lParam)->idFrom)
			{
				case 0:
					switch (((LPNMHDR)lParam)->code)
					{
						case PSN_PARAMCHANGED:
						{
							dat->gg = (GGPROTO *)((LPPSHNOTIFY)lParam)->lParam;
							break;
						}
						case PSN_INFOCHANGED:
						{
							char *szProto;
							HANDLE hContact = (HANDLE)((LPPSHNOTIFY)lParam)->lParam;
							GGPROTO *gg = dat->gg;

							// Show updated message
							if(dat && dat->updating)
							{
								MessageBox(
									NULL,
									Translate("Your details has been uploaded to the public directory."),
									GG_PROTONAME,
									MB_OK | MB_ICONINFORMATION
								);
								dat->updating = FALSE;
								break;
							}

							if (hContact == NULL)
								szProto = GG_PROTO;
							else
								szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
							if (szProto == NULL)
								break;

							// Disable when updating
							if(dat) dat->disableUpdate = TRUE;

							SetValue(hwndDlg, IDC_UIN, hContact, szProto, GG_KEY_UIN, 0, hContact != NULL);
							SetValue(hwndDlg, IDC_REALIP, hContact, szProto, GG_KEY_CLIENTIP, SVS_IP, hContact != NULL);
							SetValue(hwndDlg, IDC_PORT, hContact, szProto, GG_KEY_CLIENTPORT, SVS_ZEROISUNSPEC, hContact != NULL);
							SetValue(hwndDlg, IDC_VERSION, hContact, szProto, GG_KEY_CLIENTVERSION, SVS_GGVERSION, hContact != NULL);

							SetValue(hwndDlg, IDC_FIRSTNAME, hContact, szProto, "FirstName", SVS_NORMAL, hContact != NULL);
							SetValue(hwndDlg, IDC_LASTNAME, hContact, szProto, "LastName", SVS_NORMAL, hContact != NULL);
							SetValue(hwndDlg, IDC_NICKNAME, hContact, szProto, "NickName", SVS_NORMAL, hContact != NULL);
							SetValue(hwndDlg, IDC_BIRTHYEAR, hContact, szProto, "BirthYear", SVS_ZEROISUNSPEC, hContact != NULL);
							SetValue(hwndDlg, IDC_CITY, hContact, szProto, "City", SVS_NORMAL, hContact != NULL);
							SetValue(hwndDlg, IDC_FAMILYNAME, hContact, szProto, "FamilyName", SVS_NORMAL, hContact != NULL);
							SetValue(hwndDlg, IDC_CITYORIGIN, hContact, szProto, "CityOrigin", SVS_NORMAL, hContact != NULL);

							if (hContact)
							{
								SetValue(hwndDlg, IDC_GENDER, hContact, szProto, "Gender", SVS_GENDER, hContact != NULL);
								SetValue(hwndDlg, IDC_STATUSDESCR, hContact, "CList", GG_KEY_STATUSDESCR, SVS_NORMAL, hContact != NULL);
							}
							else switch((char)DBGetContactSettingByte(hContact, GG_PROTO, "Gender", (BYTE)'?'))
							{
								case 'F':
									SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 1, 0);
									break;
								case 'M':
									SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 2, 0);
									break;
								default:
									SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 0, 0);
							}

							// Disable when updating
							if(dat) dat->disableUpdate = FALSE;
							break;
						}
					}
					break;
				}
				break;
		case WM_COMMAND:
			if (dat && !dat->hContact && LOWORD(wParam) == IDC_SAVE && HIWORD(wParam) == BN_CLICKED)
			{
				// Save user data
				char text[256];
				gg_pubdir50_t req;
				GGPROTO *gg = dat->gg;

				if (!gg_isonline(gg))
				{
					MessageBox(NULL,
						Translate("You have to be logged in before you can change your details."),
						GG_PROTONAME, MB_OK | MB_ICONSTOP
					);
					break;
				}

				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), FALSE);

				req = gg_pubdir50_new(GG_PUBDIR50_WRITE);

				GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, sizeof(text));
				if (strlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, text);

				GetDlgItemText(hwndDlg, IDC_LASTNAME, text, sizeof(text));
				if (strlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, text);

				GetDlgItemText(hwndDlg, IDC_NICKNAME, text, sizeof(text));
				if (strlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, text);

				GetDlgItemText(hwndDlg, IDC_CITY, text, sizeof(text));
				if (strlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_CITY, text);

				// Gadu-Gadu Female <-> Male
				switch(SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0))
				{
					case 1:
						gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_FEMALE);
						break;
					case 2:
						gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_MALE);
						break;
					default:
						gg_pubdir50_add(req, GG_PUBDIR50_GENDER, "");
				}

				GetDlgItemText(hwndDlg, IDC_BIRTHYEAR, text, sizeof(text));
				if (strlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, text);

				GetDlgItemText(hwndDlg, IDC_FAMILYNAME, text, sizeof(text));
				if (strlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_FAMILYNAME, text);

				GetDlgItemText(hwndDlg, IDC_CITYORIGIN, text, sizeof(text));
				if (strlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_FAMILYCITY, text);

				// Run update
				gg_pubdir50_seq_set(req, GG_SEQ_CHINFO);
				EnterCriticalSection(&gg->sess_mutex);
				gg_pubdir50(gg->sess, req);
				LeaveCriticalSection(&gg->sess_mutex);
				dat->updating = TRUE;

				gg_pubdir50_free(req);
			}

			if(dat && !dat->hContact && !dat->disableUpdate && (HIWORD(wParam) == EN_CHANGE && (
				LOWORD(wParam) == IDC_NICKNAME || LOWORD(wParam) == IDC_FIRSTNAME || LOWORD(wParam) == IDC_LASTNAME || LOWORD(wParam) == IDC_FAMILYNAME ||
				LOWORD(wParam) == IDC_CITY || LOWORD(wParam) == IDC_CITYORIGIN || LOWORD(wParam) == IDC_BIRTHYEAR) ||
				HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_GENDER))
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), TRUE);

			switch(LOWORD(wParam))
			{
				case IDCANCEL:
					SendMessage(GetParent(hwndDlg),msg,wParam,lParam);
					break;
			}
			break;
		case WM_DESTROY:
			if(dat) mir_free(dat);
			break;
	}
	return FALSE;
}
Пример #11
0
int session_io_handler(Session *s){
struct gg_event *event;
char *jid,*str;
int chat;
GIOCondition condition=s->g_pollfd.revents;
time_t timestamp;
gboolean state;

	user_load_locale(s->user);
	debug(L_("Checking error conditions..."));
	if (condition&(G_IO_ERR|G_IO_NVAL)){
		if (condition&G_IO_ERR) g_warning(N_("Error on connection for %s, GGid: %i"),s->jid,s->ggs->uin);
		if (condition&G_IO_HUP){
			g_warning(N_("Hangup on connection for %s, GGid: %i"),s->jid,s->ggs->uin);
			return session_error(s);
		}
		if (condition&G_IO_NVAL) g_warning(N_("Invalid channel on connection for %s"),s->jid);

		session_broken(s);
		return FALSE;
	}

	debug(L_("watching fd (gg_debug_level=%i)..."),gg_debug_level);
	event=gg_watch_fd(s->ggs);
	if (!event){
		g_warning(N_("Connection broken. Session of %s, GGid: %i"),s->jid,s->ggs->uin);
		return session_error(s);
	}

	switch(event->type){
		case GG_EVENT_DISCONNECT:
			g_warning(N_("Server closed connection of %s, GGid: %i"),s->jid,s->ggs->uin);
			session_error(s);
			gg_event_free(event);
			return FALSE;
		case GG_EVENT_CONN_FAILED:
			g_message(N_("Login failed (%d:%s) for %s, GGid: %i"),
					event->event.failure,
					(event->event.failure>GG_FAILURE_NUM_REASONS||event->event.failure<1)?"-UNKNOWN-":gg_failure_reason[event->event.failure-1],
					s->jid,
					s->ggs->uin);
			if (s->req_id)
				jabber_iq_send_error(s->s,s->jid,NULL,s->req_id,401,_("Unauthorized"));
			else {
				str=g_strdup(from_utf8(gg_failure_reason_txt[event->event.failure-1]));
				presence_send(s->s,NULL,s->user->jid,0,NULL,str,0);
				g_free(str);
			}
			state = FALSE;
			if (!s->req_id)
				switch(event->event.failure){
					case GG_FAILURE_RESOLVING:
					case GG_FAILURE_CONNECTING:
					case GG_FAILURE_INVALID:
					case GG_FAILURE_READING:
					case GG_FAILURE_WRITING:
					case GG_FAILURE_TLS:
						state = session_try_next(s);
					default:
						break;
				}
			if (state) {
				s->connected=0;
				session_schedule_reconnect(s);
			} else
				session_remove(s);
			gg_event_free(event);
			return FALSE;
		case GG_EVENT_CONN_SUCCESS:
			g_message(L_("Login succeed for %s, GGid: %i"),s->jid,s->ggs->uin);
			if (s->req_id)
				jabber_iq_send_result(s->s,s->jid,NULL,s->req_id,NULL);
			if (s->req_id){
				g_free(s->req_id);
				s->req_id=NULL;
			}
			if (s->query){
				xmlnode_free(s->query);
				s->query=NULL;
			}
			if (!s->user->confirmed){
				s->user->confirmed=1;
				user_save(s->user);
			}
			s->connected=1;
			session_send_status(s);
			session_send_notify(s);
			presence_send(s->s,NULL,s->user->jid,s->user->invisible?-1:1,NULL,s->gg_status_descr,0);

			if (s->timeout_func) g_source_remove(s->timeout_func);
			s->timeout_func=NULL;
			if (s->ping_timeout_func) g_source_remove(s->ping_timeout_func);
			s->ping_timeout_func=g_timeout_add(ping_interval*1000,session_ping,s);
			if (s->pubdir_change){
				add_request(RT_CHANGE,s->jid,NULL,s->req_id,
							NULL,s->pubdir_change,s->s);
				gg_pubdir50_free(s->pubdir_change);
				s->pubdir_change=NULL;
			}
			if (s->get_roster){
				gg_userlist_request(s->ggs, GG_USERLIST_GET, NULL);
			}
			break;
		case GG_EVENT_NOTIFY:
			session_event_notify(s,event);
			break;
		case GG_EVENT_NOTIFY_DESCR:
			session_event_notify_descr(s,event);
			break;
		case GG_EVENT_NOTIFY60:
			session_event_notify60(s,event);
			break;
		case GG_EVENT_STATUS:
			session_event_status(s,
					event->event.status.status,
					event->event.status.uin,
					event->event.status.descr,
					0,0,0,0);
			break;
		case GG_EVENT_STATUS60:
			session_event_status(s,
					event->event.status60.status,
					event->event.status60.uin,
					event->event.status60.descr,
					1,
					event->event.status60.remote_ip,
					event->event.status60.remote_port,
					event->event.status60.version);
			break;
		case GG_EVENT_MSG:
			if (event->event.msg.recipients_count>1){
				debug(L_("Dropped conference message: sender: %i class: %i time: %lu"),
							event->event.msg.sender,
							event->event.msg.msgclass,
							(unsigned long)event->event.msg.time);
				break;
			}
			gg_messages_in++;
			debug(L_("Message: sender: %i class: %i time: %lu"),
							event->event.msg.sender,
							event->event.msg.msgclass,
							(unsigned long)event->event.msg.time);
			
			if (event->event.msg.sender==0){
				if (!user_sys_msg_received(s->user,event->event.msg.msgclass)) break;
				if (ignore_system_messages == ISM_IGNORE_ALL) break;
				if (ignore_system_messages == ISM_IGNORE_HTML
					&& strstr((const char *)event->event.msg.message, "<HTML>")) break;
				timestamp=event->event.msg.time;
				str=g_strdup_printf(_("GG System message #%i"),
							event->event.msg.msgclass);
				message_send_subject(s->s,jid, s->user->jid, str,
						string_from_gg((const char *)event->event.msg.message),
												timestamp);
				g_free(str);
				break;
			}
			else{
				Contact *c=user_get_contact(s->user,
						event->event.msg.sender,0);
				if ((!c && s->user->ignore_unknown) 
				    || (c && c->ignored)) {
					debug(L_("Ignoring the message."));
			       		break;
				}
				jid=jid_build_full(event->event.msg.sender);
				if ((event->event.msg.msgclass&GG_CLASS_CHAT)!=0) chat=1;
				else chat=0;
			}
			if ((event->event.msg.msgclass&GG_CLASS_QUEUED)!=0){
				timestamp=event->event.msg.time;
			}
			else timestamp=0;
			if(event->event.msg.formats_length>0)
				message_send_rich(s->s,jid,s->user->jid,chat,
						(char *)event->event.msg.message,timestamp,
						event->event.msg.formats_length,(void *)event->event.msg.formats);
			else
				message_send(s->s,jid,s->user->jid,chat,
						string_from_gg((const char *)event->event.msg.message),timestamp);
			g_free(jid);
			break;
		case GG_EVENT_PONG:
			s->waiting_for_pong=FALSE;
			if (s->ping_timer){
				g_timer_stop(s->ping_timer);
				debug(L_("Pong! ping time: %fs"),
						g_timer_elapsed(s->ping_timer,NULL));
			}
			if (s->timeout_func) g_source_remove(s->timeout_func);
			s->timeout_func=NULL;
			break;
		case GG_EVENT_PUBDIR50_SEARCH_REPLY:
			request_response_search(event);
			break;
		case GG_EVENT_PUBDIR50_WRITE:
			request_response_write(event);
			break;
		case GG_EVENT_ACK:
			debug("GG_EVENT_ACK");
			break;
		case GG_EVENT_NONE:
			debug("GG_EVENT_NONE");
			break;
		case GG_EVENT_USERLIST:
			if(event->event.userlist.type==GG_USERLIST_GET_REPLY)
				get_roster_done(s,event);
			else
				g_warning(N_("Wrong gg userlist type: %i"),event->event.userlist.type);
			break;
		default:
			g_warning(N_("Unknown GG event: %i"),event->type);
			break;
	}

	session_setup_g_source(s);

	gg_event_free(event);
	debug(L_("io handler done..."));

	return FALSE;
}
Пример #12
0
HANDLE GGPROTO::SearchByName(const TCHAR *nick, const TCHAR *firstName, const TCHAR *lastName)
{
	// Check if connected and if there's a search data
	if (!isonline())
		return 0;

	if (!nick && !firstName && !lastName)
		return 0;

	gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);
	if (req == NULL) {
#ifdef DEBUGMODE
		debugLogA("SearchByName(): ForkThread 12 GGPROTO::searchthread");
#endif
		ForkThread(&GGPROTO::searchthread, NULL);
		return (HANDLE)1;
	}

	// Add nick,firstName,lastName and search it
	CMStringA szQuery;
	if (nick)
	{
		T2Utf nick_utf8(nick);
		gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, nick_utf8);
		szQuery.Append(nick_utf8);
	}
	szQuery.AppendChar('.');

	if (firstName)
	{
		T2Utf firstName_utf8(firstName);
		gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, firstName_utf8);
		szQuery.Append(firstName_utf8);
	}
	szQuery.AppendChar('.');

	if (lastName)
	{
		T2Utf lastName_utf8(lastName);
		gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, lastName_utf8);
		szQuery.Append(lastName_utf8);
	}
	szQuery.AppendChar('.');

	// Count crc & check if the data was equal if yes do same search with shift
	unsigned long crc = crc_get(szQuery.GetBuffer());
	if (crc == last_crc && next_uin)
		gg_pubdir50_add(req, GG_PUBDIR50_START, ditoa(next_uin));
	else
		last_crc = crc;

	gg_pubdir50_seq_set(req, GG_SEQ_SEARCH);
	gg_EnterCriticalSection(&sess_mutex, "SearchByName", 51, "sess_mutex", 1);
	if (!gg_pubdir50(sess, req))
	{
		gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 1, "sess_mutex", 1);
#ifdef DEBUGMODE
		debugLogA("SearchByName(): ForkThread 13 GGPROTO::searchthread");
#endif
		ForkThread(&GGPROTO::searchthread, NULL);
		return (HANDLE)1;
	}
	gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 2, "sess_mutex", 1);
	debugLogA("SearchByName(): Seq %d.", req->seq);
	gg_pubdir50_free(req);

	return (HANDLE)1;
}
Пример #13
0
/*
 * gg_event_free()
 *
 * zwalnia pamiêæ zajmowan± przez informacjê o zdarzeniu.
 *
 *  - e - wska¼nik do informacji o zdarzeniu
 */
void gg_event_free(struct gg_event *e)
{
	gg_debug(GG_DEBUG_FUNCTION, "** gg_event_free(%p);\n", e);
			
	if (!e)
		return;
	
	switch (e->type) {
		case GG_EVENT_MSG:
			free(e->event.msg.message);
			free(e->event.msg.formats);
			free(e->event.msg.recipients);
			break;
	
		case GG_EVENT_NOTIFY:
			free(e->event.notify);
			break;
	
		case GG_EVENT_NOTIFY60:
		{
			int i;

			for (i = 0; e->event.notify60[i].uin; i++)
				free(e->event.notify60[i].descr);
		
			free(e->event.notify60);

			break;
		}

		case GG_EVENT_STATUS60:
			free(e->event.status60.descr);
			break;
	
		case GG_EVENT_STATUS:
			free(e->event.status.descr);
			break;

		case GG_EVENT_NOTIFY_DESCR:
			free(e->event.notify_descr.notify);
			free(e->event.notify_descr.descr);
			break;

		case GG_EVENT_DCC_VOICE_DATA:
			free(e->event.dcc_voice_data.data);
			break;

		case GG_EVENT_PUBDIR50_SEARCH_REPLY:
		case GG_EVENT_PUBDIR50_READ:
		case GG_EVENT_PUBDIR50_WRITE:
			gg_pubdir50_free(e->event.pubdir50);
			break;

		case GG_EVENT_USERLIST:
			free(e->event.userlist.reply);
			break;
	
		case GG_EVENT_IMAGE_REPLY:
			free(e->event.image_reply.filename);
			free(e->event.image_reply.image);
			break;
	}

	free(e);
}
Пример #14
0
/*
 * gg_session_handler_search50()
 *
 * zajmuje siê obs³ug± wyniku przeszukiwania katalogu publicznego.
 *
 *  - s - sesja
 *  - e - opis zdarzenia
 */
void gg_session_handler_search50(session_t *s, struct gg_event *e)
{
	gg_private_t *g = session_private_get(s);
	gg_pubdir50_t res = e->event.pubdir50;
	int i, count, all = 0;
	list_t l;
	uin_t last_uin = 0;

	if (!g)
		return;

	if ((count = gg_pubdir50_count(res)) < 1) {
		print("search_not_found");
		return;
	}

	debug_function("gg_session_handler_search50() handle_search50, count = %d\n", gg_pubdir50_count(res));

	for (l = g->searches; l; l = l->next) {
		gg_pubdir50_t req = l->data;

		if (gg_pubdir50_seq(req) == gg_pubdir50_seq(res)) {
			all = 1;
			break;
		}
	}

	for (i = 0; i < count; i++) {
		const char *uin		= gg_pubdir50_get(res, i, "fmnumber");
		const char *__firstname = gg_pubdir50_get(res, i, "firstname");
		const char *__lastname	= gg_pubdir50_get(res, i, "lastname");
		const char *__nickname	= gg_pubdir50_get(res, i, "nickname");
		const char *__fmstatus	= gg_pubdir50_get(res, i, "fmstatus");
		const char *__birthyear = gg_pubdir50_get(res, i, "birthyear");
		const char *__city	= gg_pubdir50_get(res, i, "city");

		char *firstname		= gg_to_core_dup(s, __firstname);
		char *lastname		= gg_to_core_dup(s, __lastname);
		char *nickname		= gg_to_core_dup(s, __nickname);
		char *city		= gg_to_core_dup(s, __city);
		int status		= (__fmstatus)	? atoi(__fmstatus) : GG_STATUS_NOT_AVAIL;
		const char *birthyear	= (__birthyear && xstrcmp(__birthyear, "0")) ? __birthyear : NULL;

		char *name, *active, *gender;
		const char *target = NULL;

		if (count == 1 && !all) {
			xfree(last_search_first_name);
			xfree(last_search_last_name);
			xfree(last_search_nickname);
			xfree(last_search_uid);
			last_search_first_name	= xstrdup(firstname);
			last_search_last_name	= xstrdup(lastname);
			last_search_nickname	= xstrdup(nickname);
			last_search_uid		= saprintf("gg:%s", uin);
		}

		name = saprintf(
			("%s %s"),
					firstname ? firstname : (""), 
					lastname ? lastname : (""));

#define __format(x) ((count == 1 && !all) ? "search_results_single" x : "search_results_multi" x)
		{
			const char *fvalue;
			switch (status) {
				case GG_STATUS_AVAIL:
				case GG_STATUS_AVAIL_DESCR:
					fvalue = format_find(__format("_avail"));
					break;
				case GG_STATUS_BUSY:
				case GG_STATUS_BUSY_DESCR:
					fvalue = format_find(__format("_away"));
					break;
				default:
					fvalue = format_find(__format("_notavail"));
			}
			active = format_string(fvalue, (__firstname) ? __firstname : nickname);
		}
		gender = format_string(format_find(__format("_unknown")), "");

			/* XXX: why do we _exactly_ use it here? can't we just always
			 *	define target and thus display result in right conversation window? */
		for (l = autofinds; l; l = l->next) {
			char *d = (char *) l->data;
		
			if (!xstrcasecmp(d + 3, uin)) {
				target = d;
				break;
			}
		}
		
		print_info(target, s, __format(""), 
			uin		? uin : ("?"), name, 
			nickname	? nickname : (""), 
			city		? city : (""), 
			birthyear	? birthyear : ("-"),
			gender, active);

#undef __format

		xfree(name);
		xfree(active);
		xfree(gender);

		xfree(firstname);
		xfree(lastname);
		xfree(nickname);
		xfree(city);

		last_uin = atoi(uin);
	}

	/* je¶li mieli¶my ,,/find --all'', szukamy dalej */
	for (l = g->searches; l; l = l->next) {
		gg_pubdir50_t req = l->data;
		uin_t next;

		if (gg_pubdir50_seq(req) != gg_pubdir50_seq(res))
			continue;

		/* nie ma dalszych? to dziêkujemy */
		if (!(next = gg_pubdir50_next(res)) || !g->sess || next <= last_uin) {
			list_remove(&g->searches, req, 0);
			gg_pubdir50_free(req);
			break;
		}

		gg_pubdir50_add(req, GG_PUBDIR50_START, ekg_itoa(next));
		gg_pubdir50(g->sess, req);

		break;
	}

}
Пример #15
0
////////////////////////////////////////////////////////////////////////////////
// Info Page : Proc
// lParam: 0 if current user (account owner) details, hContact if on list user details
static INT_PTR CALLBACK gg_detailsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct GGDETAILSDLGDATA *dat = (struct GGDETAILSDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch(msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		dat = (struct GGDETAILSDLGDATA *)mir_alloc(sizeof(struct GGDETAILSDLGDATA));
		dat->hContact = lParam;
		dat->disableUpdate = FALSE;
		dat->updating = FALSE;
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
		// Add genders
		if (!dat->hContact)
		{
			SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)_T(""));				// 0
			SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)TranslateT("Female"));	// 1
			SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)TranslateT("Male"));	// 2
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_PARAMCHANGED:
				dat->gg = (GGPROTO *)((LPPSHNOTIFY)lParam)->lParam;
				break;

			case PSN_INFOCHANGED:
				{
					MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
					GGPROTO *gg = dat->gg;
					if (!dat)
						break;

					// Show updated message
					if (dat->updating)
					{
						MessageBox(NULL, TranslateT("Your details has been uploaded to the public directory."),
							gg->m_tszUserName, MB_OK | MB_ICONINFORMATION);
						dat->updating = FALSE;
						break;
					}

					char *szProto = (hContact == NULL) ? gg->m_szModuleName : GetContactProto(hContact);
					if (szProto == NULL)
						break;

					// Disable when updating
					dat->disableUpdate = TRUE;

					SetValue(hwndDlg, IDC_UIN, hContact, szProto, GG_KEY_UIN, 0, hContact != NULL);
					SetValue(hwndDlg, IDC_REALIP, hContact, szProto, GG_KEY_CLIENTIP, SVS_IP, hContact != NULL);
					SetValue(hwndDlg, IDC_PORT, hContact, szProto, GG_KEY_CLIENTPORT, SVS_ZEROISUNSPEC, hContact != NULL);
					SetValue(hwndDlg, IDC_VERSION, hContact, szProto, GG_KEY_CLIENTVERSION, SVS_GGVERSION, hContact != NULL);

					SetValue(hwndDlg, IDC_FIRSTNAME, hContact, szProto, GG_KEY_PD_FIRSTNAME, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_LASTNAME, hContact, szProto, GG_KEY_PD_LASTNAME, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_NICKNAME, hContact, szProto, GG_KEY_PD_NICKNAME, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_BIRTHYEAR, hContact, szProto, GG_KEY_PD_BIRTHYEAR, SVS_ZEROISUNSPEC, hContact != NULL);
					SetValue(hwndDlg, IDC_CITY, hContact, szProto, GG_KEY_PD_CITY, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_FAMILYNAME, hContact, szProto, GG_KEY_PD_FAMILYNAME, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_CITYORIGIN, hContact, szProto, GG_KEY_PD_FAMILYCITY	, SVS_NORMAL, hContact != NULL);

					if (hContact)
					{
						SetValue(hwndDlg, IDC_GENDER, hContact, szProto, GG_KEY_PD_GANDER, SVS_GENDER, hContact != NULL);
						SetValue(hwndDlg, IDC_STATUSDESCR, hContact, "CList", GG_KEY_STATUSDESCR, SVS_NORMAL, hContact != NULL);
					}
					else switch((char)db_get_b(hContact, gg->m_szModuleName, GG_KEY_PD_GANDER, (BYTE)'?')) {
					case 'F':
						SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 1, 0);
						break;
					case 'M':
						SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 2, 0);
						break;
					default:
						SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 0, 0);
					}

					// Disable when updating
					dat->disableUpdate = FALSE;
					break;
				}
			}
			break;
		}
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			SendMessage(GetParent(hwndDlg),msg,wParam,lParam);
			break;
		case IDC_NICKNAME:
		case IDC_FIRSTNAME:
		case IDC_LASTNAME:
		case IDC_FAMILYNAME:
		case IDC_CITY:
		case IDC_CITYORIGIN:
		case IDC_BIRTHYEAR:
			if (HIWORD(wParam) == EN_CHANGE) {
				if (!dat || dat->hContact || dat->disableUpdate)
					break;
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), TRUE);
				break;
			}
		case IDC_GENDER:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				if (!dat || dat->hContact || dat->disableUpdate)
					break;
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), TRUE);
				break;
			}
		case IDC_SAVE: // Save current user data
			if (HIWORD(wParam) == BN_CLICKED) {
				if (!dat || dat->hContact || dat->disableUpdate)
					break;
				{
				TCHAR text[256];
				GGPROTO *gg = dat->gg;

				if (!gg->isonline())
				{
					MessageBox(NULL,
						TranslateT("You have to be logged in before you can change your details."),
						gg->m_tszUserName, MB_OK | MB_ICONSTOP);
					break;
				}

				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), FALSE);

				gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_WRITE);

				GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_LASTNAME, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_NICKNAME, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_CITY, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_CITY, T2Utf(text));

				// Gadu-Gadu Female <-> Male
				switch(SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0)) {
				case 1:
					gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_FEMALE);
					break;
				case 2:
					gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_MALE);
					break;
				default:
					gg_pubdir50_add(req, GG_PUBDIR50_GENDER, "");
				}

				GetDlgItemText(hwndDlg, IDC_BIRTHYEAR, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_FAMILYNAME, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_FAMILYNAME, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_CITYORIGIN, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_FAMILYCITY, T2Utf(text));

				// Run update
				gg_pubdir50_seq_set(req, GG_SEQ_CHINFO);
				gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_detailsdlgproc", 35, "sess_mutex", 1);
				gg_pubdir50(gg->sess, req);
				gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 35, 1, "sess_mutex", 1);
				dat->updating = TRUE;

				gg_pubdir50_free(req);
				}
				break;
			}
		}
		break;

	case WM_DESTROY:
		if (dat) mir_free(dat);
		break;
	}
	return FALSE;
}
Пример #16
0
unsigned int
GaduSession::pubDirSearch(  ResLine& query, int ageFrom, int ageTo, bool onlyAlive )
{
	QString bufYear;
	unsigned int reqNr;
	gg_pubdir50_t searchRequest;

	if ( !session_ ) {
		return 0;
	}

	searchRequest = gg_pubdir50_new( GG_PUBDIR50_SEARCH_REQUEST );
	if ( !searchRequest ) {
		return 0;
	}

	if ( query.uin == 0 ) {
		if (query.firstname.length()) {
			gg_pubdir50_add( searchRequest, GG_PUBDIR50_FIRSTNAME,
						(const char*)textcodec->fromUnicode( query.firstname ) );
		}
		if ( query.surname.length() ) {
			gg_pubdir50_add( searchRequest, GG_PUBDIR50_LASTNAME,
						(const char*)textcodec->fromUnicode( query.surname ) );
		}
		if ( query.nickname.length() ) {
			gg_pubdir50_add( searchRequest, GG_PUBDIR50_NICKNAME,
						(const char*)textcodec->fromUnicode( query.nickname ) );
		}
		if ( query.city.length() ) {
			gg_pubdir50_add( searchRequest, GG_PUBDIR50_CITY,
						(const char*)textcodec->fromUnicode( query.city ) );
		}
		if ( ageFrom || ageTo ) {
			QString yearFrom = QString::number( QDate::currentDate().year() - ageFrom );
			QString yearTo = QString::number( QDate::currentDate().year() - ageTo );

			if ( ageFrom && ageTo ) {
				gg_pubdir50_add( searchRequest, GG_PUBDIR50_BIRTHYEAR,
							(const char*)textcodec->fromUnicode( yearFrom + " " + yearTo ) );
			}
			if ( ageFrom ) {
				gg_pubdir50_add( searchRequest, GG_PUBDIR50_BIRTHYEAR,
							(const char*)textcodec->fromUnicode( yearFrom ) );
			}
			else {
				gg_pubdir50_add( searchRequest, GG_PUBDIR50_BIRTHYEAR,
							(const char*)textcodec->fromUnicode( yearTo ) );
			}
		}

		if ( query.gender.length() == 1 ) {
                	gg_pubdir50_add( searchRequest, GG_PUBDIR50_GENDER,
				(const char *)((const char*)textcodec->fromUnicode( query.gender ) ) );
		}

		if ( onlyAlive ) {
			gg_pubdir50_add( searchRequest, GG_PUBDIR50_ACTIVE, GG_PUBDIR50_ACTIVE_TRUE );
		}
	}
	// otherwise we are looking only for one fellow with this nice UIN
	else{
		gg_pubdir50_add( searchRequest, GG_PUBDIR50_UIN, QString::number( query.uin ).ascii() );
	}

	gg_pubdir50_add( searchRequest, GG_PUBDIR50_START, QString::number( searchSeqNr_ ).ascii() );
	reqNr = gg_pubdir50( session_, searchRequest );
	gg_pubdir50_free( searchRequest );

	return reqNr;
}
Пример #17
0
int main(int argc, char **argv)
{

   // Do po³±czenia
   struct gg_session *sess;
   struct gg_event *e;
   struct gg_login_params p;
   list_t searches = NULL;

   char *last_search_first_name = NULL;
   char *last_search_last_name = NULL;
   char *last_search_nickname = NULL;
   uin_t last_search_uin = 0;

   gg_pubdir50_t res;
   // Do wyszukiwania
   char *user;
   gg_pubdir50_t req;
   int i, all = 0;

   if (argc < 4) {
      fprintf(stderr, "Usage: %s <my_uid> <my_password> <params>\n\n", argv[0]);
      fprintf(stderr, "Parameters:\n");
      fprintf(stderr, " -f <val> (--first)     - first name\n");
      fprintf(stderr, " -l <val> (--last)      - last name\n");
      fprintf(stderr, " -n <val> (--nickname)  - nickname\n");
      fprintf(stderr, " -c <val> (--city)      - city\n");
      fprintf(stderr, " -u <val> (--uin)       - user ID\n");
      fprintf(stderr, " -F       (--female)    - search females only\n");
      fprintf(stderr, " -M       (--male)      - search males only\n");
      fprintf(stderr, " -a       (--active)    - search on-line users only\n");
      fprintf(stderr, " -b <val> (--born)      - year of birth\n");
      fprintf(stderr, " -s <val> (--start)     - search offset\n");
      fprintf(stderr, " -A       (--all)       - show all\n");
      return 1;
   }

   // Poziom debugowania
   gg_debug_level = 5;

   memset(&p, 0, sizeof(p));
   p.uin = atoi(argv[1]);
   p.password = argv[2];


   // Po³±czenie

   if (!(sess = gg_login(&p))) {
      printf("Connection failed: %s\n", strerror(errno));
      gg_free_session(sess);
      return 1;
   }

   printf("Po³±czono.\n");

   // Wyszukiwanie

   if (!sess || sess->state != GG_STATE_CONNECTED) {
      printf("not_connected\n");
      return 1;
   }

   argv = argv + 3;

   // próba odpalenia trybu szukania konkretnego usera
   user = strdup(argv[0]);

   // Konwersja do CP
   for (i = 0; argv[i]; i++) {
      iso_to_cp(argv[i]);
   }

   // Zapytanie
   if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH))) {
      printf("\n");
      return 1;
   }

   // wyszukiwanie UIN
   if (argv[0] && argv[0][0] != '-') {
      uin_t uin = get_uin(user);

      if (!uin) {
	 printf("User not found (%s)\n", user);
	 return 1;
      }

      gg_pubdir50_add(req, GG_PUBDIR50_UIN, itoa(uin));
      i = 1;

   } else {
      i = 0;
   }

   free(user);

   // Parsowanie argumentów
   for (; argv[i]; i++) {
      char *arg = argv[i];

      if (match_arg(arg, 'f', "first", 2) && argv[i + 1]) {
	 gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, argv[++i]);
	 continue;
      }

      if (match_arg(arg, 'l', "last", 2) && argv[i + 1]) {
	 gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, argv[++i]);
	 continue;
      }

      if (match_arg(arg, 'n', "nickname", 2) && argv[i + 1]) {
	 gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, argv[++i]);
	 continue;
      }

      if (match_arg(arg, 'c', "city", 2) && argv[i + 1]) {
	 gg_pubdir50_add(req, GG_PUBDIR50_CITY, argv[++i]);
	 continue;
      }

      if (match_arg(arg, 'u', "uin", 2) && argv[i + 1]) {
	 gg_pubdir50_add(req, GG_PUBDIR50_UIN, itoa(get_uin(argv[++i])));
	 continue;
      }

      if (match_arg(arg, 's', "start", 3) && argv[i + 1]) {
	 gg_pubdir50_add(req, GG_PUBDIR50_START, argv[++i]);
	 continue;
      }

      if (match_arg(arg, 'F', "female", 2)) {
	 gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_FEMALE);
	 continue;
      }

      if (match_arg(arg, 'M', "male", 2)) {
	 gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_MALE);
	 continue;
      }

      if (match_arg(arg, 'a', "active", 2)) {
	 gg_pubdir50_add(req, GG_PUBDIR50_ACTIVE, GG_PUBDIR50_ACTIVE_TRUE);
	 continue;
      }

      if (match_arg(arg, 'b', "born", 2) && argv[i + 1]) {
	 char *foo = strchr(argv[++i], ':');

	 if (foo)
	    *foo = ' ';

	 gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, argv[i]);
	 continue;
      }

      if (match_arg(arg, 'A', "all", 3)) {
	 if (!gg_pubdir50_get(req, 0, GG_PUBDIR50_START))
	    gg_pubdir50_add(req, GG_PUBDIR50_START, "0");
	 all = 1;
	 continue;
      }

      printf("invalid_params\n");

      gg_pubdir50_free(req);

      return 1;
   }

   // Wywo³anie wyszukiwania

   if (!gg_pubdir50(sess, req)) {
      printf("Search failed\n");
      return 1;
   }

   // Dodanie wyniku wyszykiwania do listy
   if (all) {
      list_add(&searches, req, 0);
   } else {
      gg_pubdir50_free(req);
   }

   // Pêtla czekaj±ca na wynik wyszukiwania
   while (1) {
      if (!(e = gg_watch_fd(sess))) {
	 printf("Connection interrupted: %s\n", strerror(errno));
	 gg_logoff(sess);
	 gg_free_session(sess);
	 return 1;
      }

      if (e->type == GG_EVENT_PUBDIR50_SEARCH_REPLY) {
         printf("Received results!\n");
         res = e->event.pubdir50;
         all = i = 0;
         int count, all = 0;
         list_t l;
         uin_t last_uin = 0;

         if ((count = gg_pubdir50_count(res)) < 1) {
            printf("search_not_found\n");
            return 1;
         }

         gg_debug(GG_DEBUG_MISC, "handle_search50, count = %d\n", gg_pubdir50_count(res));

         for (l = searches; l; l = l->next) {
            gg_pubdir50_t req = l->data;

            if (gg_pubdir50_seq(req) == gg_pubdir50_seq(res)) {
               all = 1;
               break;
            }
         }

         for (i = 0; i < count; i++) {
            const char *__fmnumber = gg_pubdir50_get(res, i, "fmnumber");
            const char *uin = (__fmnumber) ? __fmnumber : "?";

            const char *__firstname = gg_pubdir50_get(res, i, "firstname");
            char *firstname = strdup((__firstname) ? __firstname : "");

            const char *__lastname = gg_pubdir50_get(res, i, "lastname");
            char *lastname = strdup((__lastname) ? __lastname : "");

            const char *__nickname = gg_pubdir50_get(res, i, "nickname");
            char *nickname = strdup((__nickname) ? __nickname : "");

            const char *__fmstatus = gg_pubdir50_get(res, i, "fmstatus");
            int status = (__fmstatus) ? atoi(__fmstatus) : GG_STATUS_NOT_AVAIL;

            const char *__birthyear = gg_pubdir50_get(res, i, "birthyear");
            const char *birthyear = (__birthyear && strcmp(__birthyear, "0")) ? __birthyear : "-";

            const char *__city = gg_pubdir50_get(res, i, "city");
            char *city = strdup((__city) ? __city : "");

            char *name, *active;

            const char *target = NULL;

            cp_to_iso(firstname);
            cp_to_iso(lastname);
            cp_to_iso(nickname);
            cp_to_iso(city);

            if (count == 1 && !all) {
               free(last_search_first_name);
               free(last_search_last_name);
               free(last_search_nickname);
               last_search_first_name = strdup(firstname);
               last_search_last_name = strdup(lastname);
               last_search_nickname = strdup(nickname);
               last_search_uin = atoi(uin);
            }

            name = saprintf("%s %s", firstname, lastname);

            switch (status & 0x7f) {
               case GG_STATUS_AVAIL:
               case GG_STATUS_AVAIL_DESCR:
                  active = strdup("Avail");
                  break;
               case GG_STATUS_BUSY:
               case GG_STATUS_BUSY_DESCR:
                  active = strdup("Busy");
                  break;
               case GG_STATUS_INVISIBLE:
               case GG_STATUS_INVISIBLE_DESCR:
                  active = strdup("Invis");
                  break;
               default:
                  active = strdup("Inact");
            }

            printf("UIN\t: %s\n", uin);
            printf("Name\t: %s\n", name);
            printf("Nick\t: %s\n", nickname);
            printf("City\t: %s\n", city);
            printf("Birth\t: %s\n", birthyear);
            printf("Active\t: %s\n\n", active);

            free(name);
            free(active);

            free(firstname);
            free(lastname);
            free(nickname);
            free(city);

            last_uin = atoi(uin);
         }

         /* je¶li mieli¶my ,,/find --all'', szukamy dalej */
         for (l = searches; l; l = l->next) {
            gg_pubdir50_t req = l->data;
            uin_t next;

            if (gg_pubdir50_seq(req) != gg_pubdir50_seq(res))
               continue;

            /* nie ma dalszych? to dziêkujemy */
            if (!(next = gg_pubdir50_next(res)) || !sess || next < last_uin) {
               list_remove(&searches, req, 0);
               gg_pubdir50_free(req);
               break;
            }

            gg_pubdir50_add(req, GG_PUBDIR50_START, itoa(next));
            gg_pubdir50(sess, req);

            break;
         }
	 gg_free_event(e);
	 break;
      }

      gg_free_event(e);
   }

   gg_logoff(sess);
   gg_free_session(sess);

   return 0;
}