From 8d1c0d1a9d02eb9fb3debe88905659a91ccf5275 Mon Sep 17 00:00:00 2001 From: plfiorini Date: Wed, 19 May 2010 17:11:22 +0000 Subject: [PATCH] Merging r148, r154, r155 with trunk. --- application/CayaConstants.h | 3 + application/Server.cpp | 7 ++- libs/libsupport/Base64.cpp | 118 ++++++++++++++++++++++++++++++++++++ libs/libsupport/Base64.h | 21 +++++++ libs/libsupport/Jamfile | 1 + 5 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 libs/libsupport/Base64.cpp create mode 100644 libs/libsupport/Base64.h diff --git a/application/CayaConstants.h b/application/CayaConstants.h index 0f7b414..f7ee1bb 100644 --- a/application/CayaConstants.h +++ b/application/CayaConstants.h @@ -67,6 +67,9 @@ enum im_what_code { // Received information on contact IM_CONTACT_INFO = 10, + + // Received extended information on contact + IM_EXTENDED_CONTACT_INFO = 30, // Start listening to changes in these contact's statuses IM_REGISTER_CONTACTS = 11, diff --git a/application/Server.cpp b/application/Server.cpp index 8cd09dd..6233663 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -234,9 +234,10 @@ Server::ImMessage(BMessage* msg) { ContactLinker* linker = _EnsureContactLinker(msg); - BString fullName = msg->FindString("nick"); - if (fullName != "") - linker->SetNotifyName(fullName); + const char* name = NULL; + + if (msg->FindString("name", &name) == B_OK) + linker->SetNotifyName(name); break; } case IM_AVATAR_CHANGED: diff --git a/libs/libsupport/Base64.cpp b/libs/libsupport/Base64.cpp new file mode 100644 index 0000000..fe2ad78 --- /dev/null +++ b/libs/libsupport/Base64.cpp @@ -0,0 +1,118 @@ +/* + * Copyright 2009, Pier Luigi Fiorini. + * Copyright 2004-2009, René Nyffenegge + * Distributed under the terms of the MIT License. + */ + +// Based on original code from: +// http://www.adp-gmbh.ch/cpp/common/base64.html + +#include + +#include "Base64.h" + +static const BString chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + + +Base64::Base64() +{ +} + + +BString +Base64::Encode(const uchar* data, size_t length) +{ + BString encoded; + int32 i = 0; + uchar array3[3], array4[4]; + + while (length--) { + array3[i++] = *(data++); + + if (i == 3) { + array4[0] = (uchar)((array3[0] & 0xfc) >> 2); + array4[1] = (uchar)(((array3[0] & 0x03) << 4) + ((array3[1] & 0xf0) >> 4)); + array4[2] = (uchar)(((array3[1] & 0x0f) << 2) + ((array3[2] & 0xc0) >> 6)); + array4[3] = (uchar)(((array4[2] & 0x3) << 6) + array4[3]); + + for (i = 0; i < 3; i++) + encoded += array3[i]; + i = 0; + } + } + + if (i) { + for (int32 j = i; j < 4; j++) + array4[j] = 0; + + for (int32 j = 0; j < 4; j++) + array4[j] = (uchar)chars.FindFirst(array4[j]); + + array3[0] = (uchar)((array4[0] << 2) + ((array4[i] & 0x30) >> 4)); + array3[1] = (uchar)(((array4[1] & 0xf) << 4) + ((array4[2] & 0x3c) >> 2)); + array3[2] = (uchar)(((array4[2] & 0x3) << 6) + array4[3]); + + for (int32 j = 0; j < i - 1; j++) + encoded += array3[j]; + } + + return encoded; +} + + +bool +Base64::IsBase64(uchar c) +{ + return isalnum(c) || (c == '+') || (c == '/'); +} + + +BString +Base64::Decode(const BString& data) +{ + int32 length = data.Length(); + int32 i = 0; + int32 index = 0; + uchar array4[4], array3[3]; + BString decoded; + + while (length-- && (data[index] != '=') && IsBase64(data[index])) { + array4[i++] = data[index]; + index++; + + if (i == 4) { + for (i = 0; i < 4; i++) + array4[i] = (uchar)chars.FindFirst(array4[i]); + + array3[0] = (uchar)((array4[0] << 2) + ((array4[1] & 0x30)>> 4)); + array3[1] = (uchar)(((array4[1] & 0xf) << 4) + ((array4[2] & 0x3c) >> 2)); + array3[2] = (uchar)(((array4[2] & 0x3) << 6) + array4[3]); + + for (i = 0; i < 3; i++) + decoded += array3[i]; + i = 0; + } + } + + if (i) { + int32 j; + + for (j = i; j < 4; j++) + array4[j] = 0; + + for (j = 0; j < 4; j++) + array4[j] = (uchar)chars.FindFirst(array4[j]); + + array3[0] = (uchar)((array4[0] << 2) + ((array4[1] & 0x30) >> 4)); + array3[1] = (uchar)(((array4[1] & 0xf) << 4) + ((array4[2] & 0x3c) >> 2)); + array3[2] = (uchar)(((array4[2] & 0x3) << 6) + array4[3]); + + for (j = 0; j < i - 1; j++) + decoded += array3[j]; + } + + return decoded; +} diff --git a/libs/libsupport/Base64.h b/libs/libsupport/Base64.h new file mode 100644 index 0000000..3188a05 --- /dev/null +++ b/libs/libsupport/Base64.h @@ -0,0 +1,21 @@ +/* + * Copyright 2009, Pier Luigi Fiorini. + * Copyright 2004-2009, René Nyffenegge + * Distributed under the terms of the MIT License. + */ +#ifndef _BASE_64_H +#define _BASE_64_H + +#include + +class Base64 { +public: + static bool IsBase64(uchar c); + static BString Encode(const uchar* data, size_t length); + static BString Decode(const BString& data); + +private: + Base64(); +}; + +#endif // _BASE_64_H diff --git a/libs/libsupport/Jamfile b/libs/libsupport/Jamfile index 2a9daf0..a550040 100644 --- a/libs/libsupport/Jamfile +++ b/libs/libsupport/Jamfile @@ -3,5 +3,6 @@ SubDir TOP libs libsupport ; SubDirSysHdrs [ FDirName $(TOP) libs ] ; StaticLibrary libsupport.a : + Base64.cpp Singleton.cpp ;