akio0911 / hcrepos

Hacker's Cafe Repository

This URL has Read+Write access

akio0911 (author)
Tue May 26 03:55:37 -0700 2009
commit  67085a8b0b5795c3697b7566b59076fc6557c716
tree    28a1534bf6f1cdf68f8c54456ebd397659d461b2
parent  e49191446673ddf4f7babb6ad30c37a4212a65c6
hcrepos / SkypeLogger / SkypeController.m
100644 129 lines (112 sloc) 3.821 kb
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
//
// SkypeController.mm
// SkypeAPITest
//
// Created by Janno Teelem on 14/04/2005.
// Copyright 2005-2006 Skype Limited. All rights reserved.
//
 
#import "SkypeController.h"
 
NSString* const cMyApplicationName = @"My Skype API Tester";
 
@implementation SkypeController
 
-(void)appendString:(NSString*)string
{
NSFileHandle* output;
@try {
// #1 パスをフルパスに
NSString* outputFile = @"~/skype.log";
NSString* outputFilePath = [outputFile stringByExpandingTildeInPath];
// #2 出力するファイルを生成
output = [NSFileHandle fileHandleForWritingAtPath:outputFilePath];
[output seekToEndOfFile];
NSData* data = [string dataUsingEncoding:NSUTF8StringEncoding];
[output writeData:data];
} @finally {
        [output closeFile];
}
}
 
/////////////////////////////////////////////////////////////////////////////////////
- (void)awakeFromNib
{
[SkypeAPI setSkypeDelegate:self];
}
 
/////////////////////////////////////////////////////////////////////////////////////
// required delegate method
- (NSString*)clientApplicationName
{
return cMyApplicationName;
}
 
/////////////////////////////////////////////////////////////////////////////////////
// optional delegate method
- (void)skypeAttachResponse:(unsigned)aAttachResponseCode
{
switch (aAttachResponseCode)
{
case 0:
[infoView insertText:@"Failed to connect\n"];
break;
case 1:
[infoView insertText:@"Successfully connected to Skype!\n"];
break;
default:
[infoView insertText:@"Unknown response from Skype\n"];
break;
}
 
}
 
/////////////////////////////////////////////////////////////////////////////////////
// optional delegate method
- (void)skypeNotificationReceived:(NSString*)aNotificationString
{
[infoView insertText:aNotificationString];
[infoView insertText:@"\n"];
// ここでパースすればよい
NSArray *array = [aNotificationString componentsSeparatedByString:@" "];
NSLog(@"[array count] = %d", [array count]);
NSLog(@"<#message#>");
if([array count] == 4 && [[array objectAtIndex:0] compare:@"MESSAGE"] == NSOrderedSame && [[array objectAtIndex:2] compare:@"STATUS"] == NSOrderedSame && ([[array objectAtIndex:3] compare:@"SENT"] == NSOrderedSame || [[array objectAtIndex:3] compare:@"RECEIVED"] == NSOrderedSame))
{
NSString* command = [[NSString alloc] initWithFormat:@"GET MESSAGE %@ BODY", [array objectAtIndex:1]];
NSString* returnedString = [SkypeAPI sendSkypeCommand:command];
[command release];
if (returnedString)
{
[self appendString:returnedString];
[self appendString:@"\n"];
}
}
}
 
/////////////////////////////////////////////////////////////////////////////////////
// optional delegate method
- (void)skypeBecameAvailable:(NSNotification*)aNotification
{
[infoView insertText:@"Skype became available\n"];
}
 
/////////////////////////////////////////////////////////////////////////////////////
// optional delegate method
- (void)skypeBecameUnavailable:(NSNotification*)aNotification
{
[infoView insertText:@"Skype became unavailable\n\n"];
}
 
/////////////////////////////////////////////////////////////////////////////////////
- (IBAction)onConnectBtn:(id)sender
{
[SkypeAPI connect];
}
 
/////////////////////////////////////////////////////////////////////////////////////
- (IBAction)onDisconnectBtn:(id)sender
{
[SkypeAPI disconnect];
}
 
/////////////////////////////////////////////////////////////////////////////////////
- (IBAction)onSendBtn:(id)sender
{
[infoView insertText:[commandField stringValue]];
[infoView insertText:@"\n"];
 
NSString* returnedString = [SkypeAPI sendSkypeCommand:[commandField stringValue]];
if (returnedString)
{
[infoView insertText:returnedString];
[infoView insertText:@"\n"];
}
}
 
/////////////////////////////////////////////////////////////////////////////////////
@end