doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
share.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  * $Id: share.c,v 1.16 2004/02/26 11:39:38 bagder Exp $
22  ***************************************************************************/
23 
24 #include "setup.h"
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <curl/curl.h>
29 #include "urldata.h"
30 #include "share.h"
31 
32 /* The last #include file should be: */
33 #ifdef CURLDEBUG
34 #include "memdebug.h"
35 #endif
36 
37 CURLSH *
39 {
40  struct Curl_share *share =
41  (struct Curl_share *)malloc(sizeof(struct Curl_share));
42  if (share) {
43  memset (share, 0, sizeof(struct Curl_share));
44  share->specifier |= (1<<CURL_LOCK_DATA_SHARE);
45  }
46 
47  return share;
48 }
49 
52 {
53  struct Curl_share *share = (struct Curl_share *)sh;
54  va_list param;
55  int type;
58  void *ptr;
59 
60  if (share->dirty)
61  /* don't allow setting options while one or more handles are already
62  using this share */
63  return CURLSHE_IN_USE;
64 
65  va_start(param, option);
66 
67  switch(option) {
68  case CURLSHOPT_SHARE:
69  /* this is a type this share will share */
70  type = va_arg(param, int);
71  share->specifier |= (1<<type);
72  switch( type )
73  {
74  case CURL_LOCK_DATA_DNS:
75  if (!share->hostcache) {
77  }
78  break;
79 
81  if (!share->cookies) {
82  share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE );
83  }
84  break;
85 
87  break;
88 
90  break;
91 
92  default:
93  return CURLSHE_BAD_OPTION;
94  }
95  break;
96 
97  case CURLSHOPT_UNSHARE:
98  /* this is a type this share will no longer share */
99  type = va_arg(param, int);
100  share->specifier &= ~(1<<type);
101  switch( type )
102  {
103  case CURL_LOCK_DATA_DNS:
104  if (share->hostcache) {
106  share->hostcache = NULL;
107  }
108  break;
109 
111  if (share->cookies) {
113  share->cookies = NULL;
114  }
115  break;
116 
118  break;
119 
121  break;
122 
123  default:
124  return CURLSHE_BAD_OPTION;
125  }
126  break;
127 
128  case CURLSHOPT_LOCKFUNC:
129  lockfunc = va_arg(param, curl_lock_function);
130  share->lockfunc = lockfunc;
131  break;
132 
134  unlockfunc = va_arg(param, curl_unlock_function);
135  share->unlockfunc = unlockfunc;
136  break;
137 
138  case CURLSHOPT_USERDATA:
139  ptr = va_arg(param, void *);
140  share->clientdata = ptr;
141  break;
142 
143  default:
144  return CURLSHE_BAD_OPTION;
145  }
146 
147  return CURLSHE_OK;
148 }
149 
152 {
153  struct Curl_share *share = (struct Curl_share *)sh;
154 
155  if (share == NULL)
156  return CURLSHE_INVALID;
157 
159  share->clientdata);
160 
161  if (share->dirty) {
163  return CURLSHE_IN_USE;
164  }
165 
166  if(share->hostcache)
168 
169  if(share->cookies)
171 
173  free (share);
174 
175  return CURLSHE_OK;
176 }
177 
178 
181  curl_lock_access accesstype)
182 {
183  struct Curl_share *share = data->share;
184 
185  if (share == NULL)
186  return CURLSHE_INVALID;
187 
188  if(share->specifier & (1<<type)) {
189  if(share->lockfunc) /* only call this if set! */
190  share->lockfunc(data, type, accesstype, share->clientdata);
191  }
192  /* else if we don't share this, pretend successful lock */
193 
194  return CURLSHE_OK;
195 }
196 
199 {
200  struct Curl_share *share = data->share;
201 
202  if (share == NULL)
203  return CURLSHE_INVALID;
204 
205  if(share->specifier & (1<<type)) {
206  if(share->unlockfunc) /* only call this if set! */
207  share->unlockfunc (data, type, share->clientdata);
208  }
209 
210  return CURLSHE_OK;
211 }
curl_hash * hostcache
Definition: share.h:40
curl_lock_function lockfunc
Definition: share.h:36
void(* curl_lock_function)(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr)
Definition: curl.h:1185
curl_hash * Curl_hash_alloc(int slots, curl_hash_dtor dtor)
Definition: hash.c:95
volatile unsigned int dirty
Definition: share.h:34
GLfloat param
Definition: glext.h:3038
CURLSHoption
Definition: curl.h:1203
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
unsigned int specifier
Definition: share.h:33
void(* curl_unlock_function)(CURL *handle, curl_lock_data data, void *userptr)
Definition: curl.h:1189
CURLSH * curl_share_init(void)
Definition: share.c:38
void * clientdata
Definition: share.h:38
#define NULL
Definition: Lib.h:88
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
CURLSHcode
Definition: curl.h:1195
void Curl_freednsinfo(void *freethis)
Definition: hostip.c:443
struct Curl_share * share
Definition: urldata.h:897
void CURLSH
Definition: curl.h:1193
curl_lock_access
Definition: curl.h:1178
void Curl_hash_destroy(curl_hash *h)
Definition: hash.c:278
struct CookieInfo * cookies
Definition: share.h:41
CURLSHcode curl_share_cleanup(CURLSH *sh)
Definition: share.c:151
CURLSHcode curl_share_setopt(CURLSH *sh, CURLSHoption option,...)
Definition: share.c:51
curl_lock_data
Definition: curl.h:1163
CURLSHcode Curl_share_lock(struct SessionHandle *data, curl_lock_data type, curl_lock_access accesstype)
Definition: share.c:180
#define TRUE
Definition: mprintf.c:69
curl_unlock_function unlockfunc
Definition: share.h:37
CURLSHcode Curl_share_unlock(struct SessionHandle *data, curl_lock_data type)
Definition: share.c:198