summaryrefslogtreecommitdiffstats
path: root/tinyHTTP/include/tinyhttp/thttp_url.h
blob: 8f93fc26abd58db53a4247e286ded9a8791e43a3 (plain)
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
/*
* Copyright (C) 2010-2015 Mamadou DIOP.
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO 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 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO 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 DOUBANGO.
*
*/

/**@file thttp_url.h
 * @brief HTTP/HTTPS URL.
 *
 */
#ifndef TINYHTTP_URL_H
#define TINYHTTP_URL_H

#include "tinyhttp_config.h"

#include "tsk_object.h"
#include "tsk_params.h"
#include "tsk_buffer.h"

THTTP_BEGIN_DECLS

#define THTTP_URL_IS_SECURE(url)		((url && url->type==thttp_url_https) ? 1 : 0)

/** Url type.
*/
typedef enum thttp_url_type_e {
    thttp_url_unknown,
    thttp_url_http,
    thttp_url_https,
}
thttp_url_type_t;

typedef enum thttp_host_type_e {
    thttp_host_unknown,
    thttp_host_hostname,
    thttp_host_ipv4,
    thttp_host_ipv6
}
thttp_host_type_t;

////////////////////////////////////////////////////////////////////////////////////////////////////
/// @struct	thttp_url_t
///
/// @brief	HTTP/HTTPS URL.
///
/// ABNF (Compact: From RFC 1738): httpurl        = "http://" hostport [ "/" hpath [ "?" search ]]
/// hpath          = hsegment *[ "/" hsegment ]
/// hsegment       = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
/// search         = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct thttp_url_s {
    TSK_DECLARE_OBJECT;

    thttp_url_type_t type;
    char *scheme;
    char *host; /**< Host name. Hostname or IPv4address or IPv6address. */
    char *hpath;
    char *search;
    thttp_host_type_t host_type; /**< IPv4 or IPv6 or domain name. */
    uint16_t port;
}
thttp_url_t;

TINYHTTP_API int thttp_url_serialize(const thttp_url_t *url, tsk_buffer_t *output);
TINYHTTP_API char* thttp_url_tostring(const thttp_url_t *url);
TINYHTTP_API thttp_url_t *thttp_url_clone(const thttp_url_t *url);
TINYHTTP_API tsk_bool_t thttp_url_isvalid(const char* urlstring);

thttp_url_t* thttp_url_create(thttp_url_type_t type);

TINYHTTP_GEXTERN const tsk_object_def_t *thttp_url_def_t;

THTTP_END_DECLS

#endif /* TINYHTTP_URL_H */

OpenPOWER on IntegriCloud