Beispiel #1
0
void logoff_contacts(BOOL bCleanup) {
	MCONTACT hContact;
	char *szProto;
	DBVARIANT dbv = { 0 };

	LOG(("logoff_contacts: Logging off contacts."));
	for (hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) {
		szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, hContact, 0);
		if (szProto != NULL && !strcmp(szProto, SKYPE_PROTONAME))
		{
			if (db_get_w(hContact, SKYPE_PROTONAME, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE)
				db_set_w(hContact, SKYPE_PROTONAME, "Status", ID_STATUS_OFFLINE);

			db_unset(hContact, SKYPE_PROTONAME, "CallId");
			if (db_get_b(hContact, SKYPE_PROTONAME, "ChatRoom", 0) == 1)
			{
				if (db_get_ts(hContact, SKYPE_PROTONAME, "ChatRoomID", &dbv)) continue;
				RemChat(dbv.ptszVal);
				db_free(&dbv);
			}
			if (db_get_s(hContact, SKYPE_PROTONAME, "Typing_Stream", &dbv) == 0)
			{
				if (bCleanup) SkypeSend("ALTER APPLICATION libpurple_typing DISCONNECT %s", dbv.pszVal);
				db_free(&dbv);
				db_unset(hContact, SKYPE_PROTONAME, "Typing_Stream");
			}

		}
	}
	if (bCleanup && (protocol >= 5 || bIsImoproxy)) SkypeSend("DELETE APPLICATION libpurple_typing");
}
void logoff_contacts(BOOL bCleanup) {
	HANDLE hContact;
	char *szProto;
	DBVARIANT dbv={0};

	LOG(("logoff_contacts: Logging off contacts."));
	for (hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);hContact != NULL;hContact=(HANDLE)CallService( MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) {
		szProto = (char*)CallService( MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0 );
		if (szProto!=NULL && !strcmp(szProto, SKYPE_PROTONAME))
		{
			if (DBGetContactSettingWord(hContact, SKYPE_PROTONAME, "Status", ID_STATUS_OFFLINE)!=ID_STATUS_OFFLINE)
				DBWriteContactSettingWord(hContact, SKYPE_PROTONAME, "Status", ID_STATUS_OFFLINE);

			DBDeleteContactSetting(hContact, SKYPE_PROTONAME, "CallId");
			if (DBGetContactSettingByte(hContact, SKYPE_PROTONAME, "ChatRoom", 0)==1)
			{
				if (DBGetContactSettingTString(hContact, SKYPE_PROTONAME, "ChatRoomID", &dbv)) continue;
				RemChat (dbv.ptszVal);
				DBFreeVariant(&dbv);
			}
			if (DBGetContactSettingString(hContact, SKYPE_PROTONAME, "Typing_Stream", &dbv) == 0)
			{
				if (bCleanup) SkypeSend ("ALTER APPLICATION libpurple_typing DISCONNECT %s", dbv.pszVal);
				DBFreeVariant(&dbv);
				DBDeleteContactSetting(hContact, SKYPE_PROTONAME, "Typing_Stream");
			}

		}
	}
	if (bCleanup && (protocol>=5 || bIsImoproxy)) SkypeSend ("DELETE APPLICATION libpurple_typing");
}
HANDLE add_contact(char *name, DWORD flags) {
	HANDLE hContact;

	// already on list?
	if (hContact=find_contact(name)) {
		if (!(flags & PALF_TEMPORARY) && DBGetContactSettingByte(hContact, "CList", "NotOnList", 1)) {
			DBDeleteContactSetting( hContact, "CList", "NotOnList" );
			DBDeleteContactSetting( hContact, "CList", "Hidden" );
		}
		LOG(("add_contact: Found %s", name));
		return hContact; // already there, return handle
	}
	// no, so add
	
	LOG(("add_contact: Adding %s", name));
	hContact=(HANDLE)CallServiceSync(MS_DB_CONTACT_ADD, 0, 0);
	if (hContact) {
		if (CallServiceSync(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact,(LPARAM)SKYPE_PROTONAME)!=0) {
			LOG(("add_contact: Ouch! MS_PROTO_ADDTOCONTACT failed for some reason"));
			CallServiceSync(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
			return NULL;
		}
		if (name[0]) DBWriteContactSettingString(hContact, SKYPE_PROTONAME, SKYPE_NAME, name);

   		if (flags & PALF_TEMPORARY ) {
			DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
			DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
		}
		if (name[0]) {
			SkypeSend("GET USER %s DISPLAYNAME", name);
		} else {LOG(("add_contact: Info: The contact added has no name."));}
	} else {LOG(("add_contact: Ouch! MS_DB_CONTACT_ADD failed for some reason"));}
	LOG(("add_contact succeeded"));
	return hContact;
}
Beispiel #4
0
void SetChatTopic(const TCHAR *szChatId, TCHAR *szTopic, BOOL bSet)
{
	MCONTACT hContact = find_chat (szChatId);
	char *szUTFTopic;

	GCDEST gcd = { SKYPE_PROTONAME, szChatId, GC_EVENT_TOPIC };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.ptszText = szTopic;
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.time = (DWORD)time (NULL);
	CallService(MS_GC_EVENT, 0, (LPARAM)&gce);

	gcd.iType = GC_EVENT_SETSBTEXT;
	CallService(MS_GC_EVENT, 0, (LPARAM)&gce);

	if (bSet) {
#ifdef _UNICODE
		szUTFTopic=(char*)make_utf8_string(szTopic);
#else
		if (utf8_encode(szTopic, &szUTFTopic)==-1) szUTFTopic = NULL;
#endif
		if (szUTFTopic) {
			SkypeSend ("ALTER CHAT "STR" SETTOPIC %s", szChatId, szUTFTopic);
			free (szUTFTopic);
		}
		testfor ("ALTER CHAT SETTOPIC", INFINITE);
	}

	if (hContact)
		db_set_ts(hContact, SKYPE_PROTONAME, "Nick", szTopic);
}
Beispiel #5
0
void WatchDogTimer(char *dummy) {
	LOG(("WatchDogTimer started"));
	WatchDogRunning=TRUE;
	while (1) {
		Sleep(PING_INTERVAL);
		if (!WatchDog) {
			OUTPUT("Ouch.. It seems that Skype has died unexpectedly. Trying to restart.");
			ConnectToSkypeAPI((void *)TRUE);
		}
		WatchDog=0;
		SkypeSend("PING");
	}
}
Beispiel #6
0
void KillChatSession(GCDEST *gcd)
{
	GCEVENT gce = { sizeof(gce), gcd };
	EnterCriticalSection(&m_GCMutex);
	LOG(("KillChatSession: Groupchatsession terminated."));
	gcd->iType = GC_EVENT_CONTROL;
	if (SkypeSend ("ALTER CHAT "STR" LEAVE", gcd->ptszID) == 0)
	{
		CallService(MS_GC_EVENT, SESSION_OFFLINE, (LPARAM)&gce);
		CallService(MS_GC_EVENT, SESSION_TERMINATE, (LPARAM)&gce);
	}
	LeaveCriticalSection(&m_GCMutex);
}
Beispiel #7
0
void InviteUser(const TCHAR *szChatId)
{
	HMENU tMenu = CreatePopupMenu();
	MCONTACT hContact = db_find_first(), hInvitedUser;
	DBVARIANT dbv;
	HWND tWindow;
	POINT pt;
	gchat_contacts *gc;
	int j;

	if (!szChatId || !(gc=GetChat(szChatId))) return;

	// add the heading
	AppendMenu(tMenu, MF_STRING|MF_GRAYED|MF_DISABLED, (UINT_PTR)0, TranslateT("&Invite user..."));
	AppendMenu(tMenu, MF_SEPARATOR, (UINT_PTR)1, NULL);
    
	// generate a list of contact
	while (hContact) {
		char *szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, hContact,0 );
		if (szProto && !strcmp(SKYPE_PROTONAME, szProto) &&
			!db_get_b(hContact, SKYPE_PROTONAME, "ChatRoom", 0) &&
			 db_get_w(hContact, SKYPE_PROTONAME, "Status", ID_STATUS_OFFLINE)!=ID_STATUS_OFFLINE) 
		{
			BOOL alreadyInSession = FALSE;
			for (j=0; j<gc->mJoinedCount; j++) {
				if (gc->mJoinedContacts[j].hContact==hContact) {
					alreadyInSession = TRUE;
					break;
				}
			}
            if (!alreadyInSession)
				AppendMenu(tMenu, MF_STRING, (UINT_PTR)hContact, 
					(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR));
        }
		hContact = db_find_next(hContact);
	}

	tWindow = CreateWindow(_T("EDIT"),_T(""),0,1,1,1,1,NULL,NULL,hInst,NULL);

	GetCursorPos (&pt);
	hInvitedUser = (MCONTACT)TrackPopupMenu(tMenu, TPM_NONOTIFY | TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD, pt.x, pt.y, 0, tWindow, NULL);
	DestroyMenu(tMenu);
	DestroyWindow(tWindow);

	if (!hInvitedUser || db_get_s(hInvitedUser, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) 
		return;
	SkypeSend ("ALTER CHAT "STR" ADDMEMBERS %s", szChatId, dbv.pszVal);
	db_free(&dbv);

}
Beispiel #8
0
MCONTACT add_contact(char *name, DWORD flags)
{
	// already on list?
	MCONTACT hContact = find_contact(name);
	if (hContact) {
		if (!(flags & PALF_TEMPORARY) && db_get_b(hContact, "CList", "NotOnList", 1)) {
			db_unset(hContact, "CList", "NotOnList");
			db_unset(hContact, "CList", "Hidden");
		}
		LOG(("add_contact: Found %s", name));
		return hContact; // already there, return handle
	}
	// no, so add

	LOG(("add_contact: Adding %s", name));
	hContact = (MCONTACT)CallServiceSync(MS_DB_CONTACT_ADD, 0, 0);
	if (hContact) {
		if (CallServiceSync(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)SKYPE_PROTONAME) != 0) {
			LOG(("add_contact: Ouch! MS_PROTO_ADDTOCONTACT failed for some reason"));
			CallServiceSync(MS_DB_CONTACT_DELETE, hContact, 0);
			return NULL;
		}
		if (name[0]) db_set_s(hContact, SKYPE_PROTONAME, SKYPE_NAME, name);

		if (flags & PALF_TEMPORARY) {
			db_set_b(hContact, "CList", "NotOnList", 1);
			db_set_b(hContact, "CList", "Hidden", 1);
		}
		if (name[0]) {
			SkypeSend("GET USER %s DISPLAYNAME", name);
		}
		else { LOG(("add_contact: Info: The contact added has no name.")); }
	}
	else { LOG(("add_contact: Ouch! MS_DB_CONTACT_ADD failed for some reason")); }
	LOG(("add_contact succeeded"));
	return hContact;
}
Beispiel #9
0
static void KickUser (MCONTACT hContact, GCHOOK *gch)
{
	char *ptr;

	EnterCriticalSection(&m_GCMutex);
	if (SkypeSend ("ALTER CHAT "STR" KICK "STR, gch->pDest->ptszID, gch->ptszUID)!=-1) {
		if (ptr=SkypeRcv("ALTER CHAT KICK", 2000)) {
			if (strncmp(ptr, "ERROR", 5)) {
				GCDEST gcd = { SKYPE_PROTONAME, gch->pDest->ptszID, GC_EVENT_KICK };
				GCEVENT gce = { sizeof(gce), &gcd };
				gce.time = (DWORD)time(NULL);
				gce.dwFlags = GCEF_ADDTOLOG;
				gce.ptszUID = gch->ptszUID;

				CONTACTINFO ci = {0};
				ci.cbSize = sizeof(ci);
				ci.szProto = SKYPE_PROTONAME;
				ci.dwFlag = CNF_DISPLAY | CNF_TCHAR;
				ci.hContact = hContact;
				if (hContact && !CallService(MS_CONTACT_GETCONTACTINFO,0,(LPARAM)&ci)) gce.ptszNick=ci.pszVal; 
				else gce.ptszNick=gce.ptszUID;
        
				DBVARIANT dbv;
				if (!db_get_ts(NULL, SKYPE_PROTONAME, "Nick", &dbv)) {
					gce.ptszStatus = dbv.ptszVal;		
					CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
					RemChatContact (GetChat(gcd.ptszID), gch->ptszUID);
					db_free(&dbv);
				}
				if (ci.pszVal) mir_free (ci.pszVal);
			}
			free (ptr);
		}
	}
	LeaveCriticalSection(&m_GCMutex);
}
Beispiel #10
0
void ServerThread(char *dummy) {
	unsigned int length, received;
	char *buf, command, reply;

	LOG(("ServerThread started"));
	AcceptSocket=INVALID_SOCKET;
	while( AcceptSocket == INVALID_SOCKET) {
		if ((AcceptSocket = accept( ListenSocket, NULL, NULL ))==INVALID_SOCKET) {
			LOG(("ServerThread: Byebye..."));
			SetEvent(ServerThreadBye);
			bail_out(1);
			return;
		}
		OUTPUT("Connection by client");
		while(1) {
			if ((received=recv(AcceptSocket, (char *)&length, sizeof(length), 0))==SOCKET_ERROR ||
				received==0) 
			{
				OUTPUT("Connection was closed by client. See ya soon! :)");
				break;
			}
			// Command mode
			if (length==0) {
				reply=0;
				if (recv(AcceptSocket, (char *)&command, 1, 0)==SOCKET_ERROR) {
					OUTPUT("Connection to client was lost.");
					break;
				}
#ifdef USE_AUTHENTICATION
				if (command==AUTHENTICATE)
					if (password) reply=0x01;		 // Ok, go ahead
					else command=0;
#endif
				if (command==CAPABILITIES)
					reply=password?USE_AUTHENTICATION:0;

				if (send(AcceptSocket, (char *)&reply, 1, 0)==SOCKET_ERROR) {
					OUTPUT("Connection to client was lost.");
					break;
				}
				continue;
			}
			// Normal Skype API-call
			if (!(buf=calloc(1, length+1))) {
				OUTPUT("Out of memory error while allocating buffer space.");
				break;
			}
			if (recv(AcceptSocket, buf, length, 0)==SOCKET_ERROR) {
				OUTPUT("Connection to client was lost.");
				free(buf);
				break;
			}
			switch (command) {
#ifdef USE_AUTHENTICATION
			case 0x01: // Compare hash
				if (password && !strcmp(password, buf)) Authenticated=TRUE;
				else Authenticated=FALSE;
				if (Authenticated) {
					OUTPUT("User authenticated succesfully.");
					reply=1; 
				} else {
					OUTPUT("User authentication failed!! (Intruder?)");
					reply=0;
				}
				if (send(AcceptSocket, (char *)&reply, 1, 0)==SOCKET_ERROR) {
					OUTPUT("Connection to client was lost.");
					break;
				}
				command=0;
				break;
#endif
			default:
#ifdef USE_AUTHENTICATION
				if (password && !Authenticated) break;
#endif
				SkypeSend(buf);
			}
			command=0;
			free(buf);
		}
		AcceptSocket=INVALID_SOCKET;
#ifdef USE_AUTHENTICATION
		Authenticated=FALSE;
#endif
	}
}
Beispiel #11
0
int __cdecl  ChatInit(WPARAM wParam, LPARAM lParam)
{
	DBVARIANT dbv, dbv2;
	char *szChatName;
	int iRet = -1;

	if (!wParam) return -1;

	GCSESSION gcw = { sizeof(gcw) };
	gcw.iType = GCW_CHATROOM;
	gcw.pszModule = SKYPE_PROTONAME;

	if (!(szChatName = SkypeGet ("CHAT", (char *)wParam, "FRIENDLYNAME")) || !*szChatName)
		gcw.ptszName=TranslateT("Unknown"); else {
#ifdef _UNICODE
		gcw.ptszName=make_unicode_string((const unsigned char*)szChatName);
		free (szChatName);
		szChatName = (char*)gcw.ptszName;
#else
		gcw.ptszName=szChatName;
#endif
	}
	gcw.ptszID = make_nonutf_tchar_string((const unsigned char*)wParam);
	gcw.ptszStatusbarText = NULL;
	EnterCriticalSection(&m_GCMutex);
	if (!CallService(MS_GC_NEWSESSION, 0, (LPARAM)&gcw)) {
		char *szChatRole;

		GCDEST gcd = { SKYPE_PROTONAME, gcw.ptszID, GC_EVENT_ADDGROUP };
		GCEVENT gce = { sizeof(gce), &gcd };
		gce.ptszStatus = _T("CREATOR");
		// BUG: Groupchat returns nonzero on success here in earlier versions, so we don't check
		// it here
		CallService(MS_GC_EVENT, 0, (LPARAM)&gce);
		gce.ptszStatus = _T("MASTER");
		CallService(MS_GC_EVENT, 0, (LPARAM)&gce);
		gce.ptszStatus = _T("HELPER");
		CallService(MS_GC_EVENT, 0, (LPARAM)&gce);
		gce.ptszStatus = _T("USER");
		CallService(MS_GC_EVENT, 0, (LPARAM)&gce);
		gce.ptszStatus = _T("LISTENER");
		CallService(MS_GC_EVENT, 0, (LPARAM)&gce);
		gce.ptszStatus = _T("APPLICANT");
		CallService(MS_GC_EVENT, 0, (LPARAM)&gce);

		gcd.iType = GC_EVENT_JOIN;
		gce.ptszStatus = NULL;
		if (protocol >=7 && (szChatRole = SkypeGet ("CHAT", (char *)wParam, "MYROLE"))) {
			if (strncmp(szChatRole, "ERROR", 5))
			{
#ifdef _UNICODE
				gce.ptszStatus = make_unicode_string((const unsigned char*)szChatRole);
				free (szChatRole);
#else
				gce.ptszStatus = szChatRole;
#endif
			}
		}
		if (!gce.ptszStatus) gce.ptszStatus=_tcsdup(_T("CREATOR"));

		if (!db_get_ts(NULL, SKYPE_PROTONAME, "Nick", &dbv)) {
			if (!db_get_ts(NULL, SKYPE_PROTONAME, SKYPE_NAME, &dbv2)) {
				gce.ptszNick = dbv.ptszVal;
				gce.ptszUID = dbv2.ptszVal;
				gce.time = 0;
				gce.bIsMe = TRUE;
				gce.dwFlags |= GCEF_ADDTOLOG;
				if (!CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce)) {
					gcd.iType = GC_EVENT_CONTROL;
					if (!lParam)
						CallService(MS_GC_EVENT, SESSION_INITDONE, (LPARAM)&gce);
					CallService(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce);
					CallService(MS_GC_EVENT, lParam ? WINDOW_HIDDEN : WINDOW_VISIBLE, (LPARAM)&gce);
					SkypeSend ("GET CHAT %s MEMBERS", (char *)wParam);
					iRet = 0;
				}
				else {LOG (("ChatInit: Joining 'me' failed."));}
			}
			db_free(&dbv2);
		}
		free ((void*)gce.ptszStatus);
		db_free(&dbv);
	}
	free (szChatName);
	free_nonutf_tchar_string ((void*)gcw.ptszID);
	LeaveCriticalSection(&m_GCMutex);
	return iRet;
}