summaryrefslogtreecommitdiffstats
path: root/fastlib/src/vespa/fastlib/net/url.cpp
blob: 4d3f82c077051ddfaeba724beae4d8bc034e11ad (plain) (blame)
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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 *
 * @file url.cpp
 * @author Michael Sus�g
 * @date Creation date: 1999-11-23
 * @version $Id$
 *
 * This file contains different URL string functions
 *
 * Copyright (c)        : 1997-2000 Fast Search & Transfer ASA.
 *                        ALL RIGHTS RESERVED
 *
 */

/**
 * Encode and decode a URL
 */

#include <vespa/fastos/fastos.h>
#include "url.h"

void
Fast_URL::decode(const char *encodedURL, char *decodedURL, int bufsize)
{
    const char *tmpPtr;
    unsigned int charVal;
    char *bufend = decodedURL + bufsize;

    tmpPtr = encodedURL;

    /* Parse the whole encodedURL */
    while(decodedURL < bufend && *tmpPtr != '\0') {
        /* Check if an encoded character is the next one */
        if(*tmpPtr == '%') {
            tmpPtr++; /* Skip % character */
            sscanf(tmpPtr,"%02X", &charVal);
            *decodedURL = static_cast<char>(charVal);
            tmpPtr += 2;
        }
        else
        {
            *decodedURL = *tmpPtr;
            tmpPtr++;
        }
        decodedURL++;
    }
    if (decodedURL < bufend)
        *decodedURL = '\0';
}

int Fast_URL::DecodeQueryString(char *queryString)
{
    int numReplaced = 0;

    for(int i=0; queryString[i] != '\0'; i++)
    {
        if (queryString[i] == '+')
        {
            queryString[i] = ' ';
            numReplaced ++;
        }
    }

    return numReplaced;
}