Hello,

I was using textops module and had discovered that pudo-variables are not extended in textops module. So constriction like this is not working

append_hf("Remote-Party-ID: <sip:$avp(s:xxx)@ $fd>;party=calling;screen=yes;privacy=off\r\n");

I thought it would be good if textops would extend pseudo-variables.
And here is a small patch for that.
Right now it is only changes append_hf, if there is an interest I can add pseudo-variables support for the rest of the functions in textops module.

Boris./

*** textops.c.orig      Tue Nov 22 20:09:35 2005
--- textops.c   Wed Nov 23 18:03:38 2005
***************
*** 94,104 ****
  static int replace_all_f(struct sip_msg* msg, char* key, char* str);
  static int search_append_f(struct sip_msg*, char*, char*);
static int append_to_reply_f(struct sip_msg* msg, char* key, char* str);
! static int append_hf(struct sip_msg* msg, char* str1, char* str2);
  static int append_urihf(struct sip_msg* msg, char* str1, char* str2);
  static int append_time_f(struct sip_msg* msg, char* , char *);
  static int is_method_f(struct sip_msg* msg, char* , char *);

  static int fixup_regex(void**, int);
  static int fixup_substre(void**, int);
  static int str_fixup(void** param, int param_no);
--- 94,105 ----
  static int replace_all_f(struct sip_msg* msg, char* key, char* str);
  static int search_append_f(struct sip_msg*, char*, char*);
static int append_to_reply_f(struct sip_msg* msg, char* key, char* str);
! static int append_hf(struct sip_msg *msg, xl_elem_t *format );
  static int append_urihf(struct sip_msg* msg, char* str1, char* str2);
  static int append_time_f(struct sip_msg* msg, char* , char *);
  static int is_method_f(struct sip_msg* msg, char* , char *);

+ static int avp_fixup(void**, int);
  static int fixup_regex(void**, int);
  static int fixup_substre(void**, int);
  static int str_fixup(void** param, int param_no);
***************
*** 119,125 ****
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE| BRANCH_ROUTE},
        {"append_to_reply",  append_to_reply_f, 1, 0,
                        REQUEST_ROUTE|BRANCH_ROUTE},
!       {"append_hf",        append_hf,         1, str_fixup,
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE| BRANCH_ROUTE},
        {"append_urihf",     append_urihf,      2, str_fixup,
                        REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
--- 120,126 ----
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE| BRANCH_ROUTE},
        {"append_to_reply",  append_to_reply_f, 1, 0,
                        REQUEST_ROUTE|BRANCH_ROUTE},
!       {"append_hf",        append_hf,         1, avp_fixup,
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE| BRANCH_ROUTE},
        {"append_urihf",     append_urihf,      2, str_fixup,
                        REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
***************
*** 623,631 ****
        return 1;
  }

! static int append_hf(struct sip_msg *msg, char *str1, char *str2 )
  {
!       return append_hf_helper(msg, (str *) str1, (str *) 0);
  }

  static int append_urihf(struct sip_msg *msg, char *str1, char *str2 )
--- 624,654 ----
        return 1;
  }

! static int append_hf(struct sip_msg *msg, xl_elem_t *format )
  {
!
!       #define PRINTBUF_SIZE   1024
!       char printbuf[PRINTBUF_SIZE];
!       int printbuf_len;
!       str* s;
!
!       s = (str*)pkg_malloc(sizeof(str));
!       if (!s) {
!               LOG(L_ERR, "str_fixup(): No memory left\n");
!               return E_UNSPEC;
!       }
!
!       printbuf_len = PRINTBUF_SIZE-1;
!       if(xl_printf(msg, format, printbuf, &printbuf_len)<0)
!       {
! LOG(L_ERR, "textops:append_hf: error - cannot print the format\n");
!               return -1;
!       }
!
!       s->s = printbuf;
!       s->len = strlen(s->s);
!
!       return append_hf_helper(msg, (str *) s, (str *) 0);
  }

  static int append_urihf(struct sip_msg *msg, char *str1, char *str2 )
***************
*** 679,684 ****
--- 702,727 ----
        s->len = strlen(s->s);
        *param = (void*)s;

+       return 0;
+ }
+
+ /*
+  * Convert char* parameter to xl_elem parameter
+  */
+ static int avp_fixup(void** param, int param_no)
+ {
+       xl_elem_t *model;
+
+       if(*param)
+       {
+ if(xl_parse_format((char*)(*param), &model, XL_DISABLE_COLORS)<0)
+               {
+ LOG(L_ERR, "ERROR:textops:avp_fixup: wrong format[%s]\n",
+                               (char*)(*param));
+                       return E_UNSPEC;
+               }
+               *param = (void*)model;
+       }
        return 0;
  }

_______________________________________________
Devel mailing list
[email protected]
http://openser.org/cgi-bin/mailman/listinfo/devel

Reply via email to