source: rtems/cpukit/httpd/url.c @ dc2a1750

4.104.114.84.95
Last change on this file since dc2a1750 was ee3afa2, checked in by Joel Sherrill <joel.sherrill@…>, on 04/11/03 at 14:46:55

2002-04-10 Mike Siers <mikes@…>

  • rtems_webserver/NOTES, rtems_webserver/asp.c, rtems_webserver/balloc.c, rtems_webserver/default.c, rtems_webserver/ej.h, rtems_webserver/ejIntrn.h, rtems_webserver/ejlex.c, rtems_webserver/ejparse.c, rtems_webserver/emfdb.c, rtems_webserver/emfdb.h, rtems_webserver/form.c, rtems_webserver/h.c, rtems_webserver/handler.c, rtems_webserver/license.txt, rtems_webserver/md5.h, rtems_webserver/md5c.c, rtems_webserver/mime.c, rtems_webserver/misc.c, rtems_webserver/ringq.c, rtems_webserver/rom.c, rtems_webserver/security.c, rtems_webserver/sock.c, rtems_webserver/sym.c, rtems_webserver/uemf.c, rtems_webserver/uemf.h, rtems_webserver/um.c, rtems_webserver/um.h, rtems_webserver/url.c, rtems_webserver/value.c, rtems_webserver/wbase64.c, rtems_webserver/webcomp.c, rtems_webserver/webpage.c, rtems_webserver/webrom.c, rtems_webserver/webs.c, rtems_webserver/webs.h, rtems_webserver/websuemf.c, rtems_webserver/wsIntrn.h: Update to GoAhead? Webserver 2.1.4. The following URL is the release notes from GoAhead?.

http://data.goahead.com/Software/Webserver/2.1.4/release.htm

