/*! \brief * Send a reply */ int send_reply(struct sip_msg* _m, unsigned int _flags) { str unsup = str_init(SUPPORTED_PATH_STR); long code; str msg = str_init(MSG_200); /* makes gcc shut up */ char* buf; if (contact.data_len > 0) { add_lump_rpl( _m, contact.buf, contact.data_len, LUMP_RPL_HDR|LUMP_RPL_NODUP|LUMP_RPL_NOFREE); contact.data_len = 0; } if (rerrno == R_FINE && (_flags®_SAVE_PATH_FLAG) && _m->path_vec.s) { if ( (_flags®_SAVE_PATH_OFF_FLAG)==0 ) { if (parse_supported(_m)<0 && (_flags®_SAVE_PATH_STRICT_FLAG)) { rerrno = R_PATH_UNSUP; if (add_unsupported(_m, &unsup) < 0) return -1; if (add_path(_m, &_m->path_vec) < 0) return -1; } else if (get_supported(_m) & F_SUPPORTED_PATH) { if (add_path(_m, &_m->path_vec) < 0) return -1; } else if ((_flags®_SAVE_PATH_STRICT_FLAG)) { rerrno = R_PATH_UNSUP; if (add_unsupported(_m, &unsup) < 0) return -1; if (add_path(_m, &_m->path_vec) < 0) return -1; } } } code = codes[rerrno]; switch(code) { case 200: msg.s = MSG_200; msg.len = sizeof(MSG_200)-1; break; case 400: msg.s = MSG_400; msg.len = sizeof(MSG_400)-1;break; case 420: msg.s = MSG_420; msg.len = sizeof(MSG_420)-1;break; case 500: msg.s = MSG_500; msg.len = sizeof(MSG_500)-1;break; case 503: msg.s = MSG_503; msg.len = sizeof(MSG_503)-1;break; } if (code != 200) { buf = (char*)pkg_malloc(E_INFO_LEN + error_info[rerrno].len + CRLF_LEN + 1); if (!buf) { LM_ERR("no pkg memory left\n"); return -1; } memcpy(buf, E_INFO, E_INFO_LEN); memcpy(buf + E_INFO_LEN, error_info[rerrno].s, error_info[rerrno].len); memcpy(buf + E_INFO_LEN + error_info[rerrno].len, CRLF, CRLF_LEN); add_lump_rpl( _m, buf, E_INFO_LEN + error_info[rerrno].len + CRLF_LEN, LUMP_RPL_HDR|LUMP_RPL_NODUP); if (code >= 500 && code < 600 && retry_after) { if (add_retry_after(_m) < 0) { return -1; } } } if (sigb.reply(_m, code, &msg, NULL) == -1) { LM_ERR("failed to send %ld %.*s\n", code, msg.len,msg.s); return -1; } else return 0; }
/*! \brief * Send a reply */ int reg_send_reply(struct sip_msg* _m, contact_for_header_t* contact_header) { str unsup = str_init(OPTION_TAG_PATH_STR); long code; str msg = str_init(MSG_200); /* makes gcc shut up */ char* buf; if (contact_header && contact_header->buf && contact_header->data_len > 0) { LM_DBG("Contacts: %.*s\n", contact_header->data_len, contact_header->buf); add_lump_rpl(_m, contact_header->buf, contact_header->data_len, LUMP_RPL_HDR | LUMP_RPL_NODUP | LUMP_RPL_NOFREE); contact_header->data_len = 0; } if (rerrno == R_FINE && path_enabled && _m->path_vec.s) { if (path_mode != PATH_MODE_OFF) { if (parse_supported(_m) < 0 && path_mode == PATH_MODE_STRICT) { rerrno = R_PATH_UNSUP; if (add_unsupported(_m, &unsup) < 0) return -1; if (add_path(_m, &_m->path_vec) < 0) return -1; } else if (get_supported(_m) & F_OPTION_TAG_PATH) { if (add_path(_m, &_m->path_vec) < 0) return -1; } else if (path_mode == PATH_MODE_STRICT) { rerrno = R_PATH_UNSUP; if (add_unsupported(_m, &unsup) < 0) return -1; if (add_path(_m, &_m->path_vec) < 0) return -1; } } } code = codes[rerrno]; switch (code) { case 200: msg.s = MSG_200; msg.len = sizeof (MSG_200) - 1; break; case 400: msg.s = MSG_400; msg.len = sizeof (MSG_400) - 1; break; case 420: msg.s = MSG_420; msg.len = sizeof (MSG_420) - 1; break; case 500: msg.s = MSG_500; msg.len = sizeof (MSG_500) - 1; break; case 503: msg.s = MSG_503; msg.len = sizeof (MSG_503) - 1; break; } if (code != 200) { buf = (char*) pkg_malloc(E_INFO_LEN + error_info[rerrno].len + CRLF_LEN + 1); if (!buf) { LM_ERR("no pkg memory left\n"); return -1; } memcpy(buf, E_INFO, E_INFO_LEN); memcpy(buf + E_INFO_LEN, error_info[rerrno].s, error_info[rerrno].len); memcpy(buf + E_INFO_LEN + error_info[rerrno].len, CRLF, CRLF_LEN); add_lump_rpl(_m, buf, E_INFO_LEN + error_info[rerrno].len + CRLF_LEN, LUMP_RPL_HDR | LUMP_RPL_NODUP); if (code >= 500 && code < 600 && cfg_get(registrar, registrar_cfg, retry_after)) { if (add_retry_after(_m) < 0) { return -1; } } } if ((code > 199) && (code < 299)) { if (p_associated_uri.data_len > 0) { add_lump_rpl(_m, p_associated_uri.buf, p_associated_uri.data_len, LUMP_RPL_HDR | LUMP_RPL_NODUP | LUMP_RPL_NOFREE); p_associated_uri.data_len = 0; } if (add_service_route(_m, &scscf_serviceroute_uri_str) < 0) { //TODO - need to insert orig into this scscf_name return -1; } } if (slb.freply(_m, code, &msg) < 0) { LM_ERR("failed to send %ld %.*s\n", code, msg.len, msg.s); return -1; } else return 0; }