Parcourir la source

core: parse_to display name multi-token no-quotes fix

Fix for properly returning a non-quoted display name that is
composed of several tokens (contains spaces). The previous version
would set the display name to the first token, in this case
(e.g. Foo Bar <sip:foo@bar> resulted in display_name="Foo" instead
 of "Foo Bar").

Reported-by: Ronald Voermans  ronald voermans nu
Closes FlySpray#39 .
(cherry picked from commit 907686c0c4c1141af175d692251b8e1fab28b64e)
Andrei Pelinescu-Onciul il y a 15 ans
Parent
commit
b2ee4178b4
1 fichiers modifiés avec 33 ajouts et 6 suppressions
  1. 33 6
      parser/parse_to.c

+ 33 - 6
parser/parse_to.c

@@ -27,8 +27,13 @@
  * History:
  * ---------
  * 2003-04-26 ZSW (jiri)
+ * 2010-03-03  fix multi-token no-quotes display name (andrei)
  */
 
+/** Parser :: Parse To: header.
+ * @file
+ * @ingroup parser
+ */
 
 #include "parse_to.h"
 #include <stdlib.h>
@@ -41,7 +46,7 @@
 
 enum {
 	START_TO, DISPLAY_QUOTED, E_DISPLAY_QUOTED, DISPLAY_TOKEN,
-	S_URI_ENCLOSED, URI_ENCLOSED, E_URI_ENCLOSED,
+	DISPLAY_TOKEN_SP, S_URI_ENCLOSED, URI_ENCLOSED, E_URI_ENCLOSED,
 	URI_OR_TOKEN, MAYBE_URI_END, END, F_CR, F_LF, F_CRLF
 };
 
@@ -532,6 +537,10 @@ char* parse_to(char* buffer, char *end, struct to_body *to_b)
 	to_b->uri.s= 0;
 	to_b->display.len = 0;
 	to_b->display.s = 0;
+	to_b->tag_value.len = 0;
+	to_b->tag_value.s = 0;
+	to_b->param_lst = 0;
+	to_b->last_param = 0;
 	foo=0;
 
 	for( tmp=buffer; tmp<end; tmp++)
@@ -556,6 +565,10 @@ char* parse_to(char* buffer, char *end, struct to_body *to_b)
 						foo = tmp;
 						status = MAYBE_URI_END;
 						break;
+					case DISPLAY_TOKEN:
+						foo = tmp;
+						status = DISPLAY_TOKEN_SP;
+						break;
 				}
 				break;
 			case '\n':
@@ -565,12 +578,17 @@ char* parse_to(char* buffer, char *end, struct to_body *to_b)
 						foo = tmp;
 						status = MAYBE_URI_END;
 					case MAYBE_URI_END:
-					case DISPLAY_TOKEN:
+					case DISPLAY_TOKEN_SP:
 					case E_DISPLAY_QUOTED:
 					case END:
 						saved_status=status;
 						status=F_LF;
 						break;
+					case DISPLAY_TOKEN:
+						foo=tmp;
+						saved_status=DISPLAY_TOKEN_SP;
+						status=F_LF;
+						break;
 					case F_CR:
 						status=F_CRLF;
 						break;
@@ -592,12 +610,17 @@ char* parse_to(char* buffer, char *end, struct to_body *to_b)
 						foo = tmp;
 						status = MAYBE_URI_END;
 					case MAYBE_URI_END:
-					case DISPLAY_TOKEN:
+					case DISPLAY_TOKEN_SP:
 					case E_DISPLAY_QUOTED:
 					case END:
 						saved_status=status;
 						status=F_CR;
 						break;
+					case DISPLAY_TOKEN:
+						foo=tmp;
+						saved_status=DISPLAY_TOKEN_SP;
+						status=F_CR;
+						break;
 					case F_CRLF:
 					case F_CR:
 					case F_LF:
@@ -652,10 +675,13 @@ char* parse_to(char* buffer, char *end, struct to_body *to_b)
 						status = S_URI_ENCLOSED;
 						break;
 					case URI_OR_TOKEN:
-					case DISPLAY_TOKEN: 
+					case DISPLAY_TOKEN:
+						to_b->display.len=tmp-to_b->display.s;
+						status = S_URI_ENCLOSED;
+						break;
+					case DISPLAY_TOKEN_SP:
 					case MAYBE_URI_END:
-						/* deal with the incorrect displayname<uri>.. */
-						to_b->display.len=(foo?foo:tmp)-to_b->display.s;
+						to_b->display.len=foo-to_b->display.s;
 						status = S_URI_ENCLOSED;
 						break;
 					case F_CRLF:
@@ -756,6 +782,7 @@ char* parse_to(char* buffer, char *end, struct to_body *to_b)
 						status=URI_ENCLOSED;
 						break;
 					case MAYBE_URI_END:
+					case DISPLAY_TOKEN_SP:
 						status = DISPLAY_TOKEN;
 					case DISPLAY_QUOTED:
 					case DISPLAY_TOKEN: