options.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifdef EXTRA_DEBUG
00041 #include <stdlib.h>
00042 #endif
00043 #include "options.h"
00044 #include "../../ut.h"
00045 #include "../../mem/mem.h"
00046 #include "../../data_lump_rpl.h"
00047 #include "../../parser/parse_uri.h"
00048
00049 static str opt_200_rpl = str_init("OK");
00050 static str opt_500_rpl = str_init("Server internal error");
00051
00052
00053 int opt_reply(struct sip_msg* _msg, char* _foo, char* _bar) {
00054 str rpl_hf;
00055 int offset = 0;
00056
00057
00058 if (_msg->REQ_METHOD!=METHOD_OPTIONS) {
00059 LM_ERR("called for non-OPTIONS request\n");
00060 return -1;
00061 }
00062 if(_msg->parsed_uri_ok==0 && parse_sip_msg_uri(_msg)<0)
00063 {
00064 LM_ERR("ERROR while parsing the R-URI\n");
00065 return -1;
00066 }
00067
00068 if (_msg->parsed_uri.user.len != 0) {
00069 LM_ERR("ruri contains username\n");
00070 return -1;
00071 }
00072
00073
00074 rpl_hf.len = ACPT_STR_LEN + ACPT_ENC_STR_LEN + ACPT_LAN_STR_LEN +
00075 SUPT_STR_LEN + 4*HF_SEP_STR_LEN + opt_accept.len + opt_accept_enc.len
00076 + opt_accept_lang.len + opt_supported.len;
00077 rpl_hf.s = (char*)pkg_malloc(rpl_hf.len);
00078 if (!rpl_hf.s) {
00079 LM_CRIT("out of pkg memory\n");
00080 goto error;
00081 }
00082
00083
00084 memcpy(rpl_hf.s, ACPT_STR, ACPT_STR_LEN);
00085 offset = ACPT_STR_LEN;
00086 memcpy(rpl_hf.s + offset, opt_accept.s, opt_accept.len);
00087 offset += opt_accept.len;
00088 memcpy(rpl_hf.s + offset, HF_SEP_STR, HF_SEP_STR_LEN);
00089 offset += HF_SEP_STR_LEN;
00090 memcpy(rpl_hf.s + offset, ACPT_ENC_STR, ACPT_ENC_STR_LEN);
00091 offset += ACPT_ENC_STR_LEN;
00092 memcpy(rpl_hf.s + offset, opt_accept_enc.s, opt_accept_enc.len);
00093 offset += opt_accept_enc.len;
00094 memcpy(rpl_hf.s + offset, HF_SEP_STR, HF_SEP_STR_LEN);
00095 offset += HF_SEP_STR_LEN;
00096 memcpy(rpl_hf.s + offset, ACPT_LAN_STR, ACPT_LAN_STR_LEN);
00097 offset += ACPT_LAN_STR_LEN;
00098 memcpy(rpl_hf.s + offset, opt_accept_lang.s, opt_accept_lang.len);
00099 offset += opt_accept_lang.len;
00100 memcpy(rpl_hf.s + offset, HF_SEP_STR, HF_SEP_STR_LEN);
00101 offset += HF_SEP_STR_LEN;
00102 memcpy(rpl_hf.s + offset, SUPT_STR, SUPT_STR_LEN);
00103 offset += SUPT_STR_LEN;
00104 memcpy(rpl_hf.s + offset, opt_supported.s, opt_supported.len);
00105 offset += opt_supported.len;
00106 memcpy(rpl_hf.s + offset, HF_SEP_STR, HF_SEP_STR_LEN);
00107
00108 #ifdef EXTRA_DEBUG
00109 offset += HF_SEP_STR_LEN;
00110 if (offset != rpl_hf.len) {
00111 LM_CRIT("headerlength (%i) != offset (%i)\n", rpl_hf.len, offset);
00112 abort();
00113 }
00114 #endif
00115
00116
00117 if (add_lump_rpl( _msg, rpl_hf.s, rpl_hf.len,
00118 LUMP_RPL_HDR|LUMP_RPL_NODUP)!=0) {
00119 if (opt_slb.send_reply(_msg, 200, &opt_200_rpl) == -1) {
00120 LM_ERR("failed to send 200 via send_reply\n");
00121 return -1;
00122 }
00123 else
00124 return 0;
00125 } else {
00126 pkg_free(rpl_hf.s);
00127 LM_ERR("add_lump_rpl failed\n");
00128 }
00129
00130 error:
00131 if (opt_slb.send_reply(_msg, 500, &opt_500_rpl) == -1) {
00132 LM_ERR("failed to send 500 via send_reply\n");
00133 return -1;
00134 }
00135 else
00136 return 0;
00137 }
00138