![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
sip3funcs.h
Go to the documentation of this file.
00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2006, Digium, Inc. 00005 * and Edvina AB, Sollentuna, Sweden (chan_sip3 changes/additions) 00006 * 00007 * Mark Spencer <markster@digium.com> 00008 * Olle E. Johansson 00009 * 00010 * See http://www.asterisk.org for more information about 00011 * the Asterisk project. Please do not directly contact 00012 * any of the maintainers of this project for assistance; 00013 * the project provides a web site, mailing lists and IRC 00014 * channels for your use. 00015 * 00016 * This program is free software, distributed under the terms of 00017 * the GNU General Public License Version 2. See the LICENSE file 00018 * at the top of the source tree. 00019 */ 00020 00021 /*! 00022 * \file 00023 * \brief Definitions of functions in the sip3 library files used 00024 * by chan_sip3.c 00025 * 00026 * Version 3 of chan_sip 00027 * 00028 * \author Mark Spencer <markster@digium.com> 00029 * \author Olle E. Johansson <oej@edvina.net> (all the chan_sip3 changes) 00030 * 00031 * See Also: 00032 * \arg \ref AstCREDITS 00033 * 00034 */ 00035 00036 #ifndef SIP3_FUNCS 00037 #define SIP3_FUNCS 00038 00039 //#define GNURK extern 00040 #define GNURK 00041 00042 /*! Function declarations */ 00043 00044 /*! Chan_sip3.c */ 00045 /* XXX Should we really expose functions in chan_sip3.c ? */ 00046 /* These needs to be resorted and moved around */ 00047 GNURK void sip_peer_hold(struct sip_dialog *p, int hold); 00048 GNURK int handle_request(struct sip_dialog *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock); 00049 GNURK int sip_do_reload(void); 00050 GNURK int sip_prune_realtime(int fd, int argc, char *argv[]); /* XXX Needs to move to sip3_cliami.c */ 00051 GNURK int sip_notify(int fd, int argc, char *argv[]); /* XXX Move where ?? */ 00052 GNURK int sip_reload(int fd); 00053 GNURK void do_setnat(struct sip_dialog *p, int natflags); 00054 GNURK void __sip_pretend_ack(struct sip_dialog *p); 00055 GNURK int create_addr(struct sip_dialog *dialog, const char *username, char *domain, const char *device); 00056 GNURK struct sip_dialog *get_sip_dialog_byid_locked(const char *callid, const char *totag, const char *fromtag); 00057 GNURK void ast_quiet_chan(struct ast_channel *chan); 00058 GNURK void free_old_route(struct sip_route *route); 00059 GNURK int update_call_counter(struct sip_dialog *fup, int event); 00060 GNURK int sip_reload_check(void); 00061 GNURK int sip_send_mwi_to_peer(struct sip_device *peer); 00062 GNURK int add_t38_sdp(struct sip_request *resp, struct sip_dialog *p); 00063 GNURK void try_suggested_sip_codec(struct sip_dialog *p); 00064 00065 /*! sip3_transmit.c */ 00066 GNURK int __transmit_response(struct sip_dialog *p, const char *msg, struct sip_request *req, enum xmittype reliable); 00067 GNURK int transmit_reinvite_with_sdp(struct sip_dialog *p, int t38version); 00068 GNURK int transmit_response(struct sip_dialog *p, const char *msg, struct sip_request *req); 00069 GNURK int transmit_response_with_auth(struct sip_dialog *p, const char *msg, struct sip_request *req, const char *rand, enum xmittype reliable, const char *header, int stale); 00070 GNURK int transmit_invite(struct sip_dialog *p, int sipmethod, int sdp, int init); 00071 GNURK int transmit_request_with_auth(struct sip_dialog *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch); 00072 00073 GNURK int transmit_sip_request(struct sip_dialog *p, struct sip_request *req); 00074 GNURK int transmit_request(struct sip_dialog *p, int sipmethod, int inc, enum xmittype reliable, int newbranch); 00075 GNURK int transmit_response_reliable(struct sip_dialog *p, const char *msg, struct sip_request *req); 00076 GNURK int transmit_response_with_attachment(enum responseattach attach, struct sip_dialog *p, const char *msg, 00077 struct sip_request *req, enum xmittype reliable); 00078 GNURK int transmit_response_with_unsupported(struct sip_dialog *p, const char *msg, struct sip_request *req, const char *unsupported); 00079 GNURK void transmit_fake_auth_response(struct sip_dialog *p, struct sip_request *req, int reliable); 00080 GNURK int transmit_info_with_digit(struct sip_dialog *p, const char digit, unsigned int duration); 00081 GNURK int transmit_info_with_vidupdate(struct sip_dialog *p); 00082 GNURK int transmit_message_with_text(struct sip_dialog *p, const char *text); 00083 GNURK int transmit_refer(struct sip_dialog *p, const char *dest); 00084 GNURK int transmit_notify_with_mwi(struct sip_dialog *p, int newmsgs, int oldmsgs, char *vmexten); 00085 00086 /*! sip3_objects.c */ 00087 GNURK struct sip_device *find_device(const char *peer, struct sockaddr_in *sin, int realtime); 00088 GNURK void sip_destroy_device(struct sip_device *peer); 00089 GNURK void realtime_update_peer(const char *peername, struct sockaddr_in *sin, const char *username, const char *fullcontact, int expiry); 00090 GNURK void register_peer_exten(struct sip_device *device, int onoff); 00091 GNURK void update_peer(struct sip_device *device, int expiry); 00092 GNURK struct sip_device *temp_device(const char *name); 00093 GNURK void reg_source_db(struct sip_device *peer); 00094 GNURK void destroy_association(struct sip_device *peer); 00095 GNURK int expire_register(void *data); 00096 00097 /*! sip3_refer.c */ 00098 GNURK const char *referstatus2str(enum referstatus rstatus) attribute_pure; 00099 GNURK int handle_request_refer(struct sip_dialog *p, struct sip_request *req, int debug, int seqno, int *nounlock); 00100 GNURK int sip_refer_allocate(struct sip_dialog *p); 00101 GNURK int transmit_notify_with_sipfrag(struct sip_dialog *p, int cseq, char *message, int terminate); 00102 00103 /*! sip3_subscribe.c */ 00104 GNURK const char *subscription_type2str(enum subscriptiontype subtype) attribute_pure; 00105 GNURK const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype); 00106 GNURK int transmit_state_notify(struct sip_dialog *p, int state, int full, int timeout); 00107 00108 /*! sip3_network.c */ 00109 GNURK struct sip_request *siprequest_alloc(size_t len, struct sip_network *sipnet); 00110 GNURK void siprequest_free(struct sip_request *req); 00111 GNURK int close_sip_sockets(void); 00112 GNURK void reset_ip_interface(struct sip_network *sipsock); 00113 GNURK int sipsock_init(struct sip_network *sipsock, struct sockaddr_in *old_bindappr); 00114 //GNURK int sipsock_read(struct sip_network *sipnet, int *id, int fd, short events, void *ignore); 00115 GNURK int sipsock_read(int *id, int fd, short events, void *ignore); 00116 GNURK int sipnet_ourport(struct sip_network *sipnet); /*!< Get current port number */ 00117 GNURK void sipnet_ourport_set(struct sip_network *sipnet, int port); /*!< Set our port number */ 00118 GNURK void sipnet_lock(struct sip_network *sipnet); /*!< Lock netlock mutex */ 00119 GNURK void sipnet_unlock(struct sip_network *sipnet); /*!< Unlock netlock mutex */ 00120 GNURK int sipsocket_open(struct sip_network *sipnet); /* Open network socket for SIP */ 00121 GNURK int sipsocket_initialized(struct sip_network *sipnet); /* Check if we have network socket open */ 00122 /* XXX these (including retrans_pkt) may not belong here in the future, 00123 they involve the transaction states and need to handle various transports (UDP, TCP) */ 00124 GNURK int send_response(struct sip_dialog *p, struct sip_request *req, enum xmittype reliable); 00125 GNURK int send_request(struct sip_dialog *p, struct sip_request *req, enum xmittype reliable); 00126 GNURK const struct sockaddr_in *sip_real_dst(const struct sip_dialog *p); 00127 GNURK inline int sip_debug_test_pvt(struct sip_dialog *p); 00128 GNURK inline int sip_debug_test_addr(const struct sockaddr_in *addr); 00129 GNURK int sip_ouraddrfor(struct in_addr *them, struct in_addr *us); 00130 00131 /*! sip3_parse.c */ 00132 GNURK int lws2sws(char *msgbuf, int len); 00133 GNURK char *sip_method2txt(int method); 00134 GNURK int sip_method_needrtp(int method); 00135 GNURK int method_match(enum sipmethod id, const char *name); 00136 GNURK int find_sip_method(const char *msg); 00137 GNURK int sip_option_lookup(const char *optionlabel); 00138 GNURK unsigned int parse_sip_options(struct sip_dialog *pvt, const char *supported); 00139 GNURK char *sip_option2text(int option); 00140 GNURK void sip_options_print(int options, int fd); 00141 GNURK const char *find_alias(const char *name, const char *_default); 00142 GNURK void copy_request(struct sip_request *dst, const struct sip_request *src); 00143 GNURK int copy_header(struct sip_request *req, struct sip_request *orig, const char *field); 00144 GNURK int copy_all_header(struct sip_request *req, struct sip_request *orig, const char *field); 00145 GNURK int copy_via_headers(struct sip_dialog *p, struct sip_request *req, struct sip_request *orig, const char *field); 00146 GNURK const char *get_header(struct sip_request *req, const char *name); 00147 GNURK const char *__get_header(struct sip_request *req, const char *name, int *start); 00148 GNURK char *get_in_brackets(char *tmp); 00149 GNURK char *generate_random_string(char *buf, size_t size); 00150 GNURK const char *gettag(const char *header, char *tagbuf, int tagbufsize); 00151 GNURK int determine_firstline_parts(struct sip_request *req); 00152 GNURK void extract_uri(struct sip_dialog *p, struct sip_request *req); 00153 GNURK void parse_moved_contact(struct sip_dialog *p, struct sip_request *req); 00154 GNURK int get_rdnis(struct sip_dialog *p, struct sip_request *oreq); 00155 GNURK int get_destination(struct sip_dialog *p, struct sip_request *oreq); 00156 GNURK void parse_request(struct sip_request *req); 00157 00158 /*! sip3_compose.c : Composing new SIP messages */ 00159 GNURK int add_header(struct sip_request *req, const char *var, const char *value); 00160 GNURK void add_blank(struct sip_request *req); 00161 GNURK int init_req(struct sip_request *req, int sipmethod, const char *recip); 00162 GNURK int init_resp(struct sip_request *resp, const char *msg); 00163 GNURK void build_callid_pvt(struct sip_dialog *pvt); 00164 GNURK void append_maxforwards(struct sip_request *req); 00165 GNURK void append_date(struct sip_request *req); 00166 GNURK int add_text(struct sip_request *req, const char *text); 00167 GNURK int add_digit(struct sip_request *req, char digit, unsigned int duration); 00168 GNURK int respprep(struct sip_request *resp, struct sip_dialog *p, const char *msg, struct sip_request *req); 00169 GNURK void add_route(struct sip_request *req, struct sip_route *route); 00170 GNURK int add_line(struct sip_request *req, const char *line); 00171 GNURK int add_header_contentLength(struct sip_request *req, int len); 00172 GNURK void initreqprep(struct sip_request *req, struct sip_dialog *p, int sipmethod); 00173 GNURK int reqprep(struct sip_request *req, struct sip_dialog *p, int sipmethod, int seqno, int newbranch); 00174 GNURK void build_contact(struct sip_dialog *p); 00175 GNURK void build_rpid(struct sip_dialog *p); 00176 00177 /*! sip3_domain.c: Domain handling functions (sip domain hosting, not DNS lookups) */ 00178 GNURK int add_sip_domain(const char *domain, const enum domain_mode mode, const char *context); 00179 GNURK int domains_configured(void); 00180 GNURK int check_sip_domain(const char *domain, char *context, size_t len); 00181 GNURK void clear_sip_domains(void); 00182 GNURK int func_check_sipdomain(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len); 00183 GNURK struct ast_custom_function checksipdomain_function; /* Definition of function */ 00184 GNURK const char *domain_mode_to_text(const enum domain_mode mode); 00185 GNURK int sip_show_domains(int fd, int argc, char *argv[]); /* CLI Function */ 00186 00187 /*! sip3_auth.c */ 00188 GNURK void auth_headers(enum sip_auth_type code, char **header, char **respheader); 00189 GNURK enum check_auth_result check_auth(struct sip_dialog *p, struct sip_request *req, const char *username, 00190 const char *secret, const char *md5secret, int sipmethod, 00191 char *uri, enum xmittype reliable, int ignore); 00192 GNURK int do_register_auth(struct sip_dialog *p, struct sip_request *req, enum sip_auth_type code); 00193 GNURK int do_proxy_auth(struct sip_dialog *p, struct sip_request *req, enum sip_auth_type code, int sipmethod, int init); 00194 GNURK int reply_digest(struct sip_dialog *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len); 00195 GNURK int build_reply_digest(struct sip_dialog *p, int method, char* digest, int digest_len); 00196 GNURK int clear_realm_authentication(struct sip_auth *authlist); /* Clear realm authentication list (at reload) */ 00197 GNURK struct sip_auth *find_realm_authentication(struct sip_auth *authlist, const char *realm); 00198 GNURK struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno); 00199 00200 /* sip3_sdprtp.c */ 00201 GNURK struct ast_frame *sip_read(struct ast_channel *ast); 00202 GNURK void register_rtp_and_udptl(void); 00203 GNURK void unregister_rtp_and_udptl(void); 00204 GNURK char *get_body(struct sip_request *req, char *name); 00205 GNURK int process_sdp(struct sip_dialog *p, struct sip_request *req); 00206 GNURK int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active); 00207 GNURK enum ast_rtp_get_result sip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp); 00208 GNURK enum ast_rtp_get_result sip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp); 00209 GNURK char *get_body(struct sip_request *req, char *name); 00210 GNURK int find_sdp(struct sip_request *req); 00211 GNURK int add_sdp(struct sip_request *resp, struct sip_dialog *p); 00212 GNURK struct ast_frame *sip_read(struct ast_channel *ast); 00213 GNURK void stop_media_flows(struct sip_dialog *dialog); 00214 00215 /* sip3_config.c */ 00216 GNURK void set_device_defaults(struct sip_device *device); 00217 GNURK struct sip_device *realtime_peer(const char *newpeername, struct sockaddr_in *sin); 00218 GNURK int reload_config(enum channelreloadreason reason); 00219 GNURK int sip_listconfigs(int fd); 00220 GNURK void device_unref(struct sip_device *device); 00221 GNURK struct sip_device *device_ref(struct sip_device *device); 00222 00223 /* sip3_callerid.c */ 00224 GNURK int get_rpid_num(const char *input, char *output, int maxlen); 00225 GNURK char *get_calleridname(const char *input, char *output, size_t outputsize); 00226 GNURK void replace_cid(struct sip_dialog *p, const char *rpid_num, const char *calleridname); 00227 00228 /* sip3_cliami.c */ 00229 GNURK const char *sip_nat_mode(const struct sip_dialog *p); 00230 GNURK void print_group(int fd, ast_group_t group, int crlf); 00231 GNURK int device_status(struct sip_device *peer, char *status, int statuslen); 00232 GNURK int manager_sip_show_device(struct mansession *s, const struct message *m ); 00233 GNURK int manager_sip_show_devices(struct mansession *s, const struct message *m); 00234 GNURK void sip_cli_and_manager_commands_register(void); 00235 GNURK void sip_cli_and_manager_commands_unregister(void); 00236 GNURK char *complete_sip_device(const char *word, int state, int flags2); 00237 GNURK char *complete_sip_show_device(const char *line, const char *word, int pos, int state); 00238 00239 00240 /* sip3_dialog.c */ 00241 GNURK void set_initreq(struct sip_dialog *dialog, struct sip_request *req); 00242 GNURK void find_via_branch(struct sip_request *req, char *viabuf, size_t vialen); 00243 GNURK void dialoglist_lock(void); 00244 GNURK void dialoglist_unlock(void); 00245 GNURK const char *dialogstate2str(const enum dialogstate state); 00246 GNURK void dialogstatechange(struct sip_dialog *dialog, enum dialogstate newstate); 00247 GNURK void sip_scheddestroy(struct sip_dialog *p, int ms); 00248 GNURK void sip_cancel_destroy(struct sip_dialog *p); 00249 GNURK int hangup_sip2cause(int cause); 00250 GNURK const char *hangup_cause2sip(int cause); 00251 GNURK struct sip_dialog *sip_alloc(ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method); 00252 GNURK void make_our_tag(char *tagbuf, size_t len); 00253 GNURK struct sip_dialog *match_or_create_dialog(struct sip_request *req, struct sockaddr_in *sin, const int intended_method); 00254 GNURK void sip_destroy(struct sip_dialog *p); 00255 GNURK void __sip_destroy(struct sip_dialog *p, int lockowner, int lockdialoglist); 00256 GNURK void __sip_ack(struct sip_dialog *dialog, int seqno, int resp, int sipmethod, int reset); 00257 GNURK int __sip_semi_ack(struct sip_dialog *p, int seqno, int resp, int sipmethod); 00258 GNURK void dialog_lock(struct sip_dialog *dialog, int state); 00259 GNURK int transmit_final_response(struct sip_dialog *dialog, const char *msg, struct sip_request *req, enum xmittype reliable); 00260 GNURK void initialize_initreq(struct sip_dialog *p, struct sip_request *req); 00261 GNURK void build_via(struct sip_dialog *p, int forcenewbranch); 00262 00263 00264 /* sip3_services.c - outbound registration for services from other servers/providers */ 00265 00266 GNURK void sip_send_all_registers(void); 00267 GNURK int sip_register(char *value, int lineno, struct sip_device *peer); 00268 GNURK void sip_registry_destroy(struct sip_registry *reg); 00269 GNURK char *regstate2str(enum sipregistrystate regstate) attribute_const; 00270 GNURK int handle_response_register(struct sip_dialog *p, int resp, char *rest, struct sip_request *req, int seqno); 00271 GNURK int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader); 00272 00273 /* sip3_utils.c - various utility functions */ 00274 GNURK void logdebug(int level, const char *fmt, ...); 00275 GNURK void append_history_full(struct sip_dialog *p, const char *fmt, ...); 00276 GNURK void append_history_va(struct sip_dialog *p, const char *fmt, va_list ap); 00277 GNURK void sip_dump_history(struct sip_dialog *dialog); /* Dump history to LOG_DEBUG at end of dialog, before destroying data */ 00278 00279 /* sip3_pokedevice.c - poking peers (qualify) */ 00280 int sip_poke_noanswer(void *data); 00281 int sip_poke_peer(struct sip_device *peer); 00282 void sip_poke_all_peers(void); 00283 int sip_poke_peer_s(void *data); 00284 int sip_poke_peer(struct sip_device *peer); 00285 void handle_response_peerpoke(struct sip_dialog *p, int resp, struct sip_request *req); 00286 00287 /* sip3_monitor.c - the monitor thread */ 00288 void *do_sip_monitor(void *data); 00289 void kill_monitor(void); 00290 int restart_monitor(void); 00291 00292 #endif