Exemple #1
0
char* ChangeInfoData::GetItemSettingText(int i, char *buf, size_t bufsize)
{
	char *text = buf;
	int alloced = 0;

	buf[0] = '\0';

	if (settingData[i].value == 0 && !(setting[i].displayType & LIF_ZEROISVALID))
	{
		if (setting[i].displayType & LIF_CHANGEONLY)
			text = ICQTranslateUtfStatic(LPGEN("<unremovable once applied>"), buf, bufsize);
		else
			text = ICQTranslateUtfStatic(LPGEN("<empty>"), buf, bufsize);
	}
	else 
	{
		switch (setting[i].displayType & LIM_TYPE) {
		case LI_STRING:
		case LI_LONGSTRING:
			text = BinaryToEscapes((char*)settingData[i].value);
			alloced = 1;
			break;

		case LI_NUMBER:
			_itoa(settingData[i].value, text, 10);
			break;

		case LI_LIST:
			if (setting[i].dbType == DBVT_ASCIIZ) 
				text = ICQTranslateUtfStatic((char*)settingData[i].value, buf, bufsize);
			else 
			{
				text = ICQTranslateUtfStatic(LPGEN("Unknown value"), buf, bufsize);

				FieldNamesItem *list = (FieldNamesItem*)setting[i].pList;
				for (int j=0; TRUE; j++)
					if (list[j].code == settingData[i].value) 
					{
						text = ICQTranslateUtfStatic(list[j].text, buf, bufsize);
						break;
					}
					else if (!list[j].text)
					{
						if (list[j].code == settingData[i].value)
							text = ICQTranslateUtfStatic("Unspecified", buf, bufsize);
						break;
					}
			}
			break;
		}
	}
	if (setting[i].displayType & LIF_PASSWORD) 
	{
		if (settingData[i].changed) 
			for (int j=0; text[j]; j++) text[j] = '*';
		else 
		{
			if (alloced) 
			{
				SAFE_FREE(&text);
				alloced = 0;
			}
			text = "********";
		}
	}
	if (text != buf)
	{
		char *tmp = text;

		text = null_strcpy(buf, text, bufsize - 1);
		if (alloced)
			SAFE_FREE(&tmp);
	}

	return text;
}
Exemple #2
0
char* ChangeInfoData::GetItemSettingText(int i, char *buf, size_t bufsize)
{
	char *text = buf;
	int alloced = 0;

	buf[0] = '\0';

	const SettingItem &si = setting[i];
	SettingItemData &sid = settingData[i];
	if (sid.value == 0 && !(si.displayType & LIF_ZEROISVALID)) {
		if (si.displayType & LIF_CHANGEONLY)
			text = ICQTranslateUtfStatic(LPGEN("<unremovable once applied>"), buf, bufsize);
		else
			text = ICQTranslateUtfStatic(LPGEN("<empty>"), buf, bufsize);
	}
	else {
		switch (si.displayType & LIM_TYPE) {
		case LI_STRING:
		case LI_LONGSTRING:
			text = BinaryToEscapes((char*)sid.value);
			alloced = 1;
			break;

		case LI_NUMBER:
			_itoa(sid.value, text, 10);
			break;

		case LI_LIST:
			if (si.dbType == DBVT_ASCIIZ)
				text = ICQTranslateUtfStatic((char*)sid.value, buf, bufsize);
			else {
				text = ICQTranslateUtfStatic(LPGEN("Unknown value"), buf, bufsize);

				FieldNamesItem *list = (FieldNamesItem*)si.pList;
				if (list == timezonesField) {
					HANDLE tz = TimeZone_CreateByContact(NULL, ppro->m_szModuleName, 0);
					text = make_utf8_string_static(TimeZone_GetDescription(TimeZone_GetName(tz)), buf, bufsize);
					break;
				}

				for (int j = 0;; j++) {
					if (list[j].code == sid.value) {
						text = ICQTranslateUtfStatic(list[j].text, buf, bufsize);
						break;
					}
					else if (!list[j].text) {
						if (list[j].code == sid.value)
							text = ICQTranslateUtfStatic("Unspecified", buf, bufsize);
						break;
					}
				}
			}
			break;
		}
	}

	if (si.displayType & LIF_PASSWORD) {
		if (sid.changed) {
			for (int j = 0; text[j]; j++)
				text[j] = '*';
		}
		else {
			if (alloced) {
				SAFE_FREE(&text);
				alloced = 0;
			}
			text = "********";
		}
	}
	if (text != buf) {
		char *tmp = text;

		text = null_strcpy(buf, text, bufsize - 1);
		if (alloced)
			SAFE_FREE(&tmp);
	}

	return text;
}
Exemple #3
0
void __cdecl CIcqProto::ServerThread(serverthread_start_info *infoParam)
{
	serverthread_info info = {0};

	info.isLoginServer = 1;
	info.wAuthKeyLen = infoParam->wPassLen;
	null_strcpy((char*)info.szAuthKey, infoParam->szPass, info.wAuthKeyLen);
	// store server port
	info.wServerPort = infoParam->nloc.wPort;

	srand(time(NULL));

	ResetSettingsOnConnect();

	// Connect to the login server
	NetLog_Server("Authenticating to server");
	{
		NETLIBOPENCONNECTION nloc = infoParam->nloc;
		nloc.timeout = 6;
		if (m_bGatewayMode)
			nloc.flags |= NLOCF_HTTPGATEWAY;

		hServerConn = NetLib_OpenConnection(m_hServerNetlibUser, NULL, &nloc);

		SAFE_FREE((void**)&nloc.szHost);
		SAFE_FREE((void**)&infoParam);

		if (hServerConn && m_bSecureConnection)
		{
			if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hServerConn, 0))
			{
				icq_LogMessage(LOG_ERROR, LPGEN("Unable to connect to ICQ login server, SSL could not be negotiated"));
				SetCurrentStatus(ID_STATUS_OFFLINE);
				NetLib_CloseConnection(&hServerConn, TRUE);
				return;
			}
		}

	}

	// Login error
	if (hServerConn == NULL)
	{
		DWORD dwError = GetLastError();

		SetCurrentStatus(ID_STATUS_OFFLINE);

		icq_LogUsingErrorCode(LOG_ERROR, dwError, LPGEN("Unable to connect to ICQ login server"));
		return;
	}

	// Initialize direct connection ports
	{
		DWORD dwInternalIP;
		BYTE bConstInternalIP = getSettingByte(NULL, "ConstRealIP", 0);

		info.hDirectBoundPort = NetLib_BindPort(icq_newConnectionReceived, this, &wListenPort, &dwInternalIP);
		if (!info.hDirectBoundPort)
		{
			icq_LogUsingErrorCode(LOG_WARNING, GetLastError(), LPGEN("Miranda was unable to allocate a port to listen for direct peer-to-peer connections between clients. You will be able to use most of the ICQ network without problems but you may be unable to send or receive files.\n\nIf you have a firewall this may be blocking Miranda, in which case you should configure your firewall to leave some ports open and tell Miranda which ports to use in M->Options->ICQ->Network."));
			wListenPort = 0;
			if (!bConstInternalIP) deleteSetting(NULL, "RealIP");
		}
		else if (!bConstInternalIP)
			setSettingDword(NULL, "RealIP", dwInternalIP);
	}

	// Initialize rate limiting queues
	{ 
		icq_lock l(m_ratesMutex);

		m_ratesQueue_Request = new rates_queue(this, "request", RML_IDLE_30, RML_IDLE_50, 1);
		m_ratesQueue_Response = new rates_queue(this, "response", RML_IDLE_10, RML_IDLE_30, -1);
	}

	// This is the "infinite" loop that receives the packets from the ICQ server
	{
		int recvResult;
		NETLIBPACKETRECVER packetRecv = {0};

		info.hPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hServerConn, 0x2400);
		packetRecv.cbSize = sizeof(packetRecv);
		packetRecv.dwTimeout = INFINITE;
		while (serverThreadHandle)
		{
			if (info.bReinitRecver)
			{ // we reconnected, reinit struct
				info.bReinitRecver = 0;
				ZeroMemory(&packetRecv, sizeof(packetRecv));
				packetRecv.cbSize = sizeof(packetRecv);
				packetRecv.dwTimeout = INFINITE;
			}

			recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)info.hPacketRecver, (LPARAM)&packetRecv);

			if (recvResult == 0)
			{
				NetLog_Server("Clean closure of server socket");
				break;
			}

			if (recvResult == SOCKET_ERROR)
			{
				NetLog_Server("Abortive closure of server socket, error: %d", GetLastError());
				break;
			}

			if (m_iDesiredStatus == ID_STATUS_OFFLINE)
			{ // Disconnect requested, send disconnect packet
				icq_sendCloseConnection();

				// disconnected upon request
				m_bConnectionLost = FALSE;
				SetCurrentStatus(ID_STATUS_OFFLINE);

				NetLog_Server("Logged off.");
				break;
			}

			// Deal with the packet
			packetRecv.bytesUsed = handleServerPackets(packetRecv.buffer, packetRecv.bytesAvailable, &info);
		}
		serverThreadHandle = NULL;

		// Time to shutdown
		NetLib_CloseConnection(&hServerConn, TRUE);

		// Close the packet receiver (connection may still be open)
		NetLib_SafeCloseHandle(&info.hPacketRecver);

		// Close DC port
		NetLib_SafeCloseHandle(&info.hDirectBoundPort);
	}

	// disable auto info-update thread
	icq_EnableUserLookup(FALSE);

	if (m_iStatus != ID_STATUS_OFFLINE && m_iDesiredStatus != ID_STATUS_OFFLINE)
	{
		if (!info.bLoggedIn)
			icq_LogMessage(LOG_FATAL, LPGEN("Connection failed.\nLogin sequence failed for unknown reason.\nTry again later."));

		// set flag indicating we were kicked out
		m_bConnectionLost = TRUE;

		SetCurrentStatus(ID_STATUS_OFFLINE);
	}

	// signal keep-alive thread to stop
	StopKeepAlive(&info);

	// Close all open DC connections
	CloseContactDirectConns(NULL);

	// Close avatar connection if any
	StopAvatarThread();

	// Offline all contacts
	HANDLE hContact = FindFirstContact();
	while (hContact)
	{
		DWORD dwUIN;
		uid_str szUID;

		if (!getContactUid(hContact, &dwUIN, &szUID))
		{
			if (getContactStatus(hContact) != ID_STATUS_OFFLINE)
			{
				char tmp = 0;

				setSettingWord(hContact, "Status", ID_STATUS_OFFLINE);

				handleXStatusCaps(dwUIN, szUID, hContact, (BYTE*)&tmp, 0, &tmp, 0);
			}
		}

		hContact = FindNextContact(hContact);
	}

	setSettingDword(NULL, "LogonTS", 0); // clear logon time

	servlistPendingFlushOperations(); // clear pending operations list

	{ // release rates queues
		icq_lock l(m_ratesMutex);

		SAFE_DELETE((void_struct**)&m_ratesQueue_Request);
		SAFE_DELETE((void_struct**)&m_ratesQueue_Response);
		SAFE_DELETE((void_struct**)&m_rates);
	}

	FlushServerIDs();         // clear server IDs list

	NetLog_Server("%s thread ended.", "Server");
}