~ubuntu-branches/ubuntu/saucy/apt-cacher-ng/saucy

« back to all changes in this revision

Viewing changes to source/header.cc

  • Committer: Package Import Robot
  • Author(s): Eduard Bloch
  • Date: 2011-09-30 16:37:18 UTC
  • mfrom: (24.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20110930163718-r0agyg6jptvobt5w
* New upstream versions
  + implements extra keeping of obsolete package versions (closes: #634145)
  + configurable outgoing connection protocol (closes: #641257)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <unistd.h>
16
16
 
17
17
#include "fileio.h"
 
18
#include "filereader.h"
18
19
 
19
20
using namespace MYSTD;
20
21
 
40
41
    { header::CONTENT_TYPE, "Content-Type" }
41
42
};
42
43
 
43
 
/*
44
 
static const char *szHeadNames[] = {
45
 
        "Connection",            // 0
46
 
        "Content-Length",  
47
 
        "If-Modified-Since",
48
 
        "Range",
49
 
        "If-Range", // 4
50
 
        "Content-Range",
51
 
        "Last-Modified",
52
 
        "Proxy-Connection",
53
 
        "Transfer-Encoding", // 8
54
 
        "X-Original-Source",
55
 
        "Authorization",
56
 
        "X-Forwarded-For",
57
 
        "X-42-Unreachable"
58
 
};
59
 
*/
60
 
 
61
44
header::header()
62
45
:
63
46
        type(INVALID),
214
197
int header::LoadFromFile(const string &sPath)
215
198
{
216
199
        clear();
 
200
#if 0
 
201
        filereader buf;
 
202
        return buf.OpenFile(sPath, true) && LoadFromBuf(buf.GetBuffer(), buf.GetSize());
 
203
#endif
217
204
        acbuf buf;
218
205
        if(!buf.initFromFile(sPath.c_str()))
219
206
                return -1;
220
207
        return LoadFromBuf(buf.rptr(), buf.size());
 
208
//#endif
221
209
}
222
210
 
 
211
 
223
212
void header::set(eHeadPos i, const char *val)
224
213
{
225
214
        if (h[i])
256
245
 
257
246
void header::set(eHeadPos key, off_t nValue)
258
247
{       
259
 
        char buf[21];
 
248
        char buf[3*sizeof(off_t)];
260
249
        sprintf(buf, OFF_T_FMT, nValue);
261
250
    set(key, buf);
262
251
}
263
252
 
264
253
#ifndef MINIBUILD
265
254
 
266
 
string header::ToString()
 
255
mstring header::ToString() const
267
256
{
268
257
 
269
258
        string hstr = frontLine + "\r\n";
289
278
        return hstr;
290
279
}
291
280
 
292
 
int header::StoreToFile(const string &sPath) 
 
281
int header::StoreToFile(const string &sPath) const
293
282
{
294
283
        int nByteCount(0);
295
284
        
296
285
        int fd=open(sPath.c_str(), O_WRONLY|O_CREAT|O_TRUNC, acfg::fileperms);
297
286
        if(fd<0)
298
 
                return -errno;
 
287
        {
 
288
                fd=-errno;
 
289
                // maybe there is something in the way which can be removed?
 
290
                if(::unlink(sPath.c_str()))
 
291
                        return fd;
 
292
 
 
293
                fd=open(sPath.c_str(), O_WRONLY|O_CREAT|O_TRUNC, acfg::fileperms);
 
294
                if(fd<0)
 
295
                        return -errno;
 
296
        }
299
297
        
300
298
        string hstr=ToString();
301
299
        const char *p=hstr.c_str();