Cleaning up the AIM code base and adding the right icon from IM Kit.
This commit is contained in:
parent
e524826f03
commit
c599c12c7f
|
@ -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,22 +30,23 @@ AIMProtocol::~AIMProtocol()
|
|||
status_t
|
||||
AIMProtocol::Init(CayaProtocolMessengerInterface* msgr)
|
||||
{
|
||||
printf("init\n");
|
||||
gServerMsgr = msgr;
|
||||
fIMCommHandle = imcomm_create_handle();
|
||||
fOnline = false;
|
||||
|
||||
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);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_BUDDYAWAY, (void (*)())BuddyAway);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_BUDDYUNAWAY, (void (*)())BuddyBack);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_AWAYMSG, (void (*)())BuddyAwayMsg);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_IDLEINFO, (void (*)())BuddyIdle);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_PROFILE, (void (*)())BuddyProfile);
|
||||
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);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_BUDDYAWAY, (void (*)())BuddyAway);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_BUDDYUNAWAY, (void (*)())BuddyBack);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_AWAYMSG, (void (*)())BuddyAwayMsg);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_IDLEINFO, (void (*)())BuddyIdle);
|
||||
imcomm_register_callback(fIMCommHandle, IMCOMM_IM_PROFILE, (void (*)())BuddyProfile);
|
||||
|
||||
// TODO: Missing IMCOMM_ERROR, IMCOMM_FORMATTED_SN, IMCOMM_HANDLE_DELETED
|
||||
|
||||
// XXX missing IMCOMM_ERROR, IMCOMM_FORMATTED_SN, IMCOMM_HANDLE_DELETED
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
@ -57,159 +62,125 @@ AIMProtocol::Shutdown()
|
|||
status_t
|
||||
AIMProtocol::Process(BMessage* msg)
|
||||
{
|
||||
msg->PrintToStream();
|
||||
switch (msg->what) {
|
||||
case IM_MESSAGE: {
|
||||
int32 im_what = 0;
|
||||
|
||||
msg->FindInt32("im_what", &im_what);
|
||||
|
||||
switch (msg->what) {
|
||||
case IM_MESSAGE:
|
||||
{
|
||||
int32 im_what = 0;
|
||||
|
||||
msg->FindInt32("im_what", &im_what);
|
||||
switch (im_what) {
|
||||
case IM_SET_STATUS: {
|
||||
int32 status = msg->FindInt32("status");
|
||||
|
||||
switch (im_what) {
|
||||
case IM_SET_STATUS:
|
||||
{
|
||||
int32 status = msg->FindInt32("status");
|
||||
BString status_msg("");
|
||||
msg->FindString("message", &status_msg);
|
||||
char *smsg = strdup(status_msg.String());
|
||||
BString status_msg("");
|
||||
msg->FindString("message", &status_msg);
|
||||
char* smsg = strdup(status_msg.String());
|
||||
|
||||
switch (status) {
|
||||
case CAYA_ONLINE:
|
||||
{
|
||||
if (!fOnline) {
|
||||
A_LogOn();
|
||||
} else {
|
||||
imcomm_set_unaway(fIMCommHandle);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CAYA_AWAY:
|
||||
imcomm_set_away(fIMCommHandle,
|
||||
smsg);
|
||||
switch (status) {
|
||||
case CAYA_ONLINE:
|
||||
if (!fOnline)
|
||||
A_LogOn();
|
||||
else
|
||||
imcomm_set_unaway(fIMCommHandle);
|
||||
break;
|
||||
case CAYA_AWAY:
|
||||
imcomm_set_away(fIMCommHandle, smsg);
|
||||
break;
|
||||
case CAYA_EXTENDED_AWAY:
|
||||
imcomm_set_away(fIMCommHandle, smsg);
|
||||
//UnsupportedOperation(); ?
|
||||
break;
|
||||
case CAYA_DO_NOT_DISTURB:
|
||||
imcomm_set_away(fIMCommHandle, smsg);
|
||||
//UnsupportedOperation(); ?
|
||||
break;
|
||||
case CAYA_OFFLINE:
|
||||
LogOff();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case CAYA_EXTENDED_AWAY:
|
||||
imcomm_set_away(fIMCommHandle,
|
||||
smsg);
|
||||
free(smsg);
|
||||
|
||||
// UnsupportedOperation(); ?
|
||||
break;
|
||||
case CAYA_DO_NOT_DISTURB:
|
||||
imcomm_set_away(fIMCommHandle,
|
||||
smsg);
|
||||
// UnsupportedOperation(); ?
|
||||
break;
|
||||
case CAYA_OFFLINE:
|
||||
LogOff();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
BMessage msg(IM_MESSAGE);
|
||||
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: {
|
||||
const char* buddy = msg->FindString("id");
|
||||
const char* sms = msg->FindString("message");
|
||||
imcomm_im_send_message(fIMCommHandle, buddy, sms, 0);
|
||||
|
||||
free(smsg);
|
||||
// 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);
|
||||
msg.AddString("id", buddy);
|
||||
msg.AddString("message", sms);
|
||||
|
||||
BMessage msg(IM_MESSAGE);
|
||||
msg.AddInt32("im_what", IM_STATUS_SET);
|
||||
msg.AddString("protocol", kProtocolName);
|
||||
msg.AddInt32("status", status);
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
break;
|
||||
}
|
||||
case IM_REGISTER_CONTACTS: {
|
||||
const char* buddy = NULL;
|
||||
char *buddy_copy;
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
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: {
|
||||
const char* buddy = NULL;
|
||||
|
||||
break;
|
||||
}
|
||||
case IM_SET_NICKNAME:
|
||||
{
|
||||
UnsupportedOperation();
|
||||
break;
|
||||
}
|
||||
case IM_SEND_MESSAGE:
|
||||
{
|
||||
const char* buddy = msg->FindString("id");
|
||||
const char* sms = msg->FindString("message");
|
||||
imcomm_im_send_message(fIMCommHandle, buddy,
|
||||
sms, 0);
|
||||
|
||||
// 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);
|
||||
msg.AddString("id", buddy);
|
||||
msg.AddString("message", sms);
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
break;
|
||||
}
|
||||
case IM_REGISTER_CONTACTS:
|
||||
{
|
||||
const char* buddy = NULL;
|
||||
char *buddy_copy;
|
||||
|
||||
for (int 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:
|
||||
{
|
||||
const char* buddy = NULL;
|
||||
|
||||
for (int i = 0;
|
||||
msg->FindString("id", i, &buddy) == B_OK;
|
||||
i++) {
|
||||
imcomm_im_remove_buddy(fIMCommHandle, buddy);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case IM_USER_STARTED_TYPING:
|
||||
{
|
||||
// UnsupportedOperation();
|
||||
break;
|
||||
}
|
||||
case IM_USER_STOPPED_TYPING:
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
default:
|
||||
// We don't handle this what code
|
||||
return B_ERROR;
|
||||
}
|
||||
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();
|
||||
break;
|
||||
case IM_USER_STOPPED_TYPING:
|
||||
//UnsupportedOperation();
|
||||
break;
|
||||
case IM_GET_CONTACT_INFO:
|
||||
UnsupportedOperation();
|
||||
break;
|
||||
case IM_SEND_AUTH_ACK:
|
||||
UnsupportedOperation();
|
||||
break;
|
||||
case IM_SPECIAL_TO_PROTOCOL:
|
||||
UnsupportedOperation();
|
||||
break;
|
||||
default:
|
||||
return B_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// We don't handle this what code
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AIMProtocol::UnsupportedOperation() {
|
||||
printf("noop\n");
|
||||
AIMProtocol::UnsupportedOperation()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
AIMProtocol::GetSignature()
|
||||
{
|
||||
|
@ -220,7 +191,7 @@ AIMProtocol::GetSignature()
|
|||
const char*
|
||||
AIMProtocol::GetFriendlySignature()
|
||||
{
|
||||
return "AOL Instant Messenger";
|
||||
return "AOL Instant Messenger";
|
||||
}
|
||||
|
||||
|
||||
|
@ -232,20 +203,20 @@ 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;
|
||||
}
|
||||
|
||||
if ((fUsername != username) || (fPassword != password)) {
|
||||
fUsername = username;
|
||||
fPassword = password;
|
||||
// XXX kill the handle and sign back in?
|
||||
}
|
||||
if ((fUsername != username) || (fPassword != password)) {
|
||||
fUsername = username;
|
||||
fPassword = password;
|
||||
// XXX kill the handle and sign back in?
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
@ -261,160 +232,163 @@ 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);
|
||||
resume_thread(fIMCommThread);
|
||||
fIMCommThread = spawn_thread(WaitForData, "imcomm receiver",
|
||||
B_LOW_PRIORITY, this);
|
||||
resume_thread(fIMCommThread);
|
||||
|
||||
fOnline = true;
|
||||
fOnline = true;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
return B_ERROR;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
AIMProtocol::LogOff()
|
||||
{
|
||||
fOnline = false;
|
||||
imcomm_delete_handle_now(fIMCommHandle);
|
||||
fOnline = false;
|
||||
imcomm_delete_handle_now(fIMCommHandle);
|
||||
|
||||
return B_OK;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
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;
|
||||
AIMProtocol::WaitForData(void* aimProtocol)
|
||||
{
|
||||
// XXX No need for aimProtocol since imcomm does its own callback thing
|
||||
fd_set readset;
|
||||
struct timeval tm;
|
||||
|
||||
while (1) {
|
||||
FD_ZERO(&readset);
|
||||
tm.tv_sec = 2;
|
||||
tm.tv_usec = 500000;
|
||||
while (1) {
|
||||
FD_ZERO(&readset);
|
||||
tm.tv_sec = 2;
|
||||
tm.tv_usec = 500000;
|
||||
|
||||
IMCOMM_RET ret = imcomm_select(1, &readset, NULL, NULL, &tm);
|
||||
if (ret != IMCOMM_RET_OK && errno == EINTR) continue;
|
||||
}
|
||||
IMCOMM_RET ret = imcomm_select(1, &readset, NULL, NULL, &tm);
|
||||
if (ret != IMCOMM_RET_OK && errno == EINTR)
|
||||
continue;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
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);
|
||||
msg.AddString("id", who);
|
||||
msg.AddString("message", strip_html(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);
|
||||
msg.AddString("id", who);
|
||||
msg.AddString("message", strip_html(recvmsg));
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AIMProtocol::BuddyOnline(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_ONLINE);
|
||||
AIMProtocol::BuddyOnline(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_ONLINE);
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AIMProtocol::BuddyOffline(void *imcomm, char *who) {
|
||||
BMessage msg(IM_MESSAGE);
|
||||
msg.AddInt32("im_what", IM_STATUS_CHANGED);
|
||||
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);
|
||||
|
||||
msg.AddString("protocol", kProtocolName);
|
||||
msg.AddString("id", who);
|
||||
msg.AddInt32("status", CAYA_OFFLINE);
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AIMProtocol::BuddyAway(void *imcomm, char *who) {
|
||||
imcomm_request_awaymsg(imcomm, who);
|
||||
AIMProtocol::BuddyAway(void* imcomm, char* who)
|
||||
{
|
||||
imcomm_request_awaymsg(imcomm, who);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AIMProtocol::BuddyBack(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_ONLINE);
|
||||
AIMProtocol::BuddyBack(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_ONLINE);
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AIMProtocol::BuddyAwayMsg(void *imcomm, char *who, char *awaymsg) {
|
||||
BMessage msg(IM_MESSAGE);
|
||||
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);
|
||||
msg.AddInt32("status", CAYA_EXTENDED_AWAY);
|
||||
msg.AddString("message", strip_html(awaymsg));
|
||||
|
||||
msg.AddInt32("im_what", IM_STATUS_CHANGED);
|
||||
msg.AddString("protocol", kProtocolName);
|
||||
msg.AddString("id", who);
|
||||
msg.AddInt32("status", CAYA_EXTENDED_AWAY);
|
||||
msg.AddString("message", strip_html(awaymsg));
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AIMProtocol::BuddyIdle(void *imcomm, char *who, long idletime) {
|
||||
BMessage msg(IM_MESSAGE);
|
||||
msg.AddInt32("im_what", IM_STATUS_CHANGED);
|
||||
msg.AddString("protocol", kProtocolName);
|
||||
msg.AddString("id", who);
|
||||
msg.AddInt32("status", CAYA_ONLINE);
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
AIMProtocol::BuddyIdle(void* imcomm, char* who, long idletime)
|
||||
{
|
||||
BMessage msg(IM_MESSAGE);
|
||||
msg.AddInt32("im_what", IM_STATUS_CHANGED);
|
||||
msg.AddString("protocol", kProtocolName);
|
||||
msg.AddString("id", who);
|
||||
msg.AddInt32("status", CAYA_ONLINE);
|
||||
|
||||
gServerMsgr->SendMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AIMProtocol::BuddyProfile(void *handle, char *who, char *profile) {
|
||||
// XXX vcard is probably an issue
|
||||
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;
|
||||
size_t len = strlen(message);
|
||||
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, "&", 5) == 0) {
|
||||
|
@ -452,6 +430,7 @@ AIMProtocol::strip_html(const char *message)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (x + 5 < len) {
|
||||
if (strncmp(message + x, """, 6) == 0) {
|
||||
temp[count] = '\"';
|
||||
|
@ -459,6 +438,7 @@ AIMProtocol::strip_html(const char *message)
|
|||
x += 5;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strncmp(message + x, " ", 6) == 0) {
|
||||
temp[count] = ' ';
|
||||
count++;
|
||||
|
@ -466,6 +446,7 @@ AIMProtocol::strip_html(const char *message)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (x + 3 < len) {
|
||||
if (strncmp(message + x, "<", 4) == 0) {
|
||||
temp[count] = '<';
|
||||
|
@ -474,6 +455,7 @@ AIMProtocol::strip_html(const char *message)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (x + 3 < len) {
|
||||
if (strncmp(message + x, ">", 4) == 0) {
|
||||
temp[count] = '>';
|
||||
|
@ -483,6 +465,7 @@ AIMProtocol::strip_html(const char *message)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (message[x] == '\n' || message[x] == '\r')
|
||||
continue;
|
||||
else
|
||||
|
|
|
@ -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>
|
||||
|
@ -16,43 +16,43 @@
|
|||
|
||||
class AIMProtocol : public CayaProtocol {
|
||||
public:
|
||||
AIMProtocol();
|
||||
virtual ~AIMProtocol();
|
||||
AIMProtocol();
|
||||
virtual ~AIMProtocol();
|
||||
|
||||
virtual status_t Init( CayaProtocolMessengerInterface* );
|
||||
virtual status_t Shutdown();
|
||||
virtual status_t Process( BMessage * );
|
||||
virtual const char * GetSignature();
|
||||
virtual const char * GetFriendlySignature();
|
||||
virtual status_t UpdateSettings( BMessage & );
|
||||
virtual uint32 GetEncoding();
|
||||
virtual status_t Init(CayaProtocolMessengerInterface* messenger);
|
||||
|
||||
static int32 WaitForData(void *);
|
||||
virtual status_t Shutdown();
|
||||
virtual status_t Process(BMessage*);
|
||||
|
||||
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 *);
|
||||
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;
|
||||
|
||||
|
||||
protected:
|
||||
status_t A_LogOn();
|
||||
status_t LogOff();
|
||||
void UnsupportedOperation();
|
||||
static char * strip_html (const char *message);
|
||||
status_t A_LogOn();
|
||||
status_t LogOff();
|
||||
void UnsupportedOperation();
|
||||
|
||||
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
|
||||
|
|
|
@ -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"
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Ŝarĝante…
Reference in New Issue