~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to cutestuff/network/httpconnect.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 */
20
20
 
21
 
#include"httpconnect.h"
 
21
#include "httpconnect.h"
22
22
 
23
 
#include<qstringlist.h>
24
 
#include"bsocket.h"
25
 
#include"base64.h"
 
23
#include <qstringlist.h>
 
24
//Added by qt3to4:
 
25
#include <Q3CString>
 
26
#include "bsocket.h"
 
27
#include <QtCrypto>
26
28
 
27
29
#ifdef PROX_DEBUG
28
 
#include<stdio.h>
 
30
#include <stdio.h>
29
31
#endif
30
32
 
31
33
// CS_NAMESPACE_BEGIN
32
34
 
33
35
static QString extractLine(QByteArray *buf, bool *found)
34
36
{
35
 
        // scan for newline
36
 
        int n;
37
 
        for(n = 0; n < (int)buf->size()-1; ++n) {
38
 
                if(buf->at(n) == '\r' && buf->at(n+1) == '\n') {
39
 
                        QCString cstr;
40
 
                        cstr.resize(n+1);
41
 
                        memcpy(cstr.data(), buf->data(), n);
42
 
                        n += 2; // hack off CR/LF
43
 
 
44
 
                        memmove(buf->data(), buf->data() + n, buf->size() - n);
45
 
                        buf->resize(buf->size() - n);
46
 
                        QString s = QString::fromUtf8(cstr);
47
 
 
48
 
                        if(found)
49
 
                                *found = true;
50
 
                        return s;
51
 
                }
52
 
        }
53
 
 
54
 
        if(found)
55
 
                *found = false;
56
 
        return "";
 
37
        // Scan for newline
 
38
        int index = buf->indexOf ("\r\n");
 
39
        if (index == -1) {
 
40
                // Newline not found
 
41
                if (found)
 
42
                        *found = false;
 
43
                return "";
 
44
        }
 
45
        else {
 
46
                // Found newline
 
47
                QString s = QString::fromAscii(buf->left(index));
 
48
                buf->remove(0, index + 2);
 
49
 
 
50
                if (found)
 
51
                        *found = true;
 
52
                return s;
 
53
        }
57
54
}
58
55
 
59
56
static bool extractMainHeader(const QString &line, QString *proto, int *code, QString *msg)
201
198
        s += QString("CONNECT ") + d->real_host + ':' + QString::number(d->real_port) + " HTTP/1.0\r\n";
202
199
        if(!d->user.isEmpty()) {
203
200
                QString str = d->user + ':' + d->pass;
204
 
                s += QString("Proxy-Authorization: Basic ") + Base64::encodeString(str) + "\r\n";
 
201
                s += QString("Proxy-Authorization: Basic ") + QCA::Base64().encodeString(str) + "\r\n";
205
202
        }
206
203
        s += "Pragma: no-cache\r\n";
207
204
        s += "\r\n";
208
205
 
209
 
        QCString cs = s.utf8();
 
206
        Q3CString cs = s.utf8();
210
207
        QByteArray block(cs.length());
211
208
        memcpy(block.data(), cs.data(), block.size());
212
209
        d->toWrite = block.size();