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