MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / encode_location_attr

Function encode_location_attr

modules/cpl_c/cpl_parser.c:827–880  ·  view source on GitHub ↗

Attr. encoding for LOCATION node: * | attr1_t(2) attr1_len(2) attr1_val(2*x) | URL attr (NT) * [| attr2_t(2) attr2_val(2) |]? PRIORITY attr * [| attr3_t(2) attr3_val(2) |]? CLEAR attr */

Source from the content-addressed store, hash-verified

825 * [| attr3_t(2) attr3_val(2) |]? CLEAR attr
826 */
827static inline int encode_location_attr(xmlNodePtr node, char *node_ptr,
828 char *buf_end)
829{
830 struct sip_uri uri;
831 xmlAttrPtr attr;
832 char *p, *p_orig;
833 unsigned char *nr_attr;
834 unsigned short nr;
835 str val;
836
837 nr_attr = &(NR_OF_ATTR(node_ptr));
838 *nr_attr = 0;
839 p = p_orig = ATTR_PTR(node_ptr);
840
841 FOR_ALL_ATTR(node,attr) {
842 (*nr_attr)++;
843 /* get attribute's value */
844 get_attr_val( attr->name , val, error);
845 switch(attr->name[0]) {
846 case 'U': case 'u':
847 set_attr_type(p, URL_ATTR, buf_end, error);
848 /* check if it's a valid SIP URL -> just call
849 * parse uri function and see if returns error ;-) */
850 if (parse_uri( val.s, val.len, &uri)!=0) {
851 LM_ERR("<%s> is not a valid SIP URL\n",val.s);
852 goto error;
853 }
854 val.len++; /*copy also the \0 */
855 append_str_attr(p,val, buf_end, error);
856 break;
857 case 'P': case 'p':
858 set_attr_type(p, PRIORITY_ATTR, buf_end, error);
859 if (val.s[0]=='0') nr=0;
860 else if (val.s[0]=='1') nr=10;
861 else goto prio_error;
862 if (val.s[1]!='.') goto prio_error;
863 if (val.s[2]<'0' || val.s[2]>'9') goto prio_error;
864 nr += val.s[2] - '0';
865 if (nr>10)
866 goto prio_error;
867 append_short_attr(p, nr, buf_end, error);
868 break;
869 case 'C': case 'c':
870 set_attr_type(p, CLEAR_ATTR, buf_end, error);
871 if (val.s[0]=='y' || val.s[0]=='Y')
872 append_short_attr(p, YES_VAL, buf_end, error);
873 else
874 append_short_attr(p, NO_VAL, buf_end, error);
875 break;
876 default:
877 LM_ERR("unknown attribute <%s>\n",attr->name);
878 goto error;
879 }
880 }
881
882 return p-p_orig;
883prio_error:

Callers 1

encode_nodeFunction · 0.85

Calls 1

parse_uriFunction · 0.85

Tested by

no test coverage detected