-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathm_upload.cpp
More file actions
120 lines (96 loc) · 2.95 KB
/
Copy pathm_upload.cpp
File metadata and controls
120 lines (96 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
WASTE - m_upload.cpp (Upload request message builder/parser class)
Copyright (C) 2003 Nullsoft, Inc.
WASTE 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.
WASTE 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 WASTE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "platform.h"
#include "m_upload.h"
C_UploadRequest::~C_UploadRequest()
{
::free(m_fn);
}
C_UploadRequest::C_UploadRequest()
{
m_fn=0;
m_idx=-1;
memset(&m_guid,0,sizeof(m_guid));
m_dest[0]=0;
m_size_low=m_size_high=-1;
memset(m_nick,0,32);
}
C_UploadRequest::C_UploadRequest(C_SHBuf *in)
{
m_fn=0;
m_idx=-1;
memset(&m_guid,0,sizeof(m_guid));
m_dest[0]=0;
memset(m_nick,0,31);
unsigned char *data=(unsigned char *)in->Get();
int datalen=in->GetLength();
if (datalen < 16+8+32+4+31 + 1 || datalen > 16+8+32+4+31 + 2048)
{
debug_printf("uploadrequest: length out of range (%d)\n",datalen);
return;
}
memcpy(&m_guid,data,16); data+=16; datalen-=16;
m_size_low = data[0]|(data[1]<<8)|(data[2]<<16)|(data[3]<<24);
data+=4;
datalen-=4;
m_size_high = data[0]|(data[1]<<8)|(data[2]<<16)|(data[3]<<24);
data+=4;
datalen-=4;
memcpy(m_dest,data,32);
m_dest[32]=0;
data+=32;
datalen-=32;
m_idx = data[0]|(data[1]<<8)|(data[2]<<16)|(data[3]<<24);
data+=4;
datalen-=4;
memcpy(m_nick,data,31);
data+=31;
datalen-=31;
m_fn=(char*)::malloc(datalen+1);
::memcpy(m_fn,data,datalen);
m_fn[datalen]=0;
}
C_SHBuf *C_UploadRequest::Make(void)
{
if (!m_fn || !m_fn[0] || strlen(m_fn) > 2048)
{
debug_printf("uploadrequest::make(): filename length %d out of range\n",m_fn?strlen(m_fn):0);
return new C_SHBuf(0);
}
C_SHBuf *p=new C_SHBuf(16+8+32+4+31+::strlen(m_fn));
unsigned char *data=(unsigned char *)p->Get();
memcpy(data,&m_guid,16); data+=16;
data[0]=m_size_low&0xff;
data[1]=(m_size_low>>8)&0xff;
data[2]=(m_size_low>>16)&0xff;
data[3]=(m_size_low>>24)&0xff;
data+=4;
data[0]=m_size_high&0xff;
data[1]=(m_size_high>>8)&0xff;
data[2]=(m_size_high>>16)&0xff;
data[3]=(m_size_high>>24)&0xff;
data+=4;
memcpy(data,m_dest,32);
data+=32;
data[0]=m_idx&0xff;
data[1]=(m_idx>>8)&0xff;
data[2]=(m_idx>>16)&0xff;
data[3]=(m_idx>>24)&0xff;
data+=4;
memcpy(data,m_nick,31); data+=31;
::memcpy(data,m_fn,strlen(m_fn));
return p;
}