Changeset 640 for trunk/zoo-project/zoo-kernel/request_parser.c
- Timestamp:
- May 28, 2015, 4:25:06 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/request_parser.c
r631 r640 25 25 #include "request_parser.h" 26 26 #include "service_internal.h" 27 #include "server_internal.h" 28 #include "response_print.h" 29 #include "caching.h" 27 30 28 31 /** … … 127 130 } 128 131 return 0; 132 } 133 134 /** 135 * Make sure that each value encoded in base64 in a maps is decoded. 136 * 137 * @param in the maps containing the values 138 * @see readBase64 139 */ 140 void ensureDecodedBase64(maps **in){ 141 maps* cursor=*in; 142 while(cursor!=NULL){ 143 map *tmp=getMap(cursor->content,"encoding"); 144 if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){ 145 tmp=getMap(cursor->content,"value"); 146 readBase64(&tmp); 147 addToMap(cursor->content,"base64_value",tmp->value); 148 int size=0; 149 char *s=strdup(tmp->value); 150 free(tmp->value); 151 tmp->value=base64d(s,strlen(s),&size); 152 free(s); 153 char sizes[1024]; 154 sprintf(sizes,"%d",size); 155 addToMap(cursor->content,"size",sizes); 156 } 157 map* length=getMap(cursor->content,"length"); 158 if(length!=NULL){ 159 int len=atoi(length->value); 160 for(int i=1;i<len;i++){ 161 tmp=getMapArray(cursor->content,"encoding",i); 162 if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){ 163 char key[17]; 164 sprintf(key,"base64_value_%d",i); 165 tmp=getMapArray(cursor->content,"value",i); 166 readBase64(&tmp); 167 addToMap(cursor->content,key,tmp->value); 168 int size=0; 169 char *s=strdup(tmp->value); 170 free(tmp->value); 171 tmp->value=base64d(s,strlen(s),&size); 172 free(s); 173 char sizes[1024]; 174 sprintf(sizes,"%d",size); 175 sprintf(key,"size_%d",i); 176 addToMap(cursor->content,key,sizes); 177 } 178 } 179 } 180 cursor=cursor->next; 181 } 129 182 } 130 183 … … 1448 1501 return 1; 1449 1502 } 1503 1504 1505 /** 1506 * Verify if a parameter value is valid. 1507 * 1508 * @param request the request map 1509 * @param res the error map potentially generated 1510 * @param toCheck the parameter to use 1511 * @param avalues the acceptable values (or null if testing only for presence) 1512 * @param mandatory verify the presence of the parameter if mandatory > 0 1513 */ 1514 void checkValidValue(map* request,map** res,const char* toCheck,const char** avalues,int mandatory){ 1515 map* lres=*res; 1516 map* r_inputs = getMap (request,toCheck); 1517 if (r_inputs == NULL){ 1518 if(mandatory>0){ 1519 char *replace=_("Mandatory parameter <%s> was not specified"); 1520 char *message=(char*)malloc((strlen(replace)+strlen(toCheck)+1)*sizeof(char)); 1521 sprintf(message,replace,toCheck); 1522 if(lres==NULL){ 1523 lres=createMap("code","MissingParameterValue"); 1524 addToMap(lres,"text",message); 1525 addToMap(lres,"locator",toCheck); 1526 }else{ 1527 int length=1; 1528 map* len=getMap(lres,"length"); 1529 if(len!=NULL){ 1530 length=atoi(len->value); 1531 } 1532 setMapArray(lres,"text",length,message); 1533 setMapArray(lres,"locator",length,toCheck); 1534 setMapArray(lres,"code",length,"MissingParameter"); 1535 } 1536 free(message); 1537 } 1538 }else{ 1539 if(avalues==NULL) 1540 return; 1541 int nb=0; 1542 int hasValidValue=-1; 1543 if(strncasecmp(toCheck,"Accept",6)==0){ 1544 char *tmp=zStrdup(r_inputs->value); 1545 char *pToken,*saveptr; 1546 pToken=strtok_r(tmp,",",&saveptr); 1547 while(pToken!=NULL){ 1548 while(avalues[nb]!=NULL){ 1549 if(strcasecmp(avalues[nb],pToken)==0){ 1550 hasValidValue=1; 1551 break; 1552 } 1553 nb++; 1554 } 1555 pToken=strtok_r(NULL,",",&saveptr); 1556 } 1557 free(tmp); 1558 }else{ 1559 while(avalues[nb]!=NULL){ 1560 if(strcasecmp(avalues[nb],r_inputs->value)==0){ 1561 hasValidValue=1; 1562 break; 1563 } 1564 nb++; 1565 } 1566 } 1567 if(hasValidValue<0){ 1568 char *replace=_("The value <%s> was not recognized, %s %s the only acceptable value."); 1569 nb=0; 1570 char *vvalues=NULL; 1571 char* num=_("is"); 1572 while(avalues[nb]!=NULL){ 1573 char *tvalues; 1574 if(vvalues==NULL){ 1575 vvalues=(char*)malloc((strlen(avalues[nb])+3)*sizeof(char)); 1576 sprintf(vvalues,"%s",avalues[nb]); 1577 } 1578 else{ 1579 tvalues=zStrdup(vvalues); 1580 vvalues=(char*)realloc(vvalues,(strlen(tvalues)+strlen(avalues[nb])+3)*sizeof(char)); 1581 sprintf(vvalues,"%s, %s",tvalues,avalues[nb]); 1582 free(tvalues); 1583 num=_("are"); 1584 } 1585 nb++; 1586 } 1587 char *message=(char*)malloc((strlen(replace)+strlen(num)+strlen(vvalues)+strlen(toCheck)+1)*sizeof(char)); 1588 sprintf(message,replace,toCheck,vvalues,num); 1589 const char *code="VersionNegotiationFailed"; 1590 code="InvalidParameterValue"; 1591 const char *locator=toCheck; 1592 if( strncasecmp(toCheck,"version",7)==0 || 1593 strncasecmp(toCheck,"AcceptVersions",14)==0 ) 1594 code="VersionNegotiationFailed"; 1595 if( strncasecmp(toCheck,"request",7)==0){ 1596 code="OperationNotSupported"; 1597 locator=r_inputs->value; 1598 } 1599 if(lres==NULL){ 1600 lres=createMap("code","InvalidParameterValue"); 1601 addToMap(lres,"text",message); 1602 addToMap(lres,"locator",locator); 1603 }else{ 1604 int length=1; 1605 map* len=getMap(lres,"length"); 1606 if(len!=NULL){ 1607 length=atoi(len->value); 1608 } 1609 setMapArray(lres,"text",length,message); 1610 setMapArray(lres,"locator",length,locator); 1611 setMapArray(lres,"code",length,"InvalidParameterValue"); 1612 } 1613 } 1614 } 1615 if(lres!=NULL){ 1616 *res=lres; 1617 } 1618 }
Note: See TracChangeset
for help on using the changeset viewer.