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

Function ospAddOspToken

modules/osp/sipheader.c:1032–1071  ·  view source on GitHub ↗

* Add OSP token header to SIP message * param msg SIP message * param token OSP authorization token * param tokensize Size of OSP authorization token * return 0 success, -1 failure */

Source from the content-addressed store, hash-verified

1030 * return 0 success, -1 failure
1031 */
1032int ospAddOspToken(
1033 struct sip_msg* msg,
1034 unsigned char* token,
1035 unsigned int tokensize)
1036{
1037 str headerval;
1038 char buffer[OSP_HEADERBUF_SIZE];
1039 unsigned char encodedtoken[OSP_TOKENBUF_SIZE];
1040 unsigned int encodedtokensize = sizeof(encodedtoken);
1041 int errorcode, result = -1;
1042
1043 if ((token == NULL) || (tokensize == 0)) {
1044 LM_DBG("destination is not OSP device\n");
1045 result = 0;
1046 } else {
1047 if ((errorcode = OSPPBase64Encode(token, tokensize, encodedtoken, &encodedtokensize)) == OSPC_ERR_NO_ERROR) {
1048 snprintf(buffer,
1049 sizeof(buffer),
1050 "%s: %.*s\r\n",
1051 OSP_TOKENHEADER_NAME,
1052 encodedtokensize,
1053 encodedtoken);
1054
1055 headerval.s = buffer;
1056 headerval.len = strlen(buffer);
1057
1058 LM_DBG("setting osp token header field '%s'\n", buffer);
1059
1060 if (ospAppendHeader(msg, &headerval) == 0) {
1061 result = 0;
1062 } else {
1063 LM_ERR("failed to append osp header\n");
1064 }
1065 } else {
1066 LM_ERR("failed to base64 encode token (%d)\n", errorcode);
1067 }
1068 }
1069
1070 return result;
1071}
1072
1073/*
1074 * Get OSP token from SIP message

Callers 1

ospPrepareDestinationFunction · 0.85

Calls 1

ospAppendHeaderFunction · 0.85

Tested by

no test coverage detected