Welcome to mirror list, hosted at ThFree Co, Russian Federation.

skype_messaging_carbon2.c - github.com/EionRobb/skype4pidgin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9316381b60e1d123f8f9573faf762754cd258c29 (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271


#include <Carbon/Carbon.h>
#include <CoreFoundation/CoreFoundation.h>


typedef struct SkypeDelegate
{
	// Required member
	CFStringRef clientApplicationName;
	
	// Optional members, can be NULL
	void (*SkypeNotificationReceived)(CFStringRef aNotificationString);
	void (*SkypeAttachResponse)(unsigned int aAttachResponseCode);			// 0 - failed, 1 - success
	void (*SkypeBecameAvailable)(CFPropertyListRef aNotification);
	void (*SkypeBecameUnavailable)(CFPropertyListRef aNotification);
} SkypeDelegate;

static SkypeDelegate *delegate = NULL;
static int isavailable = 0;

char *
CFStringToCString(CFStringRef input)
{
	int strlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8);
	char *output = NewPtr(strlen+1);
	CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8);
	return output;
}

void
availabilityUpdateCallback(
	CFNotificationCenterRef center,
	void *observer,
	CFStringRef name,
	const void *object,
	CFDictionaryRef userInfo)
{
	CFNumberRef number = NULL;
	number = (CFNumberRef) CFDictionaryGetValue(userInfo, CFSTR("SKYPE_API_AVAILABILITY"));
	CFNumberGetValue(number, kCFNumberIntType, &isavailable);
	
	printf("Availability update: %d\n", isavailable);
}

void
debugCallback(
	CFNotificationCenterRef center,
	void *observer,
	CFStringRef name,
	const void *object,
	CFDictionaryRef userInfo)
{
	if (!userInfo)
		return;
	
	CFIndex count = CFDictionaryGetCount(userInfo);
	const void *keys[count];
	const void *values[count];
	CFDictionaryGetKeysAndValues(userInfo, keys, values);
	for(int i=0; i<count; i++)
	{
		printf("For i=%d, key: %s\n", i,
					CFStringToCString((CFStringRef)keys[i]));
	}
	printf("Debug callback: %s\n", CFStringToCString(name));
}


void
apiNotificationCallback(
	CFNotificationCenterRef center,
	void *observer,
	CFStringRef name,
	const void *object,
	CFDictionaryRef userInfo)
{
	CFStringRef string = NULL;
	string = (CFStringRef) CFDictionaryGetValue(userInfo, CFSTR("SKYPE_API_NOTIFICATION_STRING"));
	if (string && delegate && delegate->SkypeNotificationReceived)
	{
		delegate->SkypeNotificationReceived(string);
	}
}


void
attachResponseCallback(
	CFNotificationCenterRef center,
	void *observer,
	CFStringRef name,
	const void *object,
	CFDictionaryRef userInfo)
{
	const void *response = CFDictionaryGetValue(userInfo, CFSTR("SKYPE_API_ATTACH_RESPONSE"));
	if (response)
	{
		CFNumberRef number = (CFNumberRef) response;
		unsigned int response_num;
		
		CFNumberGetValue(number, kCFNumberIntType, &response_num);
		
		if (delegate && delegate->SkypeAttachResponse)
		{
			delegate->SkypeAttachResponse(response_num);
		}
	}
}


void
skypeQuitCallback(
	CFNotificationCenterRef center,
	void *observer,
	CFStringRef name,
	const void *object,
	CFDictionaryRef userInfo)
{
	if (delegate && delegate->SkypeBecameAvailable)
		delegate->SkypeBecameUnavailable(NULL);
}


void
skypeAvailableCallback(
	CFNotificationCenterRef center,
	void *observer,
	CFStringRef name,
	const void *object,
	CFDictionaryRef userInfo)
{
	if (delegate && delegate->SkypeBecameAvailable)
		delegate->SkypeBecameAvailable(NULL);
}


// STANDARD SKYPE.H BITS:


void
SetSkypeDelegate(SkypeDelegate *aDelegate)
{
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
	
	if (delegate == NULL)
	{
		delegate = aDelegate;

		CFNotificationCenterAddObserver(
			center,
			delegate->clientApplicationName,
			apiNotificationCallback,
			CFSTR("SKSkypeAPINotification"),
			NULL,
			CFNotificationSuspensionBehaviorDeliverImmediately);

		CFNotificationCenterAddObserver(
			center,
			delegate->clientApplicationName,
			attachResponseCallback,
			CFSTR("SKSkypeAttachResponse"),
			NULL,
			CFNotificationSuspensionBehaviorDeliverImmediately);

		CFNotificationCenterAddObserver(
			center,
			delegate->clientApplicationName,
			skypeQuitCallback,
			CFSTR("SKSkypeWillQuit"),
			NULL,
			CFNotificationSuspensionBehaviorDeliverImmediately);

		CFNotificationCenterAddObserver(
			center,
			delegate->clientApplicationName,
			skypeAvailableCallback,
			CFSTR("SKSkypeBecameAvailable"),
			NULL,
			CFNotificationSuspensionBehaviorDeliverImmediately);
	}
}

SkypeDelegate *
GetSkypeDelegate(void)
{
	return delegate;
}


void
RemoveSkypeDelegate(void)
{
	delegate = NULL;
}

int IsSkypeAvailable(void)
{
	//is skype available?
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();

	CFNotificationCenterAddObserver(
		center,
		delegate->clientApplicationName,
		availabilityUpdateCallback,
		CFSTR("SKAvailabilityUpdate"),
		NULL,
		CFNotificationSuspensionBehaviorDeliverImmediately);

	CFNotificationCenterPostNotification(
		center,
		CFSTR("SKSkypeAPIAvailabilityRequest"),
		NULL,
		NULL,
		TRUE);
	
	int timeout = 0;
	//wait for isavailable to not be -1;
	while(isavailable == 0 && timeout<2)
	{
		RunCurrentEventLoop(1);
		timeout++;
	}
	int avail = isavailable;
	isavailable = 0;
	return avail;
}

int IsSkypeRunning(void)
{
	return 1;
}

void
ConnectToSkype(void)
{
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
	
	//do the connect
	CFNotificationCenterPostNotification(
		center,
		CFSTR("SKSkypeAPIAttachRequest"),
		delegate->clientApplicationName,
		NULL,
		TRUE);
}

void SendSkypeCommand(CFStringRef command)
{
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
	
	//send message
	CFNotificationCenterPostNotification(
		center,
		CFSTR("SKSkypeAPICommand"),
		NULL,
		NULL,
		TRUE);
}

void DisconnectFromSkype(void)
{
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
	
	//disconnect
	CFNotificationCenterPostNotification(
		center,
		CFSTR("SKSkypeAPIDetachRequest"),
		NULL,
		NULL,
		TRUE);
}