I have only done a minimal amount of testing (i.e. the network
demo program works fine). Please try this out and let me know
if it works. The patch needs to be applied on the
c/src/libnetworking/rtems_webserver directory.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * url.c -- Parse URLs
3 *
4 * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
5 *
6 * See the file "license.txt" for usage and redistribution license requirements
7 *
8 * $Id$
9 */
10
11/******************************** Description *********************************/
12
13/*
14 *      This module parses URLs into their components.
15 */
16
17/********************************* Includes ***********************************/
18
19#include        "wsIntrn.h"
20
21/********************************* Statics ************************************/
22/*
23 *      htmExt is declared in this way to avoid a Linux and Solaris segmentation
24 *      fault when a constant string is passed to strlower which could change its
25 *      argument.
26 */
27
28char_t  htmExt[] = T(".htm");
29
30
31/*********************************** Code *************************************/
32/*
33 *      Return the mime type for the given URL given a URL.
34 *      The caller supplies the buffer to hold the result.
35 *      charCnt is the number of characters the buffer will hold, ascii or UNICODE.
36 */
37
38char_t *websUrlType(char_t *url, char_t *buf, int charCnt)
39{
40        sym_t   *sp;
41        char_t  *ext, *parsebuf;
42
43        a_assert(url && *url);
44        a_assert(buf && charCnt > 0);
45
46        if (url == NULL || *url == '\0') {
47                gstrcpy(buf, T("text/plain"));
48                return buf;
49        }
50        if (websUrlParse(url, &parsebuf, NULL, NULL, NULL, NULL, NULL,
51                        NULL, &ext) < 0) {
52                gstrcpy(buf, T("text/plain"));
53                return buf;
54        }
55        strlower(ext);
56
57/*
58 *      Lookup the mime type symbol table to find the relevant content type
59 */
60        if ((sp = symLookup(websMime, ext)) != NULL) {
61                gstrncpy(buf, sp->content.value.string, charCnt);
62        } else {
63                gstrcpy(buf, T("text/plain"));
64        }
65        bfree(B_L, parsebuf);
66        return buf;
67}
68
69/******************************************************************************/
70/*
71 *      Parse the URL. A buffer is allocated to store the parsed URL in *pbuf.
72 *      This must be freed by the caller. NOTE: tag is not yet fully supported.
73 */
74
75int websUrlParse(char_t *url, char_t **pbuf, char_t **phost, char_t **ppath,
76        char_t **pport, char_t **pquery, char_t **pproto, char_t **ptag,
77        char_t **pext)
78{
79        char_t          *tok, *cp, *host, *path, *port, *proto, *tag, *query, *ext;
80        char_t          *last_delim, *hostbuf, *portbuf, *buf;
81        int                     c, len, ulen;
82
83        a_assert(url);
84        a_assert(pbuf);
85
86        ulen = gstrlen(url);
87/*
88 *      We allocate enough to store separate hostname and port number fields.
89 *      As there are 3 strings in the one buffer, we need room for 3 null chars.
90 *      We allocate MAX_PORT_LEN char_t's for the port number.
91 */
92        len = ulen * 2 + MAX_PORT_LEN + 3;
93        if ((buf = balloc(B_L, len * sizeof(char_t))) == NULL) {
94                return -1;
95        }
96        portbuf = &buf[len - MAX_PORT_LEN - 1];
97        hostbuf = &buf[ulen+1];
98        gstrcpy(buf, url);
99        url = buf;
100
101/*
102 *      Convert the current listen port to a string. We use this if the URL has
103 *      no explicit port setting
104 */
105        stritoa(websGetPort(), portbuf, MAX_PORT_LEN);
106        port = portbuf;
107        path = T("/");
108        proto = T("http");
109        host = T("localhost");
110        query = T("");
111        ext = htmExt;
112        tag = T("");
113
114        if (gstrncmp(url, T("http://"), 7) == 0) {
115                tok = &url[7];
116                tok[-3] = '\0';
117                proto = url;
118                host = tok;
119                for (cp = tok; *cp; cp++) {
120                        if (*cp == '/') {
121                                break;
122                        }
123                        if (*cp == ':') {
124                                *cp++ = '\0';
125                                port = cp;
126                                tok = cp;
127                        }
128                }
129                if ((cp = gstrchr(tok, '/')) != NULL) {
130/*
131 *                      If a full URL is supplied, we need to copy the host and port
132 *                      portions into static buffers.
133 */
134                        c = *cp;
135                        *cp = '\0';
136                        gstrncpy(hostbuf, host, ulen);
137                        gstrncpy(portbuf, port, MAX_PORT_LEN);
138                        *cp = c;
139                        host = hostbuf;
140                        port = portbuf;
141                        path = cp;
142                        tok = cp;
143                }
144
145        } else {
146                path = url;
147                tok = url;
148        }
149
150/*
151 *      Parse the query string
152 */
153        if ((cp = gstrchr(tok, '?')) != NULL) {
154                *cp++ = '\0';
155                query = cp;
156                path = tok;
157                tok = query;
158        }
159
160/*
161 *      Parse the fragment identifier
162 */
163        if ((cp = gstrchr(tok, '#')) != NULL) {
164                *cp++ = '\0';
165                if (*query == 0) {
166                        path = tok;
167                }
168        }
169
170/*
171 *      Only do the following if asked for the extension
172 */
173        if (pext) {
174                if ((cp = gstrrchr(path, '.')) != NULL) {
175                        if ((last_delim = gstrrchr(path, '/')) != NULL) {
176                                if (last_delim > cp) {
177                                        ext = htmExt;
178                                } else {
179                                        ext = cp;
180                                }
181                        } else {
182                                ext = cp;
183                        }
184                } else {
185                        if (path[gstrlen(path) - 1] == '/') {
186                                ext = htmExt;
187                        }
188                }
189        }
190
191/*
192 *      Pass back the fields requested (if not NULL)
193 */
194        if (phost)
195                *phost = host;
196        if (ppath)
197                *ppath = path;
198        if (pport)
199                *pport = port;
200        if (pproto)
201                *pproto = proto;
202        if (pquery)
203                *pquery = query;
204        if (ptag)
205                *ptag = tag;
206        if (pext)
207                *pext = ext;
208        *pbuf = buf;
209        return 0;
210}
211
212/******************************************************************************/
Note: See TracBrowser for help on using the repository browser.