summaryrefslogtreecommitdiff
path: root/protocols/AimOscar/src/packets.cpp
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-10-12 11:45:28 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-10-12 11:45:28 +0000
commit08fd5437555d0b5cab972fb3316b4cdb8f11cdae (patch)
treec18c5bfd833781b935871f6ffa7d4c14769f52ec /protocols/AimOscar/src/packets.cpp
parent8473fb7c85680042038cc0ad40d4e22bb6a639e7 (diff)
AimOscar: folders restructurization
git-svn-id: http://svn.miranda-ng.org/main/trunk@1886 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/AimOscar/src/packets.cpp')
-rw-r--r--protocols/AimOscar/src/packets.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/protocols/AimOscar/src/packets.cpp b/protocols/AimOscar/src/packets.cpp
new file mode 100644
index 0000000000..91065138fa
--- /dev/null
+++ b/protocols/AimOscar/src/packets.cpp
@@ -0,0 +1,123 @@
+/*
+Plugin of Miranda IM for communicating with users of the AIM protocol.
+Copyright (c) 2008-2009 Boris Krasnovskiy
+Copyright (C) 2005-2006 Aaron Myles Landwehr
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "aim.h"
+#include "packets.h"
+
+int aim_writesnac(unsigned short service, unsigned short subgroup,unsigned short &offset, char* out, unsigned short id)
+{
+ snac_header *snac = (snac_header*)&out[offset];
+ snac->service=_htons(service);
+ snac->subgroup=_htons(subgroup);
+ snac->flags=0;
+ snac->request_id[0]=_htons(id);
+ snac->request_id[1]=_htons(subgroup);
+ offset+=sizeof(snac_header);
+ return 0;
+}
+
+int aim_writetlv(unsigned short type,unsigned short length, const char* value,unsigned short &offset,char* out)
+{
+ TLV tlv(type,length,value);
+ offset += tlv.whole(&out[offset]);
+ return 0;
+}
+
+int aim_writetlvchar(unsigned short type, unsigned char value, unsigned short &offset, char* out)
+{
+ return aim_writetlv(type, sizeof(value), (char*)&value, offset, out);
+}
+
+
+int aim_writetlvshort(unsigned short type, unsigned short value, unsigned short &offset, char* out)
+{
+ value = _htons(value);
+ return aim_writetlv(type, sizeof(value), (char*)&value, offset, out);
+}
+
+
+int aim_writetlvlong(unsigned short type, unsigned long value, unsigned short &offset, char* out)
+{
+ value = _htonl(value);
+ return aim_writetlv(type, sizeof(value), (char*)&value, offset, out);
+}
+
+int aim_writetlvlong64(unsigned short type, unsigned __int64 value, unsigned short &offset, char* out)
+{
+ value = _htonl64(value);
+ return aim_writetlv(type, sizeof(value), (char*)&value, offset, out);
+}
+
+
+int CAimProto::aim_sendflap(HANDLE hServerConn, char type,unsigned short length,const char *buf, unsigned short &seqno)
+{
+ EnterCriticalSection(&SendingMutex);
+ const int slen = FLAP_SIZE + length;
+ char* obuf = (char*)alloca(slen);
+ flap_header *flap = (flap_header*)obuf;
+ flap->ast = '*';
+ flap->type = type;
+ flap->seqno = _htons(seqno++);
+ flap->len = _htons(length);
+ memcpy(&obuf[FLAP_SIZE], buf, length);
+ int rlen= Netlib_Send(hServerConn, obuf, slen, 0);
+ if (rlen == SOCKET_ERROR) seqno--;
+ LeaveCriticalSection(&SendingMutex);
+ return rlen >= 0 ? 0 : -1;
+}
+
+void aim_writefamily(const char *buf,unsigned short &offset,char* out)
+{
+ memcpy(&out[offset],buf,4);
+ offset+=4;
+}
+
+void aim_writechar(unsigned char val, unsigned short &offset,char* out)
+{
+ out[offset++] = val;
+}
+
+void aim_writeshort(unsigned short val, unsigned short &offset,char* out)
+{
+ out[offset++] = (char)(val >> 8);
+ out[offset++] = (char)(val & 0xFF);
+}
+
+void aim_writelong(unsigned long val, unsigned short &offset,char* out)
+{
+ out[offset++] = (char)(val >> 24);
+ out[offset++] = (char)((val >> 16) & 0xFF);
+ out[offset++] = (char)((val >> 8) & 0xFF);
+ out[offset++] = (char)(val & 0xFF);
+}
+
+void aim_writegeneric(unsigned short size,const char *buf,unsigned short &offset,char* out)
+{
+ memcpy(&out[offset],buf,size);
+ offset+=size;
+}
+
+void aim_writebartid(unsigned short type, unsigned char flags, unsigned short size,const char *buf,unsigned short &offset,char* out)
+{
+ out[offset++]=(unsigned char)(type >> 8);
+ out[offset++]=(unsigned char)(type & 0xff);
+ out[offset++]=flags;
+ out[offset++]=(char)size;
+ memcpy(&out[offset],buf,size);
+ offset+=size;
+}