Browse Source

xmlrpc: more correct re XMLRPC spec re. no type specified, defaults to string
- This will allow you to receive docs like <value>mystringvalue</value>
- instead of only allowing <value><string>mystringvalue</string></value>
- according to spec if no type specified, assume string
- allows kamailio to receive messages from apache ws-xmlrpc which doesnt specify string type

Jason Penton 13 years ago
parent
commit
fbc6ce9c07
1 changed files with 23 additions and 6 deletions
  1. 23 6
      modules/xmlrpc/xmlrpc.c

+ 23 - 6
modules/xmlrpc/xmlrpc.c

@@ -1126,6 +1126,7 @@ static time_t xmlrpc2time(const char* str)
 /* xml value types */
 /* xml value types */
 enum xmlrpc_val_type{
 enum xmlrpc_val_type{
 	XML_T_STR,
 	XML_T_STR,
+	XML_T_TXT,
 	XML_T_INT,
 	XML_T_INT,
 	XML_T_BOOL,
 	XML_T_BOOL,
 	XML_T_DATE,
 	XML_T_DATE,
@@ -1142,6 +1143,8 @@ static enum xmlrpc_val_type xml_get_type(xmlNodePtr value)
 {
 {
 	if (!xmlStrcmp(value->name, BAD_CAST "string")){
 	if (!xmlStrcmp(value->name, BAD_CAST "string")){
 		return XML_T_STR;
 		return XML_T_STR;
+	} else if (!xmlStrcmp(value->name, BAD_CAST "text")) {
+		return XML_T_TXT;
 	} else if ( !xmlStrcmp(value->name, BAD_CAST "i4") ||
 	} else if ( !xmlStrcmp(value->name, BAD_CAST "i4") ||
 				!xmlStrcmp(value->name, BAD_CAST "int")) {
 				!xmlStrcmp(value->name, BAD_CAST "int")) {
 		return XML_T_INT;
 		return XML_T_INT;
@@ -1204,6 +1207,7 @@ static int get_int(int* val, struct xmlrpc_reply* reply,
 			break;
 			break;
 		case XML_T_DOUBLE:
 		case XML_T_DOUBLE:
 		case XML_T_STR:
 		case XML_T_STR:
+		case XML_T_TXT:
 			if (flags & GET_X_AUTOCONV)
 			if (flags & GET_X_AUTOCONV)
 				break;
 				break;
 		case XML_T_ERR:
 		case XML_T_ERR:
@@ -1211,8 +1215,10 @@ static int get_int(int* val, struct xmlrpc_reply* reply,
 				set_fault(reply, 400, "Invalid Parameter Type");
 				set_fault(reply, 400, "Invalid Parameter Type");
 			return -1;
 			return -1;
 	}
 	}
-
-	val_str = (char*)xmlNodeListGetString(doc, i4->xmlChildrenNode, 1);
+	if (type == XML_T_TXT)
+		val_str = (char*)i4->content;
+	else
+		val_str = (char*)xmlNodeListGetString(doc, i4->xmlChildrenNode, 1);
 	if (!val_str) {
 	if (!val_str) {
 		if (!(flags & GET_X_NOREPLY))
 		if (!(flags & GET_X_NOREPLY))
 			set_fault(reply, 400, "Empty Parameter Value");
 			set_fault(reply, 400, "Empty Parameter Value");
@@ -1223,6 +1229,7 @@ static int get_int(int* val, struct xmlrpc_reply* reply,
 		case XML_T_INT:
 		case XML_T_INT:
 		case XML_T_BOOL:
 		case XML_T_BOOL:
 		case XML_T_STR:
 		case XML_T_STR:
+		case XML_T_TXT:
 			/* Integer/bool conversion */
 			/* Integer/bool conversion */
 			*val = strtol(val_str, &end_ptr, 10);
 			*val = strtol(val_str, &end_ptr, 10);
 			if (val_str==end_ptr)
 			if (val_str==end_ptr)
@@ -1295,6 +1302,7 @@ static int get_double(double* val, struct xmlrpc_reply* reply,
 		case XML_T_BOOL:
 		case XML_T_BOOL:
 		case XML_T_DATE:
 		case XML_T_DATE:
 		case XML_T_STR:
 		case XML_T_STR:
+		case XML_T_TXT:
 			if (flags & GET_X_AUTOCONV)
 			if (flags & GET_X_AUTOCONV)
 				break;
 				break;
 		case XML_T_ERR:
 		case XML_T_ERR:
@@ -1302,8 +1310,10 @@ static int get_double(double* val, struct xmlrpc_reply* reply,
 				set_fault(reply, 400, "Invalid Parameter Type");
 				set_fault(reply, 400, "Invalid Parameter Type");
 			return -1;
 			return -1;
 	}
 	}
-
-	val_str = (char*)xmlNodeListGetString(doc, dbl->xmlChildrenNode, 1);
+	if (type == XML_T_TXT)
+		val_str = (char*)dbl->content;
+	else
+		val_str = (char*)xmlNodeListGetString(doc, dbl->xmlChildrenNode, 1);
 	if (!val_str) {
 	if (!val_str) {
 		if (!(flags & GET_X_NOREPLY))
 		if (!(flags & GET_X_NOREPLY))
 			set_fault(reply, 400, "Empty Double Parameter");
 			set_fault(reply, 400, "Empty Double Parameter");
@@ -1315,6 +1325,7 @@ static int get_double(double* val, struct xmlrpc_reply* reply,
 		case XML_T_INT:
 		case XML_T_INT:
 		case XML_T_BOOL:
 		case XML_T_BOOL:
 		case XML_T_STR:
 		case XML_T_STR:
+		case XML_T_TXT:
 			*val = strtod(val_str, &end_ptr);
 			*val = strtod(val_str, &end_ptr);
 			if (val_str==end_ptr)
 			if (val_str==end_ptr)
 				ret=-1;
 				ret=-1;
@@ -1379,6 +1390,7 @@ static int get_string(char** val, struct xmlrpc_reply* reply,
 	type=xml_get_type(dbl);
 	type=xml_get_type(dbl);
 	switch(type){
 	switch(type){
 		case XML_T_STR:
 		case XML_T_STR:
+		case XML_T_TXT:
 			break;
 			break;
 		case XML_T_INT:
 		case XML_T_INT:
 		case XML_T_BOOL:
 		case XML_T_BOOL:
@@ -1391,9 +1403,13 @@ static int get_string(char** val, struct xmlrpc_reply* reply,
 				set_fault(reply, 400, "Invalid Parameter Type");
 				set_fault(reply, 400, "Invalid Parameter Type");
 			return -1;
 			return -1;
 	}
 	}
-	val_str = (char*)xmlNodeListGetString(doc, dbl->xmlChildrenNode, 1);
+	if (type == XML_T_TXT)
+		val_str = (char*)dbl->content;
+	else
+		val_str = (char*)xmlNodeListGetString(doc, dbl->xmlChildrenNode, 1);
+
 	if (!val_str) {
 	if (!val_str) {
-		if (type==XML_T_STR){
+		if (type==XML_T_STR || type==XML_T_TXT){
 			*val = null_str;
 			*val = null_str;
 			return 0;
 			return 0;
 		}else{
 		}else{
@@ -1405,6 +1421,7 @@ static int get_string(char** val, struct xmlrpc_reply* reply,
 	ret=0;
 	ret=0;
 	switch(type){
 	switch(type){
 		case XML_T_STR:
 		case XML_T_STR:
+		case XML_T_TXT:
 			if (flags & GET_X_LFLF2CRLF){
 			if (flags & GET_X_LFLF2CRLF){
 				p=val_str;
 				p=val_str;
 				while(*p){
 				while(*p){