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

Function construct_uri

msg_translator.c:2905–2975  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2903#define MAX_URI_LEN 1024
2904static char uri_buff[MAX_URI_LEN];
2905char *construct_uri(str *protocol,str *username,str *domain,str *port,
2906 str *params,int *len)
2907{
2908 int pos = 0;
2909 int total_len;
2910
2911 if (!len)
2912 {
2913 LM_ERR("null pointer provided for construct_uri \n");
2914 return 0;
2915 }
2916
2917 if (!protocol->s || protocol->len == 0)
2918 {
2919 LM_ERR("no protocol specified\n");
2920 return 0;
2921 }
2922
2923 if (!domain->s || domain->len == 0)
2924 {
2925 LM_ERR("no domain specified\n");
2926 return 0;
2927 }
2928
2929 total_len = protocol->len + 1 /* ':' */ + domain->len;
2930 if (username && username->s && username->len != 0)
2931 total_len += username->len + 1; /* '@' */
2932 if (port && port->s && port->len != 0)
2933 total_len += port->len + 1; /* ':' */
2934 if (params && params->s && params->len != 0)
2935 total_len += params->len + 1; /* ';' */
2936 total_len += 1; /* null terminator */
2937
2938 if (total_len > MAX_URI_LEN) {
2939 LM_ERR("constructed URI too long (%d > %d)\n",
2940 total_len, MAX_URI_LEN);
2941 return 0;
2942 }
2943
2944 memcpy(uri_buff,protocol->s,protocol->len);
2945 pos += protocol->len;
2946 uri_buff[pos++] = ':';
2947
2948 if (username && username->s && username->len != 0)
2949 {
2950 memcpy(uri_buff+pos,username->s,username->len);
2951 pos += username->len;
2952 uri_buff[pos++] = '@';
2953 }
2954
2955 memcpy(uri_buff+pos,domain->s,domain->len);
2956 pos += domain->len;
2957
2958 if (port && port->s && port->len !=0)
2959 {
2960 uri_buff[pos++] = ':';
2961 memcpy(uri_buff+pos,port->s,port->len);
2962 pos += port->len;

Callers 1

w_construct_uriFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected