src/server/daemon/req.c

changeset 654
be69e8196cc9
equal deleted inserted replaced
653:c4dae65155e9 654:be69e8196cc9
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5 *
6 * THE BSD LICENSE
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * Neither the name of the nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 // Open Web Server frame/req.cpp
35
36 #include "req.h"
37
38 #include "../util/pblock.h"
39
40 /* ---------------------------- request_depth ----------------------------- */
41
42 static inline void request_depth(Request *rq, int *prestarted, int *pinternal)
43 {
44 // Calculate the depth of the rq->orig_rq linked list
45 while (rq->orig_rq != rq) {
46 if (rq->rq_attr.req_restarted)
47 (*prestarted)++;
48 if (rq->rq_attr.internal_req)
49 (*pinternal)++;
50 rq = rq->orig_rq;
51 }
52 }
53
54 /* ------------------------- request_get_base_uri ------------------------- */
55
56 NSAPI_PUBLIC void request_get_base_uri(Request *rq, const char **pbase,
57 int *plen)
58 {
59 // URI Base URI
60 // ------------------- ---------
61 // /index.html /
62 // /foo/bar/ /foo/bar/
63 // /foo/bar/index.html /foo/bar/
64 // /cgi-bin/foo.pl/bar /cgi-bin/
65
66 if (rq) {
67 const char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
68 if (uri) {
69 int len = strlen(uri);
70 const char *path_info = pblock_findkeyval(pb_key_path_info, rq->vars);
71 if (path_info) {
72 int suffixlen = strlen(path_info);
73 if (len > suffixlen)
74 len -= suffixlen;
75 }
76
77 do { len--; } while (len > 0 && uri[len] != '/');
78
79 if (len > 0) {
80 *pbase = uri;
81 *plen = len + 1;
82 return;
83 }
84 }
85 }
86
87 *pbase = "/";
88 *plen = 1;
89 }
90
91 /* ------------------------- request_is_internal -------------------------- */
92
93 NSAPI_PUBLIC int request_is_internal(Request *rq)
94 {
95 return (rq->rq_attr.internal_req == 1);
96 }
97
98
99 /* ------------------------- request_is_restarted ------------------------- */
100
101 NSAPI_PUBLIC PRBool request_is_restarted(Request *rq)
102 {
103 return (rq->rq_attr.req_restarted == 1);
104 }
105
106
107 /* --------------------- request_is_default_type_set ---------------------- */
108
109 NSAPI_PUBLIC PRBool request_is_default_type_set(const Request *rq)
110 {
111 return (rq->rq_attr.default_type_set == 1);
112 }
113
114
115 /* ----------------------- request_has_default_type ----------------------- */
116
117 NSAPI_PUBLIC void request_has_default_type(Request *rq)
118 {
119 rq->rq_attr.default_type_set = 1;
120 }

mercurial