summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_ft.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-08-17 19:38:42 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-08-17 19:38:42 +0000
commitd0ceb5768ff3146499a0318ffe03c867c0845592 (patch)
tree984da5102d6a820e670323c47edd8187a37a0b33 /protocols/JabberG/src/jabber_ft.cpp
parent98ac258dc34b281e8441de847e37408c36c7415d (diff)
- numerous name conflicts resolved;
- funny code that loads resource #102 from miranda32.exe removed; - massive mir_sntprintf code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@14979 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/JabberG/src/jabber_ft.cpp')
-rw-r--r--protocols/JabberG/src/jabber_ft.cpp140
1 files changed, 79 insertions, 61 deletions
diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp
index 41955dc4e5..56ae8f742b 100644
--- a/protocols/JabberG/src/jabber_ft.cpp
+++ b/protocols/JabberG/src/jabber_ft.cpp
@@ -82,7 +82,7 @@ void CJabberProto::FtInitiate(TCHAR* jid, filetransfer *ft)
int i;
TCHAR sid[9];
- if (jid == NULL || ft == NULL || !m_bJabberOnline || (rs=ListGetBestClientResourceNamePtr(jid)) == NULL) {
+ if (jid == NULL || ft == NULL || !m_bJabberOnline || (rs = ListGetBestClientResourceNamePtr(jid)) == NULL) {
if (ft) {
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
delete ft;
@@ -90,27 +90,27 @@ void CJabberProto::FtInitiate(TCHAR* jid, filetransfer *ft)
return;
}
ft->type = FT_SI;
- for (i=0; i<8; i++)
- sid[i] = (rand()%10) + '0';
+ for (i = 0; i < 8; i++)
+ sid[i] = (rand() % 10) + '0';
sid[8] = '\0';
if (ft->sid != NULL) mir_free(ft->sid);
ft->sid = mir_tstrdup(sid);
filename = ft->std.ptszFiles[ft->std.currentFileNumber];
if ((p = _tcsrchr(filename, '\\')) != NULL)
- filename = p+1;
+ filename = p + 1;
- TCHAR tszJid[ 512 ];
- mir_sntprintf(tszJid, _countof(tszJid), _T("%s/%s"), jid, rs);
+ TCHAR tszJid[512];
+ mir_sntprintf(tszJid, _T("%s/%s"), jid, rs);
- XmlNodeIq iq( AddIQ(&CJabberProto::OnFtSiResult, JABBER_IQ_TYPE_SET, tszJid, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_TO, -1, ft));
+ XmlNodeIq iq(AddIQ(&CJabberProto::OnFtSiResult, JABBER_IQ_TYPE_SET, tszJid, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_TO, -1, ft));
HXML si = iq << XCHILDNS(_T("si"), JABBER_FEAT_SI) << XATTR(_T("id"), sid)
- << XATTR(_T("mime-type"), _T("binary/octet-stream")) << XATTR(_T("profile"), JABBER_FEAT_SI_FT);
+ << XATTR(_T("mime-type"), _T("binary/octet-stream")) << XATTR(_T("profile"), JABBER_FEAT_SI_FT);
si << XCHILDNS(_T("file"), JABBER_FEAT_SI_FT) << XATTR(_T("name"), filename)
<< XATTRI64(_T("size"), ft->fileSize[ft->std.currentFileNumber]) << XCHILD(_T("desc"), ft->szDescription);
HXML field = si << XCHILDNS(_T("feature"), JABBER_FEAT_FEATURE_NEG)
- << XCHILDNS(_T("x"), JABBER_FEAT_DATA_FORMS) << XATTR(_T("type"), _T("form"))
- << XCHILD(_T("field")) << XATTR(_T("var"), _T("stream-method")) << XATTR(_T("type"), _T("list-single"));
+ << XCHILDNS(_T("x"), JABBER_FEAT_DATA_FORMS) << XATTR(_T("type"), _T("form"))
+ << XCHILD(_T("field")) << XATTR(_T("var"), _T("stream-method")) << XATTR(_T("type"), _T("list-single"));
BOOL bDirect = m_options.BsDirect;
BOOL bProxy = m_options.BsProxyManual;
@@ -130,16 +130,16 @@ void CJabberProto::OnFtSiResult(HXML iqNode, CJabberIqInfo *pInfo)
if (!ft) return;
if ((pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) && pInfo->m_szFrom && pInfo->m_szTo) {
- if ((siNode = XmlGetChild(iqNode , "si")) != NULL) {
+ if ((siNode = XmlGetChild(iqNode, "si")) != NULL) {
// fix for very smart clients, like gajim
BOOL bDirect = m_options.BsDirect;
BOOL bProxy = m_options.BsProxyManual;
- if ((featureNode = XmlGetChild(siNode , "feature")) != NULL) {
+ if ((featureNode = XmlGetChild(siNode, "feature")) != NULL) {
if ((xNode = XmlGetChildByTag(featureNode, "x", "xmlns", JABBER_FEAT_DATA_FORMS)) != NULL) {
if ((fieldNode = XmlGetChildByTag(xNode, "field", "var", _T("stream-method"))) != NULL) {
- if ((valueNode = XmlGetChild(fieldNode , "value")) != NULL && XmlGetText(valueNode) != NULL) {
+ if ((valueNode = XmlGetChild(fieldNode, "value")) != NULL && XmlGetText(valueNode) != NULL) {
if ((bDirect || bProxy) && !mir_tstrcmp(XmlGetText(valueNode), JABBER_FEAT_BYTESTREAMS)) {
// Start Bytestream session
JABBER_BYTE_TRANSFER *jbt = new JABBER_BYTE_TRANSFER;
@@ -155,7 +155,7 @@ void CJabberProto::OnFtSiResult(HXML iqNode, CJabberIqInfo *pInfo)
ForkThread((MyThreadFunc)&CJabberProto::ByteSendThread, jbt);
}
else if (!mir_tstrcmp(XmlGetText(valueNode), JABBER_FEAT_IBB)) {
- JABBER_IBB_TRANSFER *jibb = (JABBER_IBB_TRANSFER *) mir_alloc(sizeof (JABBER_IBB_TRANSFER));
+ JABBER_IBB_TRANSFER *jibb = (JABBER_IBB_TRANSFER *)mir_alloc(sizeof(JABBER_IBB_TRANSFER));
memset(jibb, 0, sizeof(JABBER_IBB_TRANSFER));
jibb->srcJID = mir_tstrdup(pInfo->m_szTo);
jibb->dstJID = mir_tstrdup(pInfo->m_szFrom);
@@ -166,7 +166,13 @@ void CJabberProto::OnFtSiResult(HXML iqNode, CJabberIqInfo *pInfo)
ft->type = FT_IBB;
ft->jibb = jibb;
ForkThread((MyThreadFunc)&CJabberProto::IbbSendThread, jibb);
- } } } } } } }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
else {
debugLogA("File transfer stream initiation request denied or failed");
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, pInfo->GetIqType() == JABBER_IQ_TYPE_ERROR ? ACKRESULT_DENIED : ACKRESULT_FAILED, ft, 0);
@@ -183,7 +189,7 @@ BOOL CJabberProto::FtSend(HANDLE hConn, filetransfer *ft)
debugLog(_T("Sending [%s]"), ft->std.ptszFiles[ft->std.currentFileNumber]);
_tstati64(ft->std.ptszFiles[ft->std.currentFileNumber], &statbuf); // file size in statbuf.st_size
- if ((fd = _topen(ft->std.ptszFiles[ft->std.currentFileNumber], _O_BINARY|_O_RDONLY)) < 0) {
+ if ((fd = _topen(ft->std.ptszFiles[ft->std.currentFileNumber], _O_BINARY | _O_RDONLY)) < 0) {
debugLog(_T("File cannot be opened"));
return FALSE;
}
@@ -192,8 +198,8 @@ BOOL CJabberProto::FtSend(HANDLE hConn, filetransfer *ft)
ft->std.currentFileSize = statbuf.st_size;
ft->std.currentFileProgress = 0;
- if ((buffer=(char*)mir_alloc(2048)) != NULL) {
- while ((numRead=_read(fd, buffer, 2048)) > 0) {
+ if ((buffer = (char*)mir_alloc(2048)) != NULL) {
+ while ((numRead = _read(fd, buffer, 2048)) > 0) {
if (Netlib_Send(hConn, buffer, numRead, 0) != numRead) {
mir_free(buffer);
_close(fd);
@@ -215,8 +221,8 @@ BOOL CJabberProto::FtIbbSend(int blocksize, filetransfer *ft)
struct _stati64 statbuf;
_tstati64(ft->std.ptszFiles[ft->std.currentFileNumber], &statbuf); // file size in statbuf.st_size
-
- int fd = _topen(ft->std.ptszFiles[ft->std.currentFileNumber], _O_BINARY|_O_RDONLY);
+
+ int fd = _topen(ft->std.ptszFiles[ft->std.currentFileNumber], _O_BINARY | _O_RDONLY);
if (fd < 0) {
debugLogA("File cannot be opened");
return FALSE;
@@ -276,7 +282,7 @@ void CJabberProto::FtSendFinal(BOOL success, filetransfer *ft)
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ft->state == FT_DENIED ? ACKRESULT_DENIED : ACKRESULT_FAILED, ft, 0);
}
else {
- if (ft->std.currentFileNumber < ft->std.totalFiles-1) {
+ if (ft->std.currentFileNumber < ft->std.totalFiles - 1) {
ft->std.currentFileNumber++;
replaceStrT(ft->std.tszCurrentFile, ft->std.ptszFiles[ft->std.currentFileNumber]);
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0);
@@ -297,19 +303,19 @@ void CJabberProto::FtHandleSiRequest(HXML iqNode)
const TCHAR *from, *sid, *str, *szId, *filename;
HXML siNode, fileNode, featureNode, xNode, fieldNode, n;
int i;
- unsigned __int64 filesize;
+ unsigned __int64 filesize;
if (!iqNode ||
- (from = XmlGetAttrValue(iqNode, _T("from"))) == NULL ||
- (str = XmlGetAttrValue(iqNode, _T("type"))) == NULL || mir_tstrcmp(str, _T("set")) ||
- (siNode = XmlGetChildByTag(iqNode, "si", "xmlns", JABBER_FEAT_SI)) == NULL)
+ (from = XmlGetAttrValue(iqNode, _T("from"))) == NULL ||
+ (str = XmlGetAttrValue(iqNode, _T("type"))) == NULL || mir_tstrcmp(str, _T("set")) ||
+ (siNode = XmlGetChildByTag(iqNode, "si", "xmlns", JABBER_FEAT_SI)) == NULL)
return;
- szId = XmlGetAttrValue(iqNode, _T("id"));
- if ((sid = XmlGetAttrValue(siNode, _T("id"))) != NULL &&
+ szId = XmlGetAttrValue(iqNode, _T("id"));
+ if ((sid = XmlGetAttrValue(siNode, _T("id"))) != NULL &&
(fileNode = XmlGetChildByTag(siNode, "file", "xmlns", JABBER_FEAT_SI_FT)) != NULL &&
- (filename = XmlGetAttrValue(fileNode, _T("name"))) != NULL &&
- (str = XmlGetAttrValue(fileNode, _T("size"))) != NULL) {
+ (filename = XmlGetAttrValue(fileNode, _T("name"))) != NULL &&
+ (str = XmlGetAttrValue(fileNode, _T("size"))) != NULL) {
filesize = _ttoi64(str);
if ((featureNode = XmlGetChildByTag(siNode, "feature", "xmlns", JABBER_FEAT_FEATURE_NEG)) != NULL &&
@@ -321,31 +327,39 @@ void CJabberProto::FtHandleSiRequest(HXML iqNode)
JABBER_FT_TYPE ftType = FT_OOB;
if (!bIbbOnly) {
- for (i=0; ; i++) {
- optionNode = XmlGetChild(fieldNode ,i);
+ for (i = 0; ; i++) {
+ optionNode = XmlGetChild(fieldNode, i);
if (!optionNode)
break;
if (!mir_tstrcmp(XmlGetName(optionNode), _T("option"))) {
- if ((n = XmlGetChild(optionNode , "value")) != NULL && XmlGetText(n)) {
+ if ((n = XmlGetChild(optionNode, "value")) != NULL && XmlGetText(n)) {
if (!mir_tstrcmp(XmlGetText(n), JABBER_FEAT_BYTESTREAMS)) {
ftType = FT_BYTESTREAM;
break;
- } } } } }
+ }
+ }
+ }
+ }
+ }
// try IBB only if bytestreams support not found or BsOnlyIBB flag exists
if (bIbbOnly || !optionNode) {
- for (i=0; ; i++) {
- optionNode = XmlGetChild(fieldNode ,i);
+ for (i = 0; ; i++) {
+ optionNode = XmlGetChild(fieldNode, i);
if (!optionNode)
break;
if (!mir_tstrcmp(XmlGetName(optionNode), _T("option"))) {
- if ((n = XmlGetChild(optionNode , "value")) != NULL && XmlGetText(n)) {
+ if ((n = XmlGetChild(optionNode, "value")) != NULL && XmlGetText(n)) {
if (!mir_tstrcmp(XmlGetText(n), JABBER_FEAT_IBB)) {
ftType = FT_IBB;
break;
- } } } } }
+ }
+ }
+ }
+ }
+ }
if (optionNode != NULL) {
// Found known stream mechanism
@@ -366,7 +380,7 @@ void CJabberProto::FtHandleSiRequest(HXML iqNode)
pre.timestamp = time(NULL);
pre.files.t = (TCHAR**)&filename;
pre.lParam = (LPARAM)ft;
- if ((n = XmlGetChild(fileNode , "desc")) != NULL)
+ if ((n = XmlGetChild(fileNode, "desc")) != NULL)
pre.descr.t = (TCHAR*)XmlGetText(n);
ProtoChainRecvFile(ft->std.hContact, &pre);
@@ -380,7 +394,9 @@ void CJabberProto::FtHandleSiRequest(HXML iqNode)
e << XCHILDNS(_T("no-valid-streams"), JABBER_FEAT_SI);
m_ThreadInfo->send(iq);
return;
- } } }
+ }
+ }
+ }
// Bad stream initiation, reply with bad-profile
XmlNodeIq iq(_T("error"), szId, from);
@@ -395,34 +411,36 @@ void CJabberProto::FtAcceptSiRequest(filetransfer *ft)
if (!m_bJabberOnline || ft == NULL || ft->jid == NULL || ft->sid == NULL) return;
JABBER_LIST_ITEM *item;
- if ((item=ListAdd(LIST_FTRECV, ft->sid)) != NULL) {
+ if ((item = ListAdd(LIST_FTRECV, ft->sid)) != NULL) {
item->ft = ft;
m_ThreadInfo->send(
XmlNodeIq(_T("result"), ft->szId, ft->jid)
- << XCHILDNS(_T("si"), JABBER_FEAT_SI)
- << XCHILDNS(_T("feature"), JABBER_FEAT_FEATURE_NEG)
- << XCHILDNS(_T("x"), JABBER_FEAT_DATA_FORMS) << XATTR(_T("type"), _T("submit"))
- << XCHILD(_T("field")) << XATTR(_T("var"), _T("stream-method"))
- << XCHILD(_T("value"), JABBER_FEAT_BYTESTREAMS));
-} }
+ << XCHILDNS(_T("si"), JABBER_FEAT_SI)
+ << XCHILDNS(_T("feature"), JABBER_FEAT_FEATURE_NEG)
+ << XCHILDNS(_T("x"), JABBER_FEAT_DATA_FORMS) << XATTR(_T("type"), _T("submit"))
+ << XCHILD(_T("field")) << XATTR(_T("var"), _T("stream-method"))
+ << XCHILD(_T("value"), JABBER_FEAT_BYTESTREAMS));
+ }
+}
void CJabberProto::FtAcceptIbbRequest(filetransfer *ft)
{
if (!m_bJabberOnline || ft == NULL || ft->jid == NULL || ft->sid == NULL) return;
JABBER_LIST_ITEM *item;
- if ((item=ListAdd(LIST_FTRECV, ft->sid)) != NULL) {
+ if ((item = ListAdd(LIST_FTRECV, ft->sid)) != NULL) {
item->ft = ft;
m_ThreadInfo->send(
XmlNodeIq(_T("result"), ft->szId, ft->jid)
- << XCHILDNS(_T("si"), JABBER_FEAT_SI)
- << XCHILDNS(_T("feature"), JABBER_FEAT_FEATURE_NEG)
- << XCHILDNS(_T("x"), JABBER_FEAT_DATA_FORMS) << XATTR(_T("type"), _T("submit"))
- << XCHILD(_T("field")) << XATTR(_T("var"), _T("stream-method"))
- << XCHILD(_T("value"), JABBER_FEAT_IBB));
-} }
+ << XCHILDNS(_T("si"), JABBER_FEAT_SI)
+ << XCHILDNS(_T("feature"), JABBER_FEAT_FEATURE_NEG)
+ << XCHILDNS(_T("x"), JABBER_FEAT_DATA_FORMS) << XATTR(_T("type"), _T("submit"))
+ << XCHILD(_T("field")) << XATTR(_T("var"), _T("stream-method"))
+ << XCHILD(_T("value"), JABBER_FEAT_IBB));
+ }
+}
BOOL CJabberProto::FtHandleBytestreamRequest(HXML iqNode, CJabberIqInfo *pInfo)
{
@@ -469,15 +487,15 @@ BOOL CJabberProto::FtHandleIbbRequest(HXML iqNode, BOOL bOpen)
if (item == NULL) {
m_ThreadInfo->send(
XmlNodeIq(_T("error"), id, from)
- << XCHILD(_T("error")) << XATTRI(_T("code"), 404) << XATTR(_T("type"), _T("cancel"))
- << XCHILDNS(_T("item-not-found"), _T("urn:ietf:params:xml:ns:xmpp-stanzas")));
+ << XCHILD(_T("error")) << XATTRI(_T("code"), 404) << XATTR(_T("type"), _T("cancel"))
+ << XCHILDNS(_T("item-not-found"), _T("urn:ietf:params:xml:ns:xmpp-stanzas")));
return FALSE;
}
// open event
if (bOpen) {
if (!item->jibb) {
- JABBER_IBB_TRANSFER *jibb = (JABBER_IBB_TRANSFER *) mir_alloc(sizeof(JABBER_IBB_TRANSFER));
+ JABBER_IBB_TRANSFER *jibb = (JABBER_IBB_TRANSFER *)mir_alloc(sizeof(JABBER_IBB_TRANSFER));
memset(jibb, 0, sizeof(JABBER_IBB_TRANSFER));
jibb->srcJID = mir_tstrdup(from);
jibb->dstJID = mir_tstrdup(to);
@@ -489,14 +507,14 @@ BOOL CJabberProto::FtHandleIbbRequest(HXML iqNode, BOOL bOpen)
item->jibb = jibb;
ForkThread((MyThreadFunc)&CJabberProto::IbbReceiveThread, jibb);
- m_ThreadInfo->send( XmlNodeIq(_T("result"), id, from));
+ m_ThreadInfo->send(XmlNodeIq(_T("result"), id, from));
return TRUE;
}
// stream already open
m_ThreadInfo->send(
XmlNodeIq(_T("error"), id, from)
- << XCHILD(_T("error")) << XATTRI(_T("code"), 404) << XATTR(_T("type"), _T("cancel"))
- << XCHILDNS(_T("item-not-found"), _T("urn:ietf:params:xml:ns:xmpp-stanzas")));
+ << XCHILD(_T("error")) << XATTRI(_T("code"), 404) << XATTR(_T("type"), _T("cancel"))
+ << XCHILDNS(_T("item-not-found"), _T("urn:ietf:params:xml:ns:xmpp-stanzas")));
return FALSE;
}
@@ -505,7 +523,7 @@ BOOL CJabberProto::FtHandleIbbRequest(HXML iqNode, BOOL bOpen)
item->jibb->bStreamClosed = TRUE;
SetEvent(item->jibb->hEvent);
- m_ThreadInfo->send( XmlNodeIq(_T("result"), id, from));
+ m_ThreadInfo->send(XmlNodeIq(_T("result"), id, from));
return TRUE;
}
@@ -521,7 +539,7 @@ int CJabberProto::FtReceive(HANDLE, filetransfer *ft, char* buffer, int datalen)
__int64 remainingBytes = ft->std.currentFileSize - ft->std.currentFileProgress;
if (remainingBytes > 0) {
- int writeSize = (remainingBytes<datalen) ? remainingBytes : datalen;
+ int writeSize = (remainingBytes < datalen) ? remainingBytes : datalen;
if (_write(ft->fileId, buffer, writeSize) != writeSize) {
debugLogA("_write() error");
return -1;