Changeset 817 for trunk/zoo-project/zoo-kernel
- Timestamp:
- Feb 2, 2017, 4:24:57 PM (8 years ago)
- Location:
- trunk/zoo-project/zoo-kernel
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/caching.c
r797 r817 292 292 int hasAFailure=0; 293 293 if(hInternet!=NULL && hInternet->nb>0){ 294 AddHeaderEntries(hInternet,*m); 294 295 processDownloads(hInternet); 295 296 maps* content=*inputs; -
trunk/zoo-project/zoo-kernel/configure.ac
r813 r817 1 AC_INIT([ZOO Kernel], [1. 6.0], [bugs@zoo-project.org])1 AC_INIT([ZOO Kernel], [1.7.0], [bugs@zoo-project.org]) 2 2 3 3 # Checks for programs. -
trunk/zoo-project/zoo-kernel/ulinet.c
r797 r817 30 30 #include "ulinet.h" 31 31 #include <assert.h> 32 #include <ctype.h> 32 33 33 34 /** … … 219 220 220 221 /** 222 * Add missing headers to an existing _HINTERNET 223 * 224 * 225 * @param handle the _HINTERNET pointer 226 * @param key the header parameter name 227 * @param value the header parameter value 228 * @return 0 if the operation succeeded, -1 in other case. 229 */ 230 int AddMissingHeaderEntry(_HINTERNET* handle,const char* key,const char* value){ 231 int length=strlen(key)+strlen(value)+3; 232 char *entry=(char*)malloc((length)*sizeof(char)); 233 if(entry==NULL) 234 return -1; 235 snprintf (entry, length, "%s: %s", key, value); 236 handle->header = curl_slist_append (handle->header, entry); 237 free(entry); 238 return 0; 239 } 240 241 /** 242 * Verify if a host is protected (appear in [security] > hosts) 243 * 244 * @param protectedHosts string containing all the protected hosts (coma separated) 245 * @param url string used to extract the host from 246 * @return 1 if the host is listed as protected, 0 in other case 247 */ 248 int isProtectedHost(const char* protectedHosts,const char* url){ 249 char *token, *saveptr; 250 token = strtok_r (url, "//", &saveptr); 251 int cnt=0; 252 char* host; 253 while(token!=NULL && cnt<=1){ 254 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,token); 255 if(cnt==1) 256 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,strstr(protectedHosts,token)); 257 fflush(stderr); 258 if(cnt==1 && strstr(protectedHosts,token)!=NULL){ 259 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,strstr(protectedHosts,token)); 260 return 1; 261 } 262 token = strtok_r (NULL, "/", &saveptr); 263 cnt+=1; 264 } 265 return 0; 266 } 267 268 /** 269 * Add headers defined in [security] > attributes to an existing HINTERNET 270 * @see isProtectedHost, AddMissingHeaderEntry 271 * 272 * @param handle the _HINTERNET pointer 273 * @param conf the header parameter name 274 * @param value the header parameter value 275 * @return 0 if the operation succeeded, -1 in other case. 276 */ 277 void AddHeaderEntries(HINTERNET* handle,maps* conf){ 278 map* passThrough=getMapFromMaps(conf,"security","attributes"); 279 map* targetHosts=getMapFromMaps(conf,"security","hosts"); 280 char* passedHeader[10]; 281 int cnt=0; 282 if(passThrough!=NULL && targetHosts!=NULL){ 283 char *tmp=zStrdup(passThrough->value); 284 char *token, *saveptr; 285 token = strtok_r (tmp, ",", &saveptr); 286 for(int i=0;i<handle->nb;i++){ 287 if(targetHosts->value[0]=='*' || isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){ 288 while (token != NULL){ 289 int length=strlen(token)+6; 290 char* tmp1=(char*)malloc(length*sizeof(char)); 291 snprintf(tmp1,6,"HTTP_"); 292 for(int i=0;token[i]!='\0';i++){ 293 if(token[i]!='-') 294 tmp1[5+i]=toupper(token[i]); 295 else 296 tmp1[5+i]='_'; 297 tmp1[5+i+1]='\0'; 298 } 299 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,tmp1); 300 map* tmpMap = getMapFromMaps(conf,"renv",tmp1); 301 if(tmpMap!=NULL) 302 AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value); 303 free(tmp1); 304 if(handle->ihandle[i].header!=NULL) 305 curl_easy_setopt(handle->ihandle[i].handle,CURLOPT_HTTPHEADER,handle->ihandle[i].header); 306 cnt+=1; 307 token = strtok_r (NULL, ",", &saveptr); 308 } 309 } 310 } 311 free(tmp); 312 } 313 } 314 315 /** 221 316 * Close a HINTERNET connection and free allocated resources 222 317 * … … 241 336 if(handle.post!=NULL) 242 337 free(handle.post); 338 if(handle.url!=NULL) 339 free(handle.url); 243 340 free(handle.mimeType); 244 341 handle.mimeType = NULL; … … 270 367 hInternet->ihandle[hInternet->nb].hasCacheFile=0; 271 368 hInternet->ihandle[hInternet->nb].nDataAlloc = 0; 369 hInternet->ihandle[hInternet->nb].url = NULL; 272 370 hInternet->ihandle[hInternet->nb].mimeType = NULL; 273 371 hInternet->ihandle[hInternet->nb].nDataLen = 0; … … 340 438 341 439 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_URL,lpszUrl); 440 hInternet->ihandle[hInternet->nb].url = zStrdup(lpszUrl); 342 441 343 442 curl_multi_add_handle(hInternet->handle,hInternet->ihandle[hInternet->nb].handle); -
trunk/zoo-project/zoo-kernel/ulinet.h
r630 r817 30 30 #include <fcntl.h> 31 31 #include <curl/curl.h> 32 #include "service.h" 32 33 #ifndef WIN32 33 34 #include <unistd.h> … … 84 85 FILE* file; //!< the file pointer 85 86 unsigned char *pabyData; //!< the downloaded content 87 char *url; //!< the url used to access the server 86 88 char *mimeType; //!< the mimeType returned by the server 87 89 char *post; //!< the potential POST XML content … … 134 136 HINTERNET InternetOpen(char*,int,char*,char*,int); 135 137 138 int isProtectedHost(const char*,const char*); 139 int AddMissingHeaderEntry(_HINTERNET*,const char*,const char*); 140 void AddHeaderEntries(HINTERNET*,maps*); 141 136 142 void InternetCloseHandle(HINTERNET*); 137 143 -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r794 r817 2100 2100 addMapsToMaps (&m, tmpSess); 2101 2101 freeMaps (&tmpSess); 2102 free (tmpSess);2103 2102 } 2103 free (tmpSess); 2104 2104 } 2105 2105 }
Note: See TracChangeset
for help on using the changeset viewer.