summaryrefslogtreecommitdiff
path: root/protocols/SkypeClassic/src/voiceservice.cpp
blob: 2a22bbe86c84d0c1199225478ba8580174973967 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "skype.h"
#include "skypeapi.h"
#include "skypesvc.h"
#include "voiceservice.h"
#include <m_voiceservice.h>

#pragma warning (push)
#pragma warning (disable: 4100) // unreferenced formal parameter
#include <m_utils.h>
#pragma warning (pop)

HANDLE hVoiceNotify = NULL;
BOOL has_voice_service = FALSE;

extern char g_szProtoName[];


BOOL HasVoiceService()
{
	return has_voice_service;
}

void NofifyVoiceService(HANDLE hContact, char *callId, int state) 
{
	VOICE_CALL vc = {0};
	vc.cbSize = sizeof(vc);
	vc.szModule = SKYPE_PROTONAME;
	vc.id = callId;
	vc.flags = VOICE_CALL_CONTACT;
	vc.state = state;
	vc.hContact = hContact;
	NotifyEventHooks(hVoiceNotify, (WPARAM) &vc, 0);
}

static INT_PTR VoiceGetInfo(WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(wParam);
	UNREFERENCED_PARAMETER(lParam);

	return VOICE_SUPPORTED | VOICE_CALL_CONTACT | VOICE_CAN_HOLD;
}

static HANDLE FindContactByCallId(char *callId)
{
	HANDLE hContact;
	int iCmpRes;
	for (hContact = db_find_first();
			hContact != NULL;
			hContact = db_find_next(hContact))
	{
		char *szProto = (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);

		DBVARIANT dbv;
		if (szProto != NULL 
			&& !strcmp(szProto, SKYPE_PROTONAME) 
			&& db_get_b(hContact, SKYPE_PROTONAME, "ChatRoom", 0) == 0 
			&& !db_get_s(hContact, SKYPE_PROTONAME, "CallId", &dbv)) 
		{
			iCmpRes = strcmp(callId, dbv.pszVal);
			db_free(&dbv);
			if (iCmpRes == 0) return hContact;
		}
	}

	return NULL;
}

static INT_PTR VoiceCall(WPARAM wParam, LPARAM lParam)
{
	DBVARIANT dbv;

	UNREFERENCED_PARAMETER(lParam);

	if (!wParam) return -1;

	if (db_get_s((HANDLE)wParam, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) 
		return -1;

	SkypeSend("CALL %s", dbv.pszVal);
	db_free (&dbv);

	return 0;
}

static INT_PTR VoiceAnswer(WPARAM wParam, LPARAM lParam)
{
	char *callId = (char *) wParam;

	UNREFERENCED_PARAMETER(lParam);

	if (!wParam) return -1;
	
	if (FindContactByCallId(callId) == NULL)
		return -1;

	SkypeSend("SET %s STATUS INPROGRESS", callId);
	testfor("ERROR", 200);

	return 0;
}

static INT_PTR VoiceDrop(WPARAM wParam, LPARAM lParam)
{
	char *callId = (char *) wParam;

	UNREFERENCED_PARAMETER(lParam);

	if (!wParam) return -1;

	if (FindContactByCallId(callId) == NULL)
		return -1;

	SkypeSend("SET %s STATUS FINISHED", callId);

	return 0;
}

static INT_PTR VoiceHold(WPARAM wParam, LPARAM lParam)
{
	char *callId = (char *) wParam;

	UNREFERENCED_PARAMETER(lParam);

	if (!wParam) return -1;

	if (FindContactByCallId(callId) == NULL)
		return -1;

	SkypeSend("SET %s STATUS ONHOLD", callId);

	return 0;
}

void VoiceServiceInit() 
{
	// leecher, 26.03.2011: Did this ever work in the old versions?? 
	char szEvent[MAXMODULELABELLENGTH];

	_snprintf (szEvent, sizeof(szEvent), "%s%s", SKYPE_PROTONAME, PE_VOICE_CALL_STATE);
	hVoiceNotify = CreateHookableEvent( szEvent );
	CreateProtoService( PS_VOICE_GETINFO, VoiceGetInfo );
	CreateProtoService( PS_VOICE_CALL, VoiceCall );
	CreateProtoService( PS_VOICE_ANSWERCALL, VoiceAnswer );
	CreateProtoService( PS_VOICE_DROPCALL, VoiceDrop );
	CreateProtoService( PS_VOICE_HOLDCALL, VoiceHold );
}

void VoiceServiceExit()
{
	DestroyHookableEvent(hVoiceNotify);
}

void VoiceServiceModulesLoaded() 
{
	has_voice_service = ServiceExists(MS_VOICESERVICE_REGISTER);
}