xref: /titanic_41/usr/src/uts/common/fs/sockfs/nl7curi.h (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_SOCKFS_NL7CURI_H
28 #define	_SYS_SOCKFS_NL7CURI_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/atomic.h>
38 #include <sys/cmn_err.h>
39 #include <sys/stropts.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
42 
43 /*
44  * Some usefull chararcter macros:
45  */
46 
47 #ifndef	tolower
48 #define	tolower(c) ((c) >= 'A' && (c) <= 'Z' ? (c) | 0x20 : (c))
49 #endif
50 
51 #ifndef	isdigit
52 #define	isdigit(c) ((c) >= '0' && (c) <= '9')
53 #endif
54 
55 #ifndef isalpha
56 #define	isalpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
57 #endif
58 
59 #ifndef isspace
60 #define	isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || \
61 		(c) == '\r' || (c) == '\f' || (c) == '\013')
62 #endif
63 
64 /*
65  * ref_t - reference type, ...
66  *
67  * Note, all struct's must contain a single ref_t, all must use
68  * kmem_cache, all must use the REF_* macros for free.
69  */
70 
71 typedef struct ref_s {
72 	uint32_t	cnt;		/* Reference count */
73 	void		(*last)(void *); /* Call-back for last ref */
74 	kmem_cache_t	*kmc;		/* Container allocator cache */
75 } ref_t;
76 
77 #define	REF_INIT(container, count, inactive, kmem) {			\
78 	(container)->ref.cnt = (count);					\
79 	(container)->ref.last = (void (*)(void *))((inactive));		\
80 	(container)->ref.kmc = (kmem);					\
81 }
82 
83 #define	REF_HOLD(container) {						\
84 	atomic_add_32(&(container)->ref.cnt, 1);			\
85 	ASSERT((container)->ref.cnt != 0);				\
86 }
87 
88 #define	REF_RELE(container) {						\
89 	if (atomic_add_32_nv(&(container)->ref.cnt, -1) == 0) {		\
90 		(container)->ref.last((container));			\
91 		kmem_cache_free((container)->ref.kmc, (container));	\
92 	}								\
93 }
94 
95 #define	REF_ASSERT(container, count)					\
96 	ASSERT((container)->ref.cnt == (count));
97 
98 /*
99  * str_t - string type, used to access a an arbitrary span of a char[].
100  */
101 
102 typedef struct str_s {
103 	char	*cp;			/* Char pointer current char */
104 	char	*ep;			/* Char pointer past end of string */
105 } str_t;
106 
107 /*
108  * uri_*_t - URI descriptor, used to describe a cached URI object.
109  */
110 
111 typedef struct uri_rd_s {
112 	size_t		sz;		/* Size of data */
113 	offset_t	off;		/* Offset into file or -1 for kmem */
114 	union {				/* Response data */
115 		char	*kmem;		/* Data in kmem */
116 		vnode_t	*vnode;		/* Data in vnode */
117 	} data;
118 	struct uri_rd_s *next;		/* Next response descriptor */
119 } uri_rd_t;
120 
121 typedef struct uri_desc_s {
122 	struct uri_desc_s *hash;	/* Hash *next */
123 	uint64_t	hit;		/* Hit counter */
124 	clock_t		expire;		/* URI lbolt expires on (-1 = NEVER) */
125 	boolean_t	nocache;	/* URI no cache */
126 
127 	mblk_t		*reqmp;		/* Request mblk_t */
128 	str_t		path;		/* Path name of response  */
129 	str_t		auth;		/* Authority for response */
130 	ssize_t		resplen;	/* Response length */
131 	char		*eoh;		/* End of header pointer */
132 	void		*scheme;	/* Scheme private state */
133 
134 	ref_t		ref;		/* Reference stuff */
135 
136 	size_t		count;		/* rd_t chain byte cound */
137 	uri_rd_t	*tail;		/* Last response descriptor */
138 	uri_rd_t	response;	/* First response descriptor */
139 
140 	struct sonode	*proc;		/* Socket processing this uri */
141 	kcondvar_t	waiting;	/* Socket(s) waiting for processing */
142 	kmutex_t	proclock;	/* Lock for proc and waiting */
143 } uri_desc_t;
144 
145 #define	URI_TEMP (uri_desc_t *)-1	/* Temp (nocache) uri_t.hash pointer */
146 #define	URI_TEMP_PARSE_SZ 512		/* Enough bytes to parse for headers */
147 
148 typedef struct uri_segmap_s {
149 	ref_t		ref;		/* Reference, one per uri_desb_t */
150 	caddr_t		base;		/* Base addr of segmap mapping */
151 	size_t		len;		/* Length of segmap mapping */
152 	vnode_t		*vp;		/* Vnode mapped */
153 } uri_segmap_t;
154 
155 typedef struct uri_desb_s {
156 	frtn_t		frtn;		/* For use by esballoc() and freinds */
157 	uri_desc_t	*uri;		/* Containing URI of REF_HOLD() */
158 	uri_segmap_t	*segmap;	/* If segmap mapped else NULL */
159 } uri_desb_t;
160 
161 /*
162  * Function prototypes:
163  */
164 
165 boolean_t nl7c_http_request(char **, char *, uri_desc_t *, struct sonode *);
166 boolean_t nl7c_http_response(char **, char *, uri_desc_t *, struct sonode *);
167 boolean_t nl7c_http_cmp(void *, void *);
168 mblk_t *nl7c_http_persist(struct sonode *);
169 void nl7c_http_free(void *arg);
170 void nl7c_http_init(void);
171 
172 #ifdef	__cplusplus
173 }
174 #endif
175 
176 #endif	/* _SYS_SOCKFS_NL7CURI_H */
177