Cleaning up the AIM code base and adding the right icon from IM Kit.

This commit is contained in:
plfiorini 2010-05-12 21:48:47 +00:00
parent e524826f03
commit c599c12c7f
4 changed files with 289 additions and 311 deletions

View File

@ -1,3 +1,8 @@
/*
* Copyright 2010, Alexander Botero-Lowry. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <stdio.h>
#include <errno.h>
#include <string>
@ -8,12 +13,11 @@
const char* kProtocolName = "aim";
CayaProtocolMessengerInterface *gServerMsgr;
CayaProtocolMessengerInterface* gServerMsgr;
AIMProtocol::AIMProtocol()
{
}
@ -26,11 +30,12 @@ AIMProtocol::~AIMProtocol()
status_t
AIMProtocol::Init(CayaProtocolMessengerInterface* msgr)
{
printf("init\n");
gServerMsgr = msgr;
fIMCommHandle = imcomm_create_handle();
fOnline = false;
// Register callbacks
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_INCOMING, (void (*)())GotMessage);
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_SIGNON, (void (*)())BuddyOnline);
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_SIGNOFF, (void (*)())BuddyOffline);
@ -40,7 +45,7 @@ AIMProtocol::Init(CayaProtocolMessengerInterface* msgr)
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_IDLEINFO, (void (*)())BuddyIdle);
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_PROFILE, (void (*)())BuddyProfile);
// XXX missing IMCOMM_ERROR, IMCOMM_FORMATTED_SN, IMCOMM_HANDLE_DELETED
// TODO: Missing IMCOMM_ERROR, IMCOMM_FORMATTED_SN, IMCOMM_HANDLE_DELETED
return B_OK;
}
@ -57,48 +62,37 @@ AIMProtocol::Shutdown()
status_t
AIMProtocol::Process(BMessage* msg)
{
msg->PrintToStream();
switch (msg->what) {
case IM_MESSAGE:
{
case IM_MESSAGE: {
int32 im_what = 0;
msg->FindInt32("im_what", &im_what);
switch (im_what) {
case IM_SET_STATUS:
{
case IM_SET_STATUS: {
int32 status = msg->FindInt32("status");
BString status_msg("");
msg->FindString("message", &status_msg);
char *smsg = strdup(status_msg.String());
char* smsg = strdup(status_msg.String());
switch (status) {
case CAYA_ONLINE:
{
if (!fOnline) {
if (!fOnline)
A_LogOn();
} else {
else
imcomm_set_unaway(fIMCommHandle);
}
break;
}
case CAYA_AWAY:
imcomm_set_away(fIMCommHandle,
smsg);
imcomm_set_away(fIMCommHandle, smsg);
break;
case CAYA_EXTENDED_AWAY:
imcomm_set_away(fIMCommHandle,
smsg);
// UnsupportedOperation(); ?
imcomm_set_away(fIMCommHandle, smsg);
//UnsupportedOperation(); ?
break;
case CAYA_DO_NOT_DISTURB:
imcomm_set_away(fIMCommHandle,
smsg);
// UnsupportedOperation(); ?
imcomm_set_away(fIMCommHandle, smsg);
//UnsupportedOperation(); ?
break;
case CAYA_OFFLINE:
LogOff();
@ -113,25 +107,18 @@ AIMProtocol::Process(BMessage* msg)
msg.AddInt32("im_what", IM_STATUS_SET);
msg.AddString("protocol", kProtocolName);
msg.AddInt32("status", status);
gServerMsgr->SendMessage(&msg);
break;
}
case IM_SET_NICKNAME:
{
UnsupportedOperation();
break;
}
case IM_SEND_MESSAGE:
{
case IM_SEND_MESSAGE: {
const char* buddy = msg->FindString("id");
const char* sms = msg->FindString("message");
imcomm_im_send_message(fIMCommHandle, buddy,
sms, 0);
imcomm_im_send_message(fIMCommHandle, buddy, sms, 0);
// XXX send a message to let caya know
// we did it
// XXX send a message to let caya know we did it
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_MESSAGE_SENT);
msg.AddString("protocol", kProtocolName);
@ -141,57 +128,40 @@ AIMProtocol::Process(BMessage* msg)
gServerMsgr->SendMessage(&msg);
break;
}
case IM_REGISTER_CONTACTS:
{
case IM_REGISTER_CONTACTS: {
const char* buddy = NULL;
char *buddy_copy;
for (int i = 0;
msg->FindString("id", i, &buddy) == B_OK;
i++) {
for (int32 i = 0; msg->FindString("id", i, &buddy) == B_OK; i++) {
buddy_copy = strdup(buddy);
imcomm_im_add_buddy(fIMCommHandle, buddy_copy);
free(buddy_copy);
}
break;
}
case IM_UNREGISTER_CONTACTS:
{
case IM_UNREGISTER_CONTACTS: {
const char* buddy = NULL;
for (int i = 0;
msg->FindString("id", i, &buddy) == B_OK;
i++) {
for (int32 i = 0; msg->FindString("id", i, &buddy) == B_OK; i++)
imcomm_im_remove_buddy(fIMCommHandle, buddy);
}
break;
}
case IM_USER_STARTED_TYPING:
{
// UnsupportedOperation();
//UnsupportedOperation();
break;
}
case IM_USER_STOPPED_TYPING:
{
// UnsupportedOperation();
//UnsupportedOperation();
break;
}
case IM_GET_CONTACT_INFO:
UnsupportedOperation();
break;
case IM_SEND_AUTH_ACK:
{
UnsupportedOperation();
break;
}
case IM_SPECIAL_TO_PROTOCOL:
UnsupportedOperation();
break;
default:
msg->PrintToStream();
return B_ERROR;
}
break;
@ -206,10 +176,11 @@ AIMProtocol::Process(BMessage* msg)
void
AIMProtocol::UnsupportedOperation() {
printf("noop\n");
AIMProtocol::UnsupportedOperation()
{
}
const char*
AIMProtocol::GetSignature()
{
@ -232,11 +203,10 @@ AIMProtocol::UpdateSettings(BMessage& msg)
msg.FindString("username", &username);
msg.FindString("password", &password);
// msg.FindString("server", &server);
// msg.FindInt32("port", &server);
//msg->FindString("server", &server);
//msg->FindInt32("port", &server);
if ((username == NULL) || (password == NULL)) {
//LOG( kProtocolName, liHigh, "Invalid settings!");
printf("Invalid settings");
return B_ERROR;
}
@ -246,6 +216,7 @@ AIMProtocol::UpdateSettings(BMessage& msg)
fPassword = password;
// XXX kill the handle and sign back in?
}
return B_OK;
}
@ -261,9 +232,6 @@ status_t
AIMProtocol::A_LogOn()
{
int ret = imcomm_im_signon(fIMCommHandle, fUsername, fPassword);
printf("ret: %d\n", ret);
if (ret == IMCOMM_RET_OK) {
fIMCommThread = spawn_thread(WaitForData, "imcomm receiver",
B_LOW_PRIORITY, this);
@ -273,6 +241,7 @@ AIMProtocol::A_LogOn()
return B_OK;
}
return B_ERROR;
}
@ -286,10 +255,11 @@ AIMProtocol::LogOff()
return B_OK;
}
int32
AIMProtocol::WaitForData(void *aimProtocol) {
AIMProtocol::WaitForData(void* aimProtocol)
{
// XXX No need for aimProtocol since imcomm does its own callback thing
printf("wait\n");
fd_set readset;
struct timeval tm;
@ -299,7 +269,8 @@ AIMProtocol::WaitForData(void *aimProtocol) {
tm.tv_usec = 500000;
IMCOMM_RET ret = imcomm_select(1, &readset, NULL, NULL, &tm);
if (ret != IMCOMM_RET_OK && errno == EINTR) continue;
if (ret != IMCOMM_RET_OK && errno == EINTR)
continue;
}
return 0;
@ -307,7 +278,8 @@ AIMProtocol::WaitForData(void *aimProtocol) {
void
AIMProtocol::GotMessage(void *imcomm, char *who, int auto, char *recvmsg) {
AIMProtocol::GotMessage(void* imcomm, char* who, int auto, char* recvmsg)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_MESSAGE_RECEIVED);
msg.AddString("protocol", kProtocolName);
@ -317,8 +289,10 @@ AIMProtocol::GotMessage(void *imcomm, char *who, int auto, char *recvmsg) {
gServerMsgr->SendMessage(&msg);
}
void
AIMProtocol::BuddyOnline(void *imcomm, char *who) {
AIMProtocol::BuddyOnline(void* imcomm, char* who)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_STATUS_CHANGED);
msg.AddString("protocol", kProtocolName);
@ -328,11 +302,12 @@ AIMProtocol::BuddyOnline(void *imcomm, char *who) {
gServerMsgr->SendMessage(&msg);
}
void
AIMProtocol::BuddyOffline(void *imcomm, char *who) {
AIMProtocol::BuddyOffline(void* imcomm, char* who)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_STATUS_CHANGED);
msg.AddString("protocol", kProtocolName);
msg.AddString("id", who);
msg.AddInt32("status", CAYA_OFFLINE);
@ -340,13 +315,17 @@ AIMProtocol::BuddyOffline(void *imcomm, char *who) {
gServerMsgr->SendMessage(&msg);
}
void
AIMProtocol::BuddyAway(void *imcomm, char *who) {
AIMProtocol::BuddyAway(void* imcomm, char* who)
{
imcomm_request_awaymsg(imcomm, who);
}
void
AIMProtocol::BuddyBack(void *imcomm, char *who) {
AIMProtocol::BuddyBack(void* imcomm, char* who)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_STATUS_CHANGED);
msg.AddString("protocol", kProtocolName);
@ -356,10 +335,11 @@ AIMProtocol::BuddyBack(void *imcomm, char *who) {
gServerMsgr->SendMessage(&msg);
}
void
AIMProtocol::BuddyAwayMsg(void *imcomm, char *who, char *awaymsg) {
BMessage msg(IM_MESSAGE);
void
AIMProtocol::BuddyAwayMsg(void* imcomm, char* who, char* awaymsg)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_STATUS_CHANGED);
msg.AddString("protocol", kProtocolName);
msg.AddString("id", who);
@ -369,8 +349,10 @@ AIMProtocol::BuddyAwayMsg(void *imcomm, char *who, char *awaymsg) {
gServerMsgr->SendMessage(&msg);
}
void
AIMProtocol::BuddyIdle(void *imcomm, char *who, long idletime) {
AIMProtocol::BuddyIdle(void* imcomm, char* who, long idletime)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_STATUS_CHANGED);
msg.AddString("protocol", kProtocolName);
@ -378,43 +360,35 @@ AIMProtocol::BuddyIdle(void *imcomm, char *who, long idletime) {
msg.AddInt32("status", CAYA_ONLINE);
gServerMsgr->SendMessage(&msg);
}
void
AIMProtocol::BuddyProfile(void *handle, char *who, char *profile) {
AIMProtocol::BuddyProfile(void* handle, char* who, char* profile)
{
// XXX vcard is probably an issue
}
char *
AIMProtocol::strip_html(const char *message)
AIMProtocol::strip_html(const char* message)
{
char *temp;
int x, xnot, y, count, inhtml;
char* temp;
uint32 x, xnot, y, count, inhtml;
size_t len = strlen(message);
temp = (char*)malloc(len + 1);
for (x = 0, count = 0, inhtml = 0; x < len; x++) {
if (message[x] == '<' && inhtml == 0) {
if (x + 10 < len) {
/**
** Convert links into
** [http://url] link text
**/
// Convert links into [http://url] link text
if (strncasecmp(message + x, "<a href=\"", 9) == 0) {
xnot = x + 9;
for (y = xnot; y < len; y++) {
if (message[y] == '\"') {
/*
* we don't have to
* worry about the
* buffer size,
* because it's
* guaranteed to be
* bigger
*/
// We don't have to worry about the buffer size,
// because it's guaranteed to be bigger
memcpy(temp + count, "[", 1);
memcpy(temp + count + 1, message + xnot,
y - xnot);
@ -426,6 +400,7 @@ AIMProtocol::strip_html(const char *message)
}
}
}
if (x + 3 < len) {
if (strncasecmp(message + x, "<br>", 4) == 0) {
temp[count] = '\n';
@ -434,15 +409,18 @@ AIMProtocol::strip_html(const char *message)
continue;
}
}
inhtml = 1;
continue;
}
if (inhtml) {
if (message[x] == '>')
inhtml = 0;
continue;
}
if (message[x] == '&') {
if (x + 4 < len) {
if (strncmp(message + x, "&amp;", 5) == 0) {
@ -452,6 +430,7 @@ AIMProtocol::strip_html(const char *message)
continue;
}
}
if (x + 5 < len) {
if (strncmp(message + x, "&quot;", 6) == 0) {
temp[count] = '\"';
@ -459,6 +438,7 @@ AIMProtocol::strip_html(const char *message)
x += 5;
continue;
}
if (strncmp(message + x, "&nbsp;", 6) == 0) {
temp[count] = ' ';
count++;
@ -466,6 +446,7 @@ AIMProtocol::strip_html(const char *message)
continue;
}
}
if (x + 3 < len) {
if (strncmp(message + x, "&lt;", 4) == 0) {
temp[count] = '<';
@ -474,6 +455,7 @@ AIMProtocol::strip_html(const char *message)
continue;
}
}
if (x + 3 < len) {
if (strncmp(message + x, "&gt;", 4) == 0) {
temp[count] = '>';
@ -483,6 +465,7 @@ AIMProtocol::strip_html(const char *message)
}
}
}
if (message[x] == '\n' || message[x] == '\r')
continue;
else

