summaryrefslogtreecommitdiffstats
path: root/nanohttp/nanohttp-url.h
blob: 6e72749fe9aaaad7593f03d9ab4af5acf23fff93 (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
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
121
122
123
124
125
126
127
128
/******************************************************************
 *  $Id: nanohttp-url.h,v 1.3 2006/12/11 08:13:19 m0gg Exp $
 * 
 * CSOAP Project:  A http client/server library in C
 * Copyright (C) 2003-2004  Ferhat Ayaz
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * 
 * Email: ferhatayaz@yahoo.com
 ******************************************************************/
#ifndef __nanohttp_url_h
#define __nanohttp_url_h

/**
 *
 * URL errors
 *
 */
#define URL_ERROR			1100
#define URL_ERROR_UNKNOWN_PROTOCOL	(URL_ERROR + 1)
#define URL_ERROR_NO_PROTOCOL		(URL_ERROR + 2)
#define URL_ERROR_NO_HOST		(URL_ERROR + 3)

/**
 *
 * The protocol types in enumeration format. Used in some other nanohttp objects
 * like hurl_t.
 *
 * @see hurl_t
 *
 */
typedef enum _hprotocol
{
  PROTOCOL_HTTP,
  PROTOCOL_HTTPS
} hprotocol_t;

/**
 *
 * The URL object. A representation of an URL like:
 *
 * [protocol]://[user]@[host]:[port]/[context]['#' fragment]['?' query]
 *
 * @see http://www.ietf.org/rfc/rfc2396.txt
 *
 */
struct hurl_t
{
  /**
   *
   * The transfer protocol. Note that only PROTOCOL_HTTP and PROTOCOL_HTTPS are
   * supported by nanohttp.
   *
   */
  hprotocol_t protocol;

  /**
   *
   * The port number. If no port number was given in the URL, one of the default
   * port numbers will be selected: 
   * - HTTP_DEFAULT_PORT    
   * - HTTPS_DEFAULT_PORT   
   *
   */
  unsigned short port;

  /**
   *
   * The hostname
   *
   */
  char *host;

  /**
   *
   * The string after the hostname.
   *
   */
  char *context;
};

#ifdef __cplusplus
extern "C" {
#endif

/**
 *
 * Parses the given 'urlstr' and fills the given hurl_t object.
 * Parse an URI URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
 *
 * @param obj the destination URL object to fill
 * @param url the URL in string format
 *
 * @returns H_OK on success or one of the following otherwise
 *          - URL_ERROR_UNKNOWN_PROTOCOL 
 *          - URL_ERROR_NO_PROTOCOL 
 *          - URL_ERROR_NO_HOST 
 *
 */
extern herror_t hurl_parse(struct hurl_t * obj, const char *url);

/**
 *
 * Frees the resources within a url and the url itself.
 *
 * @param url pointer to an hurl_t
 *
 */
extern void hurl_free(struct hurl_t *url);

#ifdef __cplusplus
}
#endif

#endif