/* * libretroshare/src/serialiser: rsbaseitems.cc * * RetroShare Serialiser. * * Copyright 2007-2008 by Robert Fernie. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License Version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Please report all bugs and problems to "retroshare@lunamutt.com". * */ #include #include #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" #include "chat/rschatitems.h" //#define CHAT_DEBUG 1 std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsChatMsgItem", indent); uint16_t int_Indent = indent + 2; printIndent(out, int_Indent); out << "QblogMs " << chatFlags << std::endl; printIndent(out, int_Indent); out << "sendTime: " << sendTime << " (" << time(NULL)-sendTime << " secs ago)" << std::endl; printIndent(out, int_Indent); std::string cnv_message(message.begin(), message.end()); out << "msg: " << cnv_message << std::endl; printRsItemEnd(out, "RsChatMsgItem", indent); return out; } std::ostream& RsChatDHPublicKeyItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsChatDHPublicKeyItem", indent); uint16_t int_Indent = indent + 2; printIndent(out, int_Indent); out << " Signature Key ID: " << signature.keyId << std::endl ; out << " Public Key ID: " << gxs_key.keyId << std::endl ; printRsItemEnd(out, "RsChatMsgItem", indent); return out; } std::ostream& RsChatLobbyListItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsChatLobbyListItem", indent); for(uint32_t i=0;iPeerId()); configPeerId = ci->PeerId(); chatFlags = ci->chatFlags; configFlags = confFlags; sendTime = ci->sendTime; message = ci->message; recvTime = ci->recvTime; } /* get data from RsPrivateChatMsgConfigItem to RsChatMsgItem */ void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci) { ci->PeerId(configPeerId); ci->chatFlags = chatFlags; //configFlags not used ci->sendTime = sendTime; ci->message = message; ci->recvTime = recvTime; } RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/) : RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) { uint32_t offset = 8; // skip the header uint32_t rssize = getRsItemSize(data); bool ok = true ; #ifdef CHAT_DEBUG std::cerr << "Building new chat status item." << std::endl ; #endif /* get mandatory parts first */ ok &= getRawUInt32(data, rssize, &offset, &flags); ok &= GetTlvString(data, rssize, &offset,TLV_TYPE_STR_MSG, status_string); if (offset != rssize) std::cerr << "Size error while deserializing." << std::endl ; if (!ok) std::cerr << "Unknown error while deserializing." << std::endl ; } RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/) : RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) { uint32_t offset = 8; // skip the header uint32_t rssize = getRsItemSize(data); bool ok = true ; #ifdef CHAT_DEBUG std::cerr << "Building new chat status item." << std::endl ; #endif /* get mandatory parts first */ ok &= getRawUInt32(data, rssize, &offset,&image_size); // ensure invalid image length does not overflow data if( (offset + image_size) <= rssize){ image_data = new unsigned char[image_size] ; memcpy(image_data,(void*)((unsigned char*)data+offset),image_size) ; offset += image_size ; }else{ ok = false; std::cerr << "offset+image_size exceeds rssize" << std::endl; } if (offset != rssize) std::cerr << "Size error while deserializing." << std::endl ; if (!ok) std::cerr << "Unknown error while deserializing." << std::endl ; }