View File

@ -1,9 +1,9 @@
/*
* Copyright 2004-2009, IM Kit Team. All rights reserved.
* Copyright 2010, Alexander Botero-Lowry. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef IMKIT_AIM_H
#define IMKIT_AIM_H
#ifndef _AIM_H
#define _AIM_H
#include <List.h>
#include <Messenger.h>
@ -19,40 +19,40 @@ public:
AIMProtocol();
virtual ~AIMProtocol();
virtual status_t Init( CayaProtocolMessengerInterface* );
virtual status_t Init(CayaProtocolMessengerInterface* messenger);
virtual status_t Shutdown();
virtual status_t Process( BMessage * );
virtual const char * GetSignature();
virtual const char * GetFriendlySignature();
virtual status_t UpdateSettings( BMessage & );
virtual status_t Process(BMessage*);
virtual const char* GetSignature();
virtual const char* GetFriendlySignature();
virtual status_t UpdateSettings(BMessage&);
virtual uint32 GetEncoding();
static int32 WaitForData(void *);
static void GotMessage(void *, char *, int, char *);
static void BuddyOnline(void *, char *);
static void BuddyOffline(void *, char *);
static void BuddyAway(void *, char *);
static void BuddyBack(void *, char *);
static void BuddyAwayMsg(void *, char *, char *);
static void BuddyIdle(void *, char *, long);
static void BuddyProfile(void *, char *, char *);
BString fUsername;
BString fPassword;
bool fOnline;
thread_id fIMCommThread;
void * fIMCommHandle;
static int32 WaitForData(void*);
static void GotMessage(void*, char*, int, char*);
static void BuddyOnline(void*, char*);
static void BuddyOffline(void*, char*);
static void BuddyAway(void*, char*);
static void BuddyBack(void*, char*);
static void BuddyAwayMsg(void*, char*, char*);
static void BuddyIdle(void*, char*, long);
static void BuddyProfile(void*, char*, char*);
protected:
status_t A_LogOn();
status_t LogOff();
void UnsupportedOperation();
static char * strip_html (const char *message);
static char* strip_html(const char* message);
private:
BString fUsername;
BString fPassword;
bool fOnline;
thread_id fIMCommThread;
void* fIMCommHandle;
};
#endif // IMKIT_AIM_H
#endif // _AIM_H

View File

@ -2,7 +2,7 @@
resource app_version {
major = 0,
middle = 0,
minor = 0,
minor = 1,
variety = B_APPV_ALPHA,
internal = 0,
@ -12,23 +12,13 @@ resource app_version {
};
resource vector_icon {
$"6E636966080501040046020106023E40000000000000003D4000494000470000"
$"7EFFFFFFFFE5E1DA02000602000000BBC0004000000000009220244AF0000000"
$"33CCFC3366FF02000602000000BA000040000000000092202448800000336699"
$"FF6699CC02000602000000B9000040000000000092202448E00000CC0000FFFF"
$"000002000602000000BA000040000000000092202448800000FF9900FFFBFF00"
$"02000602000000BA000040000000000092202448800000006600FF00CC000A02"
$"06C22622C7562239222E342E2B2E3D4146364441483C50404C3C504A444A4E55"
$"44CBB634CBB83E5E2A0206C22622C7562239222E342E2B2E3D4146364441483C"
$"50404C3C504C464A505744CBB634CBB83E5E2A02024C265928532A583B59335D"
$"350610CAFFFEAF375335543B3B5A3B5A395D325D355D2C5D274F275627483241"
$"2C413541BDA7C2A83942BDA7C2A8394A3F463F463C40324036402A40234F2346"
$"2358325E2A5E395EBF5C5A3F5CBF5C5A3F544053080234313C310404FE372C37"
$"393739373A393B383B3A3B3B393B3A3B390406FE0B4536403640363F363E383E"
$"373E383E393E393E3A403B3F3B413B453A0405FE03453C453445344533433244"
$"324332403240323F323E343E333E3408024D2C4D3C0803553C4F3655300D0A00"
$"01001001178400040A020101000A010102000A0101032021210A010204053021"
$"2101178200040A0102070630212101178200040A010108301D2101178200040A"
$"0102090830212101178200040A030103000A040204051001178200040A050207"
$"061001178200040A060108301C2001178200040A07020908100117820004"
$"6E636966050501020106023E40000000000000003E4000490000490000FFFFCC"
$"007FFFFF00020106023B80000000000000003B80004A6000460000FFFFCC007C"
$"FFFF00020112023AD09E3A55D0BD34993DDD2B49C9E2492C1BFFFF007AFFD102"
$"0112023C80000000000000003C80004A0000420000FFFF007AFFD102060CFFBB"
$"B348464846524A5C5A56505C5A525E525E505A405048503A56265C305C265C24"
$"5238443850383A4034483A483A4C3C5C5C425C425844484402044A22C18022C5"
$"F722542C54B58C54BA034A36C5F736C18036402C40BA0340B58C060A00010010"
$"01178400040A0001011001178400040A010100000A020101000A030100100115"
$"7F00040A0401011001157F0004"
};

View File

@ -1,8 +1,13 @@
/*
* Copyright 2010, Alexander Botero-Lowry. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "AIM.h"
extern "C" __declspec(dllexport) CayaProtocol *main_protocol ();
extern "C" __declspec(dllexport) CayaProtocol *main_protocol();
CayaProtocol *main_protocol ()
CayaProtocol *main_protocol()
{
return (CayaProtocol *)(new AIMProtocol());
return (CayaProtocol*)new AIMProtocol();
}