@@ -923,33 +923,114 @@ char * call::get_last_header(const char * name)
923923 if (name[len - 1 ] == ' :' ) {
924924 return get_header (last_recv_msg, name, false );
925925 } else {
926+
926927 char with_colon[MAX_HEADER_LEN];
927- sprintf (with_colon, " %s:" , name);
928- return get_header (last_recv_msg, with_colon, false );
928+ const char *sep = strrchr (name, ' :' );
929+
930+ if (!sep){
931+ sprintf (with_colon, " %s:" , name);
932+ return get_header (last_recv_msg, with_colon, false );
933+ } else {
934+ if (!strcmp (sep, " :value" )) {
935+ snprintf (with_colon, len - 4 , " %s" , name);
936+ return get_header (last_recv_msg, with_colon, true );
937+ }
938+ if (!strcmp (sep, " :uri" )) {
939+ snprintf (with_colon, len - 2 , " %s" , name);
940+ char * last_header_uri = get_last_request_uri (with_colon);
941+ char * ret;
942+ if (!(ret = (char *)malloc (strlen (last_header_uri + 1 )))){
943+ ERROR (" call::get_last_header: Cannot allocate uri !\n " );
944+ }
945+ sprintf (ret, " %s" , last_header_uri);
946+ free (last_header_uri);
947+ return ret;
948+ }
949+ if (!strcmp (sep, " :param.tag" )) {
950+ snprintf (with_colon, len - 8 , " %s" , name);
951+ char * last_tag = get_last_tag (with_colon);
952+ char * ret;
953+ if (!(ret = (char *)malloc (strlen (last_tag + 1 )))){
954+ ERROR (" call::get_last_header: Cannot allocate param.tag !\n " );
955+ }
956+ sprintf (ret, " %s" , last_tag);
957+ free (last_tag);
958+ return ret;
959+ }
960+ ERROR (" Token %s not valid in %s" , sep, name);
961+ }
929962 }
930963}
931964
932- /* Return the last request URI from the To header. On any error returns the
965+ /* Return the last tag from the header line . On any error returns the
933966 * empty string. The caller must free the result. */
934- char * call::get_last_request_uri ( )
967+ char * call::get_last_tag ( const char *name )
935968{
936969 char * tmp;
937970 char * tmp2;
938- char * last_request_uri;
971+ char * result;
972+ char * last_To;
939973 int tmp_len;
940974
941- char * last_To = get_last_header (" To:" );
975+ if (!name || !strlen (name)) {
976+ return strdup (" " );
977+ }
978+
979+ last_To = get_last_header (name);
942980 if (!last_To) {
943981 return strdup (" " );
944982 }
945983
946- tmp = strchr (last_To, ' <' );
984+ tmp = strcasestr (last_To, " tag=" );
985+ if (!tmp) {
986+ return strdup (" " );
987+ }
988+
989+ tmp += strlen (" tag=" );
990+ tmp2 = tmp;
991+
992+ while (*tmp2 && *tmp2 != ' ;' && *tmp2!=' \r ' && *tmp2!=' \n ' ) tmp2++;
993+
994+ tmp_len = strlen (tmp) - strlen (tmp2);
995+ if (tmp_len < 0 ) {
996+ return strdup (" " );
997+ }
998+ if (!(result = (char *) malloc (tmp_len+1 ))) ERROR (" call::get_last_tag: Cannot allocate !\n " );
999+ memset (result, 0 , sizeof (&result));
1000+ if (tmp && (tmp_len > 0 )){
1001+ strncpy (result, tmp, tmp_len);
1002+ }
1003+ result[tmp_len] = ' \0 ' ;
1004+ return result;
1005+ }
1006+
1007+ /* Return the last request URI from the header. On any error returns the
1008+ * empty string. The caller must free the result. */
1009+ char * call::get_last_request_uri (const char *name)
1010+ {
1011+ char * tmp;
1012+ char * tmp2;
1013+ char * last_request_uri;
1014+ char * last_header;
1015+ int tmp_len;
1016+
1017+ if (!name || !strlen (name)) {
1018+ return strdup (" " );
1019+ }
1020+
1021+ last_header = get_last_header (name);
1022+
1023+ if (!last_header) {
1024+ return strdup (" " );
1025+ }
1026+
1027+ tmp = strchr (last_header, ' <' );
9471028 if (!tmp) {
9481029 return strdup (" " );
9491030 }
9501031 tmp++;
9511032
952- tmp2 = strchr (last_To , ' >' );
1033+ tmp2 = strchr (last_header , ' >' );
9531034 if (!tmp2) {
9541035 return strdup (" " );
9551036 }
@@ -2201,7 +2282,7 @@ char* call::createSendingMessage(SendingMessage *src, int P_index, char *msg_buf
22012282 }
22022283 break ;
22032284 case E_Message_Last_Request_URI: {
2204- char * last_request_uri = get_last_request_uri ();
2285+ char * last_request_uri = get_last_request_uri (" To: " );
22052286 dest += sprintf (dest, " %s" , last_request_uri);
22062287 free (last_request_uri);
22072288 break ;
0 commit comments