![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
chan_jingle.c
Go to the documentation of this file.
00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2005, Digium, Inc. 00005 * 00006 * Matt O'Gorman <mogorman@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! \file 00020 * 00021 * \author Matt O'Gorman <mogorman@digium.com> 00022 * 00023 * \brief Jingle Channel Driver 00024 * 00025 * \ingroup channel_drivers 00026 */ 00027 00028 /*** MODULEINFO 00029 <depend>iksemel</depend> 00030 ***/ 00031 00032 #include "asterisk.h" 00033 00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 51385 $") 00035 00036 #include <stdlib.h> 00037 #include <stdio.h> 00038 #include <string.h> 00039 #include <unistd.h> 00040 #include <sys/socket.h> 00041 #include <errno.h> 00042 #include <stdlib.h> 00043 #include <fcntl.h> 00044 #include <netdb.h> 00045 #include <netinet/in.h> 00046 #include <arpa/inet.h> 00047 #include <sys/signal.h> 00048 #include <iksemel.h> 00049 00050 #include "asterisk/lock.h" 00051 #include "asterisk/channel.h" 00052 #include "asterisk/config.h" 00053 #include "asterisk/logger.h" 00054 #include "asterisk/module.h" 00055 #include "asterisk/pbx.h" 00056 #include "asterisk/options.h" 00057 #include "asterisk/lock.h" 00058 #include "asterisk/sched.h" 00059 #include "asterisk/io.h" 00060 #include "asterisk/rtp.h" 00061 #include "asterisk/acl.h" 00062 #include "asterisk/callerid.h" 00063 #include "asterisk/file.h" 00064 #include "asterisk/cli.h" 00065 #include "asterisk/app.h" 00066 #include "asterisk/musiconhold.h" 00067 #include "asterisk/manager.h" 00068 #include "asterisk/stringfields.h" 00069 #include "asterisk/utils.h" 00070 #include "asterisk/causes.h" 00071 #include "asterisk/astobj.h" 00072 #include "asterisk/abstract_jb.h" 00073 #include "asterisk/jabber.h" 00074 #include "asterisk/jingle.h" 00075 00076 #define JINGLE_CONFIG "jingle.conf" 00077 00078 /*! Global jitterbuffer configuration - by default, jb is disabled */ 00079 static struct ast_jb_conf default_jbconf = 00080 { 00081 .flags = 0, 00082 .max_size = -1, 00083 .resync_threshold = -1, 00084 .impl = "" 00085 }; 00086 static struct ast_jb_conf global_jbconf; 00087 00088 enum jingle_protocol { 00089 AJI_PROTOCOL_UDP = 1, 00090 AJI_PROTOCOL_SSLTCP = 2, 00091 }; 00092 00093 enum jingle_connect_type { 00094 AJI_CONNECT_STUN = 1, 00095 AJI_CONNECT_LOCAL = 2, 00096 AJI_CONNECT_RELAY = 3, 00097 }; 00098 00099 struct jingle_pvt { 00100 ast_mutex_t lock; /*!< Channel private lock */ 00101 time_t laststun; 00102 struct jingle *parent; /*!< Parent client */ 00103 char sid[100]; 00104 char from[100]; 00105 char ring[10]; /*!< Message ID of ring */ 00106 iksrule *ringrule; /*!< Rule for matching RING request */ 00107 int initiator; /*!< If we're the initiator */ 00108 int alreadygone; 00109 int capability; 00110 struct ast_codec_pref prefs; 00111 struct jingle_candidate *theircandidates; 00112 struct jingle_candidate *ourcandidates; 00113 char cid_num[80]; /*!< Caller ID num */ 00114 char cid_name[80]; /*!< Caller ID name */ 00115 char exten[80]; /*!< Called extension */ 00116 struct ast_channel *owner; /*!< Master Channel */ 00117 struct ast_rtp *rtp; /*!< RTP audio session */ 00118 struct ast_rtp *vrtp; /*!< RTP video session */ 00119 int jointcapability; /*!< Supported capability at both ends (codecs ) */ 00120 int peercapability; 00121 struct jingle_pvt *next; /* Next entity */ 00122 }; 00123 00124 struct jingle_candidate { 00125 char name[100]; 00126 enum jingle_protocol protocol; 00127 double preference; 00128 char username[100]; 00129 char password[100]; 00130 enum jingle_connect_type type; 00131 char network[6]; 00132 int generation; 00133 char ip[16]; 00134 int port; 00135 int receipt; 00136 struct jingle_candidate *next; 00137 }; 00138 00139 struct jingle { 00140 ASTOBJ_COMPONENTS(struct jingle); 00141 struct aji_client *connection; 00142 struct aji_buddy *buddy; 00143 struct jingle_pvt *p; 00144 struct ast_codec_pref prefs; 00145 int amaflags; /*!< AMA Flags */ 00146 char user[100]; 00147 char context[100]; 00148 char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */ 00149 int capability; 00150 ast_group_t callgroup; /*!< Call group */ 00151 ast_group_t pickupgroup; /*!< Pickup group */ 00152 int callingpres; /*!< Calling presentation */ 00153 int allowguest; 00154 char language[MAX_LANGUAGE]; /*!< Default language for prompts */ 00155 char musicclass[MAX_MUSICCLASS]; /*!< Music on Hold class */ 00156 }; 00157 00158 struct jingle_container { 00159 ASTOBJ_CONTAINER_COMPONENTS(struct jingle); 00160 }; 00161 00162 static const char desc[] = "Jingle Channel"; 00163 static const char type[] = "Jingle"; 00164 00165 static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263; 00166 00167 AST_MUTEX_DEFINE_STATIC(jinglelock); /*!< Protect the interface list (of jingle_pvt's) */ 00168 00169 /* Forward declarations */ 00170 static struct ast_channel *jingle_request(const char *type, int format, void *data, int *cause); 00171 static int jingle_digit_begin(struct ast_channel *ast, char digit); 00172 static int jingle_digit_end(struct ast_channel *ast, char digit, unsigned int duration); 00173 static int jingle_call(struct ast_channel *ast, char *dest, int timeout); 00174 static int jingle_hangup(struct ast_channel *ast); 00175 static int jingle_answer(struct ast_channel *ast); 00176 static int jingle_newcall(struct jingle *client, ikspak *pak); 00177 static struct ast_frame *jingle_read(struct ast_channel *ast); 00178 static int jingle_write(struct ast_channel *ast, struct ast_frame *f); 00179 static int jingle_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen); 00180 static int jingle_fixup(struct ast_channel *oldchan, struct ast_channel *newchan); 00181 static int jingle_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen); 00182 static struct jingle_pvt *jingle_alloc(struct jingle *client, const char *from, const char *sid); 00183 /*----- RTP interface functions */ 00184 static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, 00185 struct ast_rtp *vrtp, int codecs, int nat_active); 00186 static enum ast_rtp_get_result jingle_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp); 00187 static int jingle_get_codec(struct ast_channel *chan); 00188 00189 /*! \brief PBX interface structure for channel registration */ 00190 static const struct ast_channel_tech jingle_tech = { 00191 .type = type, 00192 .description = "Jingle Channel Driver", 00193 .capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1), 00194 .requester = jingle_request, 00195 .send_digit_begin = jingle_digit_begin, 00196 .send_digit_end = jingle_digit_end, 00197 .bridge = ast_rtp_bridge, 00198 .call = jingle_call, 00199 .hangup = jingle_hangup, 00200 .answer = jingle_answer, 00201 .read = jingle_read, 00202 .write = jingle_write, 00203 .exception = jingle_read, 00204 .indicate = jingle_indicate, 00205 .fixup = jingle_fixup, 00206 .send_html = jingle_sendhtml, 00207 .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER 00208 }; 00209 00210 static struct sockaddr_in bindaddr = { 0, }; /*!< The address we bind to */ 00211 00212 static struct sched_context *sched; /*!< The scheduling context */ 00213 static struct io_context *io; /*!< The IO context */ 00214 static struct in_addr __ourip; 00215 00216 00217 /*! \brief RTP driver interface */ 00218 static struct ast_rtp_protocol jingle_rtp = { 00219 type: "jingle", 00220 get_rtp_info: jingle_get_rtp_peer, 00221 set_rtp_peer: jingle_set_rtp_peer, 00222 get_codec: jingle_get_codec, 00223 }; 00224 00225 static char externip[16]; 00226 00227 static struct jingle_container jingles; 00228 00229 static void jingle_member_destroy(struct jingle *obj) 00230 { 00231 free(obj); 00232 } 00233 00234 static struct jingle *find_jingle(char *name, char *connection) 00235 { 00236 struct jingle *jingle = NULL; 00237 00238 jingle = ASTOBJ_CONTAINER_FIND(&jingles, name); 00239 if (!jingle && strchr(name, '@')) 00240 jingle = ASTOBJ_CONTAINER_FIND_FULL(&jingles, name, user,,, strcasecmp); 00241 00242 if (!jingle) { /* guest call */ 00243 ASTOBJ_CONTAINER_TRAVERSE(&jingles, 1, { 00244 ASTOBJ_WRLOCK(iterator); 00245 if (!strcasecmp(iterator->name, "guest")) { 00246 if (!strcasecmp(iterator->connection->jid->partial, connection)) { 00247 jingle = iterator; 00248 break; 00249 } else if (!strcasecmp(iterator->connection->name, connection)) { 00250 jingle = iterator; 00251 break; 00252 } 00253 } 00254 ASTOBJ_UNLOCK(iterator); 00255 }); 00256 00257 } 00258 return jingle; 00259 } 00260 00261 00262 static void add_codec_to_answer(const struct jingle_pvt *p, int codec, iks *dcodecs) 00263 { 00264 char *format = ast_getformatname(codec); 00265 00266 if (!strcasecmp("ulaw", format)) { 00267 iks *payload_eg711u, *payload_pcmu; 00268 payload_pcmu = iks_new("payload-type"); 00269 iks_insert_attrib(payload_pcmu, "id", "0"); 00270 iks_insert_attrib(payload_pcmu, "name", "PCMU"); 00271 iks_insert_attrib(payload_pcmu, "xmlns", "http://www.google.com/session/phone"); 00272 payload_eg711u = iks_new("payload-type"); 00273 iks_insert_attrib(payload_eg711u, "id", "100"); 00274 iks_insert_attrib(payload_eg711u, "name", "EG711U"); 00275 iks_insert_attrib(payload_eg711u, "xmlns", "http://www.google.com/session/phone"); 00276 iks_insert_node(dcodecs, payload_pcmu); 00277 iks_insert_node(dcodecs, payload_eg711u); 00278 } 00279 if (!strcasecmp("alaw", format)) { 00280 iks *payload_eg711a; 00281 iks *payload_pcma = iks_new("payload-type"); 00282 iks_insert_attrib(payload_pcma, "id", "8"); 00283 iks_insert_attrib(payload_pcma, "name", "PCMA"); 00284 iks_insert_attrib(payload_pcma, "xmlns", "http://www.google.com/session/phone"); 00285 payload_eg711a = iks_new("payload-type"); 00286 iks_insert_attrib(payload_eg711a, "id", "101"); 00287 iks_insert_attrib(payload_eg711a, "name", "EG711A"); 00288 iks_insert_attrib(payload_eg711a, "xmlns", "http://www.google.com/session/phone"); 00289 iks_insert_node(dcodecs, payload_pcma); 00290 iks_insert_node(dcodecs, payload_eg711a); 00291 } 00292 if (!strcasecmp("ilbc", format)) { 00293 iks *payload_ilbc = iks_new("payload-type"); 00294 iks_insert_attrib(payload_ilbc, "id", "102"); 00295 iks_insert_attrib(payload_ilbc, "name", "iLBC"); 00296 iks_insert_attrib(payload_ilbc, "xmlns", "http://www.google.com/session/phone"); 00297 iks_insert_node(dcodecs, payload_ilbc); 00298 } 00299 if (!strcasecmp("g723", format)) { 00300 iks *payload_g723 = iks_new("payload-type"); 00301 iks_insert_attrib(payload_g723, "id", "4"); 00302 iks_insert_attrib(payload_g723, "name", "G723"); 00303 iks_insert_attrib(payload_g723, "xmlns", "http://www.google.com/session/phone"); 00304 iks_insert_node(dcodecs, payload_g723); 00305 } 00306 ast_rtp_lookup_code(p->rtp, 1, codec); 00307 } 00308 00309 static int jingle_accept_call(struct jingle *client, struct jingle_pvt *p) 00310 { 00311 struct jingle_pvt *tmp = client->p; 00312 struct aji_client *c = client->connection; 00313 iks *iq, *jingle, *dcodecs, *payload_red, *payload_audio, *payload_cn; 00314 int x; 00315 int pref_codec = 0; 00316 int alreadysent = 0; 00317 00318 if (p->initiator) 00319 return 1; 00320 00321 iq = iks_new("iq"); 00322 jingle = iks_new(GOOGLE_NODE); 00323 dcodecs = iks_new("description"); 00324 if (iq && jingle && dcodecs) { 00325 iks_insert_attrib(dcodecs, "xmlns", "http://www.google.com/session/phone"); 00326 00327 for (x = 0; x < 32; x++) { 00328 if (!(pref_codec = ast_codec_pref_index(&client->prefs, x))) 00329 break; 00330 if (!(client->capability & pref_codec)) 00331 continue; 00332 if (alreadysent & pref_codec) 00333 continue; 00334 if (pref_codec <= AST_FORMAT_MAX_AUDIO) 00335 add_codec_to_answer(p, pref_codec, dcodecs); 00336 else 00337 add_codec_to_answer(p, pref_codec, dcodecs); 00338 alreadysent |= pref_codec; 00339 } 00340 payload_red = iks_new("payload-type"); 00341 iks_insert_attrib(payload_red, "id", "117"); 00342 iks_insert_attrib(payload_red, "name", "red"); 00343 iks_insert_attrib(payload_red, "xmlns", "http://www.google.com/session/phone"); 00344 payload_audio = iks_new("payload-type"); 00345 iks_insert_attrib(payload_audio, "id", "106"); 00346 iks_insert_attrib(payload_audio, "name", "audio/telephone-event"); 00347 iks_insert_attrib(payload_audio, "xmlns", "http://www.google.com/session/phone"); 00348 payload_cn = iks_new("payload-type"); 00349 iks_insert_attrib(payload_cn, "id", "13"); 00350 iks_insert_attrib(payload_cn, "name", "CN"); 00351 iks_insert_attrib(payload_cn, "xmlns", "http://www.google.com/session/phone"); 00352 00353 00354 iks_insert_attrib(iq, "type", "set"); 00355 iks_insert_attrib(iq, "to", (p->from) ? p->from : client->user); 00356 iks_insert_attrib(iq, "id", client->connection->mid); 00357 ast_aji_increment_mid(client->connection->mid); 00358 00359 iks_insert_attrib(jingle, "xmlns", "http://www.google.com/session"); 00360 iks_insert_attrib(jingle, "type", JINGLE_ACCEPT); 00361 iks_insert_attrib(jingle, "initiator", 00362 p->initiator ? client->connection->jid->full : p->from); 00363 iks_insert_attrib(jingle, GOOGLE_SID, tmp->sid); 00364 iks_insert_node(iq, jingle); 00365 iks_insert_node(jingle, dcodecs); 00366 iks_insert_node(dcodecs, payload_red); 00367 iks_insert_node(dcodecs, payload_audio); 00368 iks_insert_node(dcodecs, payload_cn); 00369 00370 iks_send(c->p, iq); 00371 iks_delete(payload_red); 00372 iks_delete(payload_audio); 00373 iks_delete(payload_cn); 00374 iks_delete(dcodecs); 00375 iks_delete(jingle); 00376 iks_delete(iq); 00377 } 00378 return 1; 00379 } 00380 00381 static int jingle_ringing_ack(void *data, ikspak *pak) 00382 { 00383 struct jingle_pvt *p = data; 00384 00385 if (p->ringrule) 00386 iks_filter_remove_rule(p->parent->connection->f, p->ringrule); 00387 p->ringrule = NULL; 00388 if (p->owner) 00389 ast_queue_control(p->owner, AST_CONTROL_RINGING); 00390 return IKS_FILTER_EAT; 00391 } 00392 00393 static int jingle_answer(struct ast_channel *ast) 00394 { 00395 struct jingle_pvt *p = ast->tech_pvt; 00396 struct jingle *client = p->parent; 00397 int res = 0; 00398 00399 if (option_debug) 00400 ast_log(LOG_DEBUG, "Answer!\n"); 00401 ast_mutex_lock(&p->lock); 00402 jingle_accept_call(client, p); 00403 ast_mutex_unlock(&p->lock); 00404 return res; 00405 } 00406 00407 static enum ast_rtp_get_result jingle_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp) 00408 { 00409 struct jingle_pvt *p = chan->tech_pvt; 00410 enum ast_rtp_get_result res = AST_RTP_GET_FAILED; 00411 00412 if (!p) 00413 return res; 00414 00415 ast_mutex_lock(&p->lock); 00416 if (p->rtp) { 00417 *rtp = p->rtp; 00418 res = AST_RTP_TRY_NATIVE; 00419 } 00420 ast_mutex_unlock(&p->lock); 00421 00422 return res; 00423 } 00424 00425 static int jingle_get_codec(struct ast_channel *chan) 00426 { 00427 struct jingle_pvt *p = chan->tech_pvt; 00428 return p->peercapability; 00429 } 00430 00431 static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active) 00432 { 00433 struct jingle_pvt *p; 00434 00435 p = chan->tech_pvt; 00436 if (!p) 00437 return -1; 00438 ast_mutex_lock(&p->lock); 00439 00440 /* if (rtp) 00441 ast_rtp_get_peer(rtp, &p->redirip); 00442 else 00443 memset(&p->redirip, 0, sizeof(p->redirip)); 00444 p->redircodecs = codecs; */ 00445 00446 /* Reset lastrtprx timer */ 00447 ast_mutex_unlock(&p->lock); 00448 return 0; 00449 } 00450 00451 static int jingle_response(struct jingle *client, ikspak *pak, const char *reasonstr, const char *reasonstr2) 00452 { 00453 iks *response = NULL, *error = NULL, *reason = NULL; 00454 int res = -1; 00455 00456 response = iks_new("iq"); 00457 if (response) { 00458 iks_insert_attrib(response, "type", "result"); 00459 iks_insert_attrib(response, "from", client->connection->jid->full); 00460 iks_insert_attrib(response, "to", iks_find_attrib(pak->x, "from")); 00461 iks_insert_attrib(response, "id", iks_find_attrib(pak->x, "id")); 00462 if (reasonstr) { 00463 error = iks_new("error"); 00464 if (error) { 00465 iks_insert_attrib(error, "type", "cancel"); 00466 reason = iks_new(reasonstr); 00467 if (reason) 00468 iks_insert_node(error, reason); 00469 iks_insert_node(response, error); 00470 } 00471 } 00472 iks_send(client->connection->p, response); 00473 if (reason) 00474 iks_delete(reason); 00475 if (error) 00476 iks_delete(error); 00477 iks_delete(response); 00478 res = 0; 00479 } 00480 return res; 00481 } 00482 00483 static int jingle_is_answered(struct jingle *client, ikspak *pak) 00484 { 00485 struct jingle_pvt *tmp; 00486 00487 if (option_debug) 00488 ast_log(LOG_DEBUG, "The client is %s\n", client->name); 00489 /* Make sure our new call doesn't exist yet */ 00490 for (tmp = client->p; tmp; tmp = tmp->next) { 00491 if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) 00492 break; 00493 } 00494 00495 if (tmp) { 00496 if (tmp->owner) 00497 ast_queue_control(tmp->owner, AST_CONTROL_ANSWER); 00498 } else 00499 ast_log(LOG_NOTICE, "Whoa, didn't find call!\n"); 00500 jingle_response(client, pak, NULL, NULL); 00501 return 1; 00502 } 00503 00504 static int jingle_handle_dtmf(struct jingle *client, ikspak *pak) 00505 { 00506 struct jingle_pvt *tmp; 00507 iks *dtmfnode = NULL; 00508 char *dtmf; 00509 /* Make sure our new call doesn't exist yet */ 00510 for (tmp = client->p; tmp; tmp = tmp->next) { 00511 if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) 00512 break; 00513 } 00514 00515 if (tmp) { 00516 if(iks_find_with_attrib(pak->x, "dtmf-method", "method", "rtp")) { 00517 jingle_response(client,pak, 00518 "feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'", 00519 "unsupported-dtmf-method xmlns='http://jabber.org/protocol/jingle/info/dtmf#errors'"); 00520 return -1; 00521 } 00522 if ((dtmfnode = iks_find(pak->x, "dtmf"))) { 00523 if((dtmf = iks_find_attrib(dtmfnode, "code"))) { 00524 if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-up")) { 00525 struct ast_frame f = {AST_FRAME_DTMF_BEGIN, }; 00526 f.subclass = dtmf[0]; 00527 ast_queue_frame(tmp->owner, &f); 00528 ast_verbose("JINGLE! DTMF-relay event received: %c\n", f.subclass); 00529 } else if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-down")) { 00530 struct ast_frame f = {AST_FRAME_DTMF_END, }; 00531 f.subclass = dtmf[0]; 00532 ast_queue_frame(tmp->owner, &f); 00533 ast_verbose("JINGLE! DTMF-relay event received: %c\n", f.subclass); 00534 } else if(iks_find_attrib(pak->x, "dtmf")) { /* 250 millasecond default */ 00535 struct ast_frame f = {AST_FRAME_DTMF, }; 00536 f.subclass = dtmf[0]; 00537 ast_queue_frame(tmp->owner, &f); 00538 ast_verbose("JINGLE! DTMF-relay event received: %c\n", f.subclass); 00539 } 00540 } 00541 } 00542 jingle_response(client, pak, NULL, NULL); 00543 return 1; 00544 } else 00545 ast_log(LOG_NOTICE, "Whoa, didn't find call!\n"); 00546 00547 jingle_response(client, pak, NULL, NULL); 00548 return 1; 00549 } 00550 00551 00552 static int jingle_hangup_farend(struct jingle *client, ikspak *pak) 00553 { 00554 struct jingle_pvt *tmp; 00555 00556 if (option_debug) 00557 ast_log(LOG_DEBUG, "The client is %s\n", client->name); 00558 /* Make sure our new call doesn't exist yet */ 00559 for (tmp = client->p; tmp; tmp = tmp->next) { 00560 if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) 00561 break; 00562 } 00563 00564 if (tmp) { 00565 tmp->alreadygone = 1; 00566 ast_queue_hangup(tmp->owner); 00567 } else 00568 ast_log(LOG_NOTICE, "Whoa, didn't find call!\n"); 00569 jingle_response(client, pak, NULL, NULL); 00570 return 1; 00571 } 00572 00573 static int jingle_create_candidates(struct jingle *client, struct jingle_pvt *p, char *sid, char *from) 00574 { 00575 struct jingle_candidate *tmp; 00576 struct aji_client *c = client->connection; 00577 struct jingle_candidate *ours1 = NULL, *ours2 = NULL; 00578 struct sockaddr_in sin; 00579 struct sockaddr_in dest; 00580 struct in_addr us; 00581 iks *iq, *jingle, *candidate; 00582 char user[17], pass[17], preference[5], port[7]; 00583 00584 00585 iq = iks_new("iq"); 00586 jingle = iks_new(GOOGLE_NODE); 00587 candidate = iks_new("candidate"); 00588 if (!iq || !jingle || !candidate) { 00589 ast_log(LOG_ERROR, "Memory allocation error\n"); 00590 goto safeout; 00591 } 00592 ours1 = ast_calloc(1, sizeof(*ours1)); 00593 ours2 = ast_calloc(1, sizeof(*ours2)); 00594 if (!ours1 || !ours2) 00595 goto safeout; 00596 iks_insert_node(iq, jingle); 00597 iks_insert_node(jingle, candidate); 00598 00599 for (; p; p = p->next) { 00600 if (!strcasecmp(p->sid, sid)) 00601 break; 00602 } 00603 00604 if (!p) { 00605 ast_log(LOG_NOTICE, "No matching jingle session - SID %s!\n", sid); 00606 goto safeout; 00607 } 00608 00609 ast_rtp_get_us(p->rtp, &sin); 00610 ast_find_ourip(&us, bindaddr); 00611 00612 /* Setup our jingle candidates */ 00613 ast_copy_string(ours1->name, "rtp", sizeof(ours1->name)); 00614 ours1->port = ntohs(sin.sin_port); 00615 ours1->preference = 1; 00616 snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random()); 00617 snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random()); 00618 ast_copy_string(ours1->username, user, sizeof(ours1->username)); 00619 ast_copy_string(ours1->password, pass, sizeof(ours1->password)); 00620 ast_copy_string(ours1->ip, ast_inet_ntoa(us), sizeof(ours1->ip)); 00621 ours1->protocol = AJI_PROTOCOL_UDP; 00622 ours1->type = AJI_CONNECT_LOCAL; 00623 ours1->generation = 0; 00624 p->ourcandidates = ours1; 00625 00626 if (!ast_strlen_zero(externip)) { 00627 /* XXX We should really stun for this one not just go with externip XXX */ 00628 snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random()); 00629 snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random()); 00630 ast_copy_string(ours2->username, user, sizeof(ours2->username)); 00631 ast_copy_string(ours2->password, pass, sizeof(ours2->password)); 00632 ast_copy_string(ours2->ip, externip, sizeof(ours2->ip)); 00633 ast_copy_string(ours2->name, "rtp", sizeof(ours1->name)); 00634 ours2->port = ntohs(sin.sin_port); 00635 ours2->preference = 0.9; 00636 ours2->protocol = AJI_PROTOCOL_UDP; 00637 ours2->type = AJI_CONNECT_STUN; 00638 ours2->generation = 0; 00639 ours1->next = ours2; 00640 ours2 = NULL; 00641 } 00642 ours1 = NULL; 00643 dest.sin_addr = __ourip; 00644 dest.sin_port = sin.sin_port; 00645 00646 00647 for (tmp = p->ourcandidates; tmp; tmp = tmp->next) { 00648 snprintf(port, sizeof(port), "%d", tmp->port); 00649 snprintf(preference, sizeof(preference), "%.2f", tmp->preference); 00650 iks_insert_attrib(iq, "from", c->jid->full); 00651 iks_insert_attrib(iq, "to", from); 00652 iks_insert_attrib(iq, "type", "set"); 00653 iks_insert_attrib(iq, "id", c->mid); 00654 ast_aji_increment_mid(c->mid); 00655 iks_insert_attrib(jingle, "type", "candidates"); 00656 iks_insert_attrib(jingle, "id", sid); 00657 iks_insert_attrib(jingle, "initiator", (p->initiator) ? c->jid->full : from); 00658 iks_insert_attrib(jingle, "xmlns", GOOGLE_NS); 00659 iks_insert_attrib(candidate, "name", tmp->name); 00660 iks_insert_attrib(candidate, "address", tmp->ip); 00661 iks_insert_attrib(candidate, "port", port); 00662 iks_insert_attrib(candidate, "username", tmp->username); 00663 iks_insert_attrib(candidate, "password", tmp->password); 00664 iks_insert_attrib(candidate, "preference", preference); 00665 if (tmp->protocol == AJI_PROTOCOL_UDP) 00666 iks_insert_attrib(candidate, "protocol", "udp"); 00667 if (tmp->protocol == AJI_PROTOCOL_SSLTCP) 00668 iks_insert_attrib(candidate, "protocol", "ssltcp"); 00669 if (tmp->type == AJI_CONNECT_STUN) 00670 iks_insert_attrib(candidate, "type", "stun"); 00671 if (tmp->type == AJI_CONNECT_LOCAL) 00672 iks_insert_attrib(candidate, "type", "local"); 00673 if (tmp->type == AJI_CONNECT_RELAY) 00674 iks_insert_attrib(candidate, "type", "relay"); 00675 iks_insert_attrib(candidate, "network", "0"); 00676 iks_insert_attrib(candidate, "generation", "0"); 00677 iks_send(c->p, iq); 00678 } 00679 p->laststun = 0; 00680 00681 safeout: 00682 if (ours1) 00683 free(ours1); 00684 if (ours2) 00685 free(ours2); 00686 if (iq) 00687 iks_delete(iq); 00688 if (jingle) 00689 iks_delete(jingle); 00690 if (candidate) 00691 iks_delete(candidate); 00692 return 1; 00693 } 00694 00695 static struct jingle_pvt *jingle_alloc(struct jingle *client, const char *from, const char *sid) 00696 { 00697 struct jingle_pvt *tmp = NULL; 00698 struct aji_resource *resources = NULL; 00699 struct aji_buddy *buddy; 00700 char idroster[200]; 00701 00702 if (option_debug) 00703 ast_log(LOG_DEBUG, "The client is %s for alloc\n", client->name); 00704 if (!sid && !strchr(from, '/')) { /* I started call! */ 00705 if (!strcasecmp(client->name, "guest")) { 00706 buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, from); 00707 if (buddy) 00708 resources = buddy->resources; 00709 } else 00710 resources = client->buddy->resources; 00711 while (resources) { 00712 if (resources->cap->jingle) { 00713 break; 00714 } 00715 resources = resources->next; 00716 } 00717 if (resources) 00718 snprintf(idroster, sizeof(idroster), "%s/%s", from, resources->resource); 00719 else { 00720 ast_log(LOG_ERROR, "no jingle capable clients to talk to.\n"); 00721 return NULL; 00722 } 00723 } 00724 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { 00725 return NULL; 00726 } 00727 if (sid) { 00728 ast_copy_string(tmp->sid, sid, sizeof(tmp->sid)); 00729 ast_copy_string(tmp->from, from, sizeof(tmp->from)); 00730 } else { 00731 snprintf(tmp->sid, sizeof(tmp->sid), "%08lx%08lx", ast_random(), ast_random()); 00732 ast_copy_string(tmp->from, idroster, sizeof(tmp->from)); 00733 tmp->initiator = 1; 00734 } 00735 tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); 00736 tmp->parent = client; 00737 if (!tmp->rtp) { 00738 ast_log(LOG_WARNING, "Out of RTP sessions?\n"); 00739 free(tmp); 00740 return NULL; 00741 } 00742 ast_copy_string(tmp->exten, "s", sizeof(tmp->exten)); 00743 ast_mutex_init(&tmp->lock); 00744 ast_mutex_lock(&jinglelock); 00745 tmp->next = client->p; 00746 client->p = tmp; 00747 ast_mutex_unlock(&jinglelock); 00748 return tmp; 00749 } 00750 00751 /*! \brief Start new jingle channel */ 00752 static struct ast_channel *jingle_new(struct jingle *client, struct jingle_pvt *i, int state, const char *title) 00753 { 00754 struct ast_channel *tmp; 00755 int fmt; 00756 int what; 00757 const char *str; 00758 00759 if (title) 00760 str = title; 00761 else 00762 str = i->from; 00763 tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Jingle/%s-%04lx", str, ast_random() & 0xffff); 00764 if (!tmp) { 00765 ast_log(LOG_WARNING, "Unable to allocate Jingle channel structure!\n"); 00766 return NULL; 00767 } 00768 tmp->tech = &jingle_tech; 00769 00770 /* Select our native format based on codec preference until we receive 00771 something from another device to the contrary. */ 00772 if (i->jointcapability) 00773 what = i->jointcapability; 00774 else if (i->capability) 00775 what = i->capability; 00776 else 00777 what = global_capability; 00778 tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK); 00779 fmt = ast_best_codec(tmp->nativeformats); 00780 00781 if (i->rtp) { 00782 tmp->fds[0] = ast_rtp_fd(i->rtp); 00783 tmp->fds[1] = ast_rtcp_fd(i->rtp); 00784 } 00785 if (i->vrtp) { 00786 tmp->fds[2] = ast_rtp_fd(i->vrtp); 00787 tmp->fds[3] = ast_rtcp_fd(i->vrtp); 00788 } 00789 if (state == AST_STATE_RING) 00790 tmp->rings = 1; 00791 tmp->adsicpe = AST_ADSI_UNAVAILABLE; 00792 tmp->writeformat = fmt; 00793 tmp->rawwriteformat = fmt; 00794 tmp->readformat = fmt; 00795 tmp->rawreadformat = fmt; 00796 tmp->tech_pvt = i; 00797 00798 tmp->callgroup = client->callgroup; 00799 tmp->pickupgroup = client->pickupgroup; 00800 tmp->cid.cid_pres = client->callingpres; 00801 if (!ast_strlen_zero(client->accountcode)) 00802 ast_string_field_set(tmp, accountcode, client->accountcode); 00803 if (client->amaflags) 00804 tmp->amaflags = client->amaflags; 00805 if (!ast_strlen_zero(client->language)) 00806 ast_string_field_set(tmp, language, client->language); 00807 if (!ast_strlen_zero(client->musicclass)) 00808 ast_string_field_set(tmp, musicclass, client->musicclass); 00809 i->owner = tmp; 00810 ast_copy_string(tmp->context, client->context, sizeof(tmp->context)); 00811 ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten)); 00812 /* Don't use ast_set_callerid() here because it will 00813 * generate an unnecessary NewCallerID event */ 00814 tmp->cid.cid_num = ast_strdup(i->cid_num); 00815 tmp->cid.cid_ani = ast_strdup(i->cid_num); 00816 tmp->cid.cid_name = ast_strdup(i->cid_name); 00817 if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s")) 00818 tmp->cid.cid_dnid = ast_strdup(i->exten); 00819 tmp->priority = 1; 00820 if (i->rtp) 00821 ast_jb_configure(tmp, &global_jbconf); 00822 if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) { 00823 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); 00824 tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 00825 ast_hangup(tmp); 00826 tmp = NULL; 00827 } 00828 00829 return tmp; 00830 } 00831 00832 static int jingle_action(struct jingle *client, struct jingle_pvt *p, const char *action) 00833 { 00834 iks *request, *session = NULL; 00835 int res = -1; 00836 00837 request = iks_new("iq"); 00838 if (request) { 00839 iks_insert_attrib(request, "type", "set"); 00840 iks_insert_attrib(request, "from", client->connection->jid->full); 00841 iks_insert_attrib(request, "to", p->from); 00842 iks_insert_attrib(request, "id", client->connection->mid); 00843 ast_aji_increment_mid(client->connection->mid); 00844 session = iks_new("session"); 00845 if (session) { 00846 iks_insert_attrib(session, "type", action); 00847 iks_insert_attrib(session, "id", p->sid); 00848 iks_insert_attrib(session, "initiator", 00849 p->initiator ? client->connection->jid->full : p->from); 00850 iks_insert_attrib(session, "xmlns", "http://www.google.com/session"); 00851 iks_insert_node(request, session); 00852 iks_send(client->connection->p, request); 00853 iks_delete(session); 00854 res = 0; 00855 } 00856 iks_delete(request); 00857 } 00858 return res; 00859 } 00860 00861 static void jingle_free_candidates(struct jingle_candidate *candidate) 00862 { 00863 struct jingle_candidate *last; 00864 while (candidate) { 00865 last = candidate; 00866 candidate = candidate->next; 00867 free(last); 00868 } 00869 } 00870 00871 static void jingle_free_pvt(struct jingle *client, struct jingle_pvt *p) 00872 { 00873 struct jingle_pvt *cur, *prev = NULL; 00874 cur = client->p; 00875 while (cur) { 00876 if (cur == p) { 00877 if (prev) 00878 prev->next = p->next; 00879 else 00880 client->p = p->next; 00881 break; 00882 } 00883 prev = cur; 00884 cur = cur->next; 00885 } 00886 if (p->ringrule) 00887 iks_filter_remove_rule(p->parent->connection->f, p->ringrule); 00888 if (p->owner) 00889 ast_log(LOG_WARNING, "Uh oh, there's an owner, this is going to be messy.\n"); 00890 if (p->rtp) 00891 ast_rtp_destroy(p->rtp); 00892 if (p->vrtp) 00893 ast_rtp_destroy(p->vrtp); 00894 jingle_free_candidates(p->theircandidates); 00895 free(p); 00896 } 00897 00898 00899 static int jingle_newcall(struct jingle *client, ikspak *pak) 00900 { 00901 struct jingle_pvt *p, *tmp = client->p; 00902 struct ast_channel *chan; 00903 int res; 00904 iks *codec; 00905 00906 /* Make sure our new call doesn't exist yet */ 00907 while (tmp) { 00908 if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) { 00909 ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid); 00910 jingle_response(client, pak, "out-of-order", NULL); 00911 return -1; 00912 } 00913 tmp = tmp->next; 00914 } 00915 00916 p = jingle_alloc(client, pak->from->partial, iks_find_attrib(pak->query, GOOGLE_SID)); 00917 if (!p) { 00918 ast_log(LOG_WARNING, "Unable to allocate jingle structure!\n"); 00919 return -1; 00920 } 00921 chan = jingle_new(client, p, AST_STATE_DOWN, pak->from->user); 00922 if (chan) { 00923 ast_mutex_lock(&p->lock); 00924 ast_copy_string(p->from, pak->from->full, sizeof(p->from)); 00925 if (iks_find_attrib(pak->query, GOOGLE_SID)) { 00926 ast_copy_string(p->sid, iks_find_attrib(pak->query, GOOGLE_SID), 00927 sizeof(p->sid)); 00928 } 00929 00930 codec = iks_child(iks_child(iks_child(pak->x))); 00931 while (codec) { 00932 ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id"))); 00933 ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", 00934 iks_find_attrib(codec, "name"), 0); 00935 codec = iks_next(codec); 00936 } 00937 00938 ast_mutex_unlock(&p->lock); 00939 ast_setstate(chan, AST_STATE_RING); 00940 res = ast_pbx_start(chan); 00941 00942 switch (res) { 00943 case AST_PBX_FAILED: 00944 ast_log(LOG_WARNING, "Failed to start PBX :(\n"); 00945 jingle_response(client, pak, "service-unavailable", NULL); 00946 break; 00947 case AST_PBX_CALL_LIMIT: 00948 ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n"); 00949 jingle_response(client, pak, "service-unavailable", NULL); 00950 break; 00951 case AST_PBX_SUCCESS: 00952 jingle_response(client, pak, NULL, NULL); 00953 jingle_create_candidates(client, p, 00954 iks_find_attrib(pak->query, GOOGLE_SID), 00955 iks_find_attrib(pak->x, "from")); 00956 /* nothing to do */ 00957 break; 00958 } 00959 } else { 00960 jingle_free_pvt(client, p); 00961 } 00962 return 1; 00963 } 00964 00965 static int jingle_update_stun(struct jingle *client, struct jingle_pvt *p) 00966 { 00967 struct jingle_candidate *tmp; 00968 struct hostent *hp; 00969 struct ast_hostent ahp; 00970 struct sockaddr_in sin; 00971 00972 if (time(NULL) == p->laststun) 00973 return 0; 00974 00975 tmp = p->theircandidates; 00976 p->laststun = time(NULL); 00977 while (tmp) { 00978 char username[256]; 00979 hp = ast_gethostbyname(tmp->ip, &ahp); 00980 sin.sin_family = AF_INET; 00981 memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); 00982 sin.sin_port = htons(tmp->port); 00983 snprintf(username, sizeof(username), "%s%s", tmp->username, 00984 p->ourcandidates->username); 00985 00986 ast_rtp_stun_request(p->rtp, &sin, username); 00987 tmp = tmp->next; 00988 } 00989 return 1; 00990 } 00991 00992 static int jingle_add_candidate(struct jingle *client, ikspak *pak) 00993 { 00994 struct jingle_pvt *p = NULL, *tmp = NULL; 00995 struct aji_client *c = client->connection; 00996 struct jingle_candidate *newcandidate = NULL; 00997 iks *traversenodes = NULL, *receipt = NULL; 00998 newcandidate = ast_calloc(1, sizeof(*newcandidate)); 00999 if (!newcandidate) 01000 return 0; 01001 for (tmp = client->p; tmp; tmp = tmp->next) { 01002 if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) { 01003 p = tmp; 01004 break; 01005 } 01006 } 01007 01008 if (!p) 01009 return -1; 01010 01011 traversenodes = pak->query; 01012 while(traversenodes) { 01013 if(!strcasecmp(iks_name(traversenodes), "session")) { 01014 traversenodes = iks_child(traversenodes); 01015 continue; 01016 } 01017 if(!strcasecmp(iks_name(traversenodes), "candidate")) { 01018 newcandidate = ast_calloc(1, sizeof(*newcandidate)); 01019 if (!newcandidate) 01020 return 0; 01021 ast_copy_string(newcandidate->name, iks_find_attrib(traversenodes, "name"), 01022 sizeof(newcandidate->name)); 01023 ast_copy_string(newcandidate->ip, iks_find_attrib(traversenodes, "address"), 01024 sizeof(newcandidate->ip)); 01025 newcandidate->port = atoi(iks_find_attrib(traversenodes, "port")); 01026 ast_copy_string(newcandidate->username, iks_find_attrib(traversenodes, "username"), 01027 sizeof(newcandidate->username)); 01028 ast_copy_string(newcandidate->password, iks_find_attrib(traversenodes, "password"), 01029 sizeof(newcandidate->password)); 01030 newcandidate->preference = atof(iks_find_attrib(traversenodes, "preference")); 01031 if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "udp")) 01032 newcandidate->protocol = AJI_PROTOCOL_UDP; 01033 if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "ssltcp")) 01034 newcandidate->protocol = AJI_PROTOCOL_SSLTCP; 01035 01036 if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "stun")) 01037 newcandidate->type = AJI_CONNECT_STUN; 01038 if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "local")) 01039 newcandidate->type = AJI_CONNECT_LOCAL; 01040 if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "relay")) 01041 newcandidate->type = AJI_CONNECT_RELAY; 01042 ast_copy_string(newcandidate->network, iks_find_attrib(traversenodes, "network"), 01043 sizeof(newcandidate->network)); 01044 newcandidate->generation = atoi(iks_find_attrib(traversenodes, "generation")); 01045 newcandidate->next = NULL; 01046 01047 newcandidate->next = p->theircandidates; 01048 p->theircandidates = newcandidate; 01049 p->laststun = 0; 01050 jingle_update_stun(p->parent, p); 01051 newcandidate = NULL; 01052 } 01053 traversenodes = iks_next(traversenodes); 01054 } 01055 01056 receipt = iks_new("iq"); 01057 iks_insert_attrib(receipt, "type", "result"); 01058 iks_insert_attrib(receipt, "from", c->jid->full); 01059 iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from")); 01060 iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id")); 01061 iks_send(c->p, receipt); 01062 iks_delete(receipt); 01063 01064 return 1; 01065 } 01066 01067 static struct ast_frame *jingle_rtp_read(struct ast_channel *ast, struct jingle_pvt *p) 01068 { 01069 struct ast_frame *f; 01070 01071 if (!p->rtp) 01072 return &ast_null_frame; 01073 f = ast_rtp_read(p->rtp); 01074 jingle_update_stun(p->parent, p); 01075 if (p->owner) { 01076 /* We already hold the channel lock */ 01077 if (f->frametype == AST_FRAME_VOICE) { 01078 if (f->subclass != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) { 01079 if (option_debug) 01080 ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass); 01081 p->owner->nativeformats = 01082 (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass; 01083 ast_set_read_format(p->owner, p->owner->readformat); 01084 ast_set_write_format(p->owner, p->owner->writeformat); 01085 } 01086 /* if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_INBAND) && p->vad) { 01087 f = ast_dsp_process(p->owner, p->vad, f); 01088 if (option_debug && f && (f->frametype == AST_FRAME_DTMF)) 01089 ast_log(LOG_DEBUG, "* Detected inband DTMF '%c'\n", f->subclass); 01090 } */ 01091 } 01092 } 01093 return f; 01094 } 01095 01096 static struct ast_frame *jingle_read(struct ast_channel *ast) 01097 { 01098 struct ast_frame *fr; 01099 struct jingle_pvt *p = ast->tech_pvt; 01100 01101 ast_mutex_lock(&p->lock); 01102 fr = jingle_rtp_read(ast, p); 01103 ast_mutex_unlock(&p->lock); 01104 return fr; 01105 } 01106 01107 /*! \brief Send frame to media channel (rtp) */ 01108 static int jingle_write(struct ast_channel *ast, struct ast_frame *frame) 01109 { 01110 struct jingle_pvt *p = ast->tech_pvt; 01111 int res = 0; 01112 01113 switch (frame->frametype) { 01114 case AST_FRAME_VOICE: 01115 if (!(frame->subclass & ast->nativeformats)) { 01116 ast_log(LOG_WARNING, 01117 "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n", 01118 frame->subclass, ast->nativeformats, ast->readformat, 01119 ast->writeformat); 01120 return 0; 01121 } 01122 if (p) { 01123 ast_mutex_lock(&p->lock); 01124 if (p->rtp) { 01125 res = ast_rtp_write(p->rtp, frame); 01126 } 01127 ast_mutex_unlock(&p->lock); 01128 } 01129 break; 01130 case AST_FRAME_VIDEO: 01131 if (p) { 01132 ast_mutex_lock(&p->lock); 01133 if (p->vrtp) { 01134 res = ast_rtp_write(p->vrtp, frame); 01135 } 01136 ast_mutex_unlock(&p->lock); 01137 } 01138 break; 01139 case AST_FRAME_IMAGE: 01140 return 0; 01141 break; 01142 default: 01143 ast_log(LOG_WARNING, "Can't send %d type frames with Jingle write\n", 01144 frame->frametype); 01145 return 0; 01146 } 01147 01148 return res; 01149 } 01150 01151 static int jingle_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) 01152 { 01153 struct jingle_pvt *p = newchan->tech_pvt; 01154 ast_mutex_lock(&p->lock); 01155 01156 if ((p->owner != oldchan)) { 01157 ast_mutex_unlock(&p->lock); 01158 return -1; 01159 } 01160 if (p->owner == oldchan) 01161 p->owner = newchan; 01162 ast_mutex_unlock(&p->lock); 01163 return 0; 01164 } 01165 01166 static int jingle_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen) 01167 { 01168 int res = 0; 01169 01170 switch (condition) { 01171 case AST_CONTROL_HOLD: 01172 ast_moh_start(ast, data, NULL); 01173 break; 01174 case AST_CONTROL_UNHOLD: 01175 ast_moh_stop(ast); 01176 break; 01177 default: 01178 ast_log(LOG_NOTICE, "Don't know how to indicate condition '%d'\n", condition); 01179 res = -1; 01180 } 01181 01182 return res; 01183 } 01184 01185 static int jingle_digit(struct ast_channel *ast, char digit, unsigned int duration) 01186 { 01187 struct jingle_pvt *p = ast->tech_pvt; 01188 struct jingle *client = p->parent; 01189 iks *iq, *jingle, *dtmf; 01190 char buffer[2] = {digit, '\0'}; 01191 iq = iks_new("iq"); 01192 jingle = iks_new("jingle"); 01193 dtmf = iks_new("dtmf"); 01194 if(!iq || !jingle || !dtmf) { 01195 if(iq) 01196 iks_delete(iq); 01197 if(jingle) 01198 iks_delete(jingle); 01199 if(dtmf) 01200 iks_delete(dtmf); 01201 ast_log(LOG_ERROR, "Did not send dtmf do to memory issue\n"); 01202 return -1; 01203 } 01204 01205 iks_insert_attrib(iq, "type", "set"); 01206 iks_insert_attrib(iq, "to", p->from); 01207 iks_insert_attrib(iq, "from", client->connection->jid->full); 01208 iks_insert_attrib(iq, "id", client->connection->mid); 01209 ast_aji_increment_mid(client->connection->mid); 01210 iks_insert_attrib(jingle, "xmlns", "http://jabber.org/protocol/jingle"); 01211 iks_insert_attrib(jingle, "action", "content-info"); 01212 iks_insert_attrib(jingle, "initiator", p->initiator ? client->connection->jid->full : p->from); 01213 iks_insert_attrib(jingle, "sid", p->sid); 01214 iks_insert_attrib(dtmf, "xmlns", "http://jabber.org/protocol/jingle/info/dtmf"); 01215 iks_insert_attrib(dtmf, "code", buffer); 01216 iks_insert_node(iq, jingle); 01217 iks_insert_node(jingle, dtmf); 01218 01219 ast_mutex_lock(&p->lock); 01220 if (ast->dtmff.frametype == AST_FRAME_DTMF_BEGIN) { 01221 iks_insert_attrib(dtmf, "action", "button-down"); 01222 } else if (ast->dtmff.frametype == AST_FRAME_DTMF_END) { 01223 iks_insert_attrib(dtmf, "action", "button-up"); 01224 } 01225 iks_send(client->connection->p, iq); 01226 iks_delete(iq); 01227 iks_delete(jingle); 01228 iks_delete(dtmf); 01229 ast_mutex_unlock(&p->lock); 01230 return 0; 01231 } 01232 01233 static int jingle_digit_begin(struct ast_channel *chan, char digit) 01234 { 01235 return jingle_digit(chan, digit, 0); 01236 } 01237 01238 static int jingle_digit_end(struct ast_channel *ast, char digit, unsigned int duration) 01239 { 01240 return jingle_digit(ast, digit, duration); 01241 } 01242 01243 static int jingle_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen) 01244 { 01245 ast_log(LOG_NOTICE, "XXX Implement jingle sendhtml XXX\n"); 01246 01247 return -1; 01248 } 01249 static int jingle_transmit_invite(struct jingle_pvt *p) 01250 { 01251 struct jingle *jingle = NULL; 01252 struct aji_client *client = NULL; 01253 iks *iq, *desc, *session; 01254 iks *payload_eg711u, *payload_pcmu; 01255 01256 jingle = p->parent; 01257 client = jingle->connection; 01258 iq = iks_new("iq"); 01259 desc = iks_new("description"); 01260 session = iks_new("session"); 01261 iks_insert_attrib(iq, "type", "set"); 01262 iks_insert_attrib(iq, "to", p->from); 01263 iks_insert_attrib(iq, "from", client->jid->full); 01264 iks_insert_attrib(iq, "id", client->mid); 01265 ast_aji_increment_mid(client->mid); 01266 iks_insert_attrib(session, "type", "initiate"); 01267 iks_insert_attrib(session, "id", p->sid); 01268 iks_insert_attrib(session, "initiator", client->jid->full); 01269 iks_insert_attrib(session, "xmlns", "http://www.google.com/session"); 01270 iks_insert_attrib(desc, "xmlns", "http://www.google.com/session/phone"); 01271 payload_pcmu = iks_new("payload-type"); 01272 iks_insert_attrib(payload_pcmu, "id", "0"); 01273 iks_insert_attrib(payload_pcmu, "name", "PCMU"); 01274 payload_eg711u = iks_new("payload-type"); 01275 iks_insert_attrib(payload_eg711u, "id", "100"); 01276 iks_insert_attrib(payload_eg711u, "name", "EG711U"); 01277 iks_insert_node(desc, payload_pcmu); 01278 iks_insert_node(desc, payload_eg711u); 01279 iks_insert_node(iq, session); 01280 iks_insert_node(session, desc); 01281 iks_send(client->p, iq); 01282 iks_delete(iq); 01283 iks_delete(desc); 01284 iks_delete(session); 01285 iks_delete(payload_eg711u); 01286 iks_delete(payload_pcmu); 01287 return 0; 01288 } 01289 01290 /* Not in use right now. 01291 static int jingle_auto_congest(void *nothing) 01292 { 01293 struct jingle_pvt *p = nothing; 01294 01295 ast_mutex_lock(&p->lock); 01296 if (p->owner) { 01297 if (!ast_channel_trylock(p->owner)) { 01298 ast_log(LOG_NOTICE, "Auto-congesting %s\n", p->owner->name); 01299 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 01300 ast_channel_unlock(p->owner); 01301 } 01302 } 01303 ast_mutex_unlock(&p->lock); 01304 return 0; 01305 } 01306 */ 01307 01308 /*! \brief Initiate new call, part of PBX interface 01309 * dest is the dial string */ 01310 static int jingle_call(struct ast_channel *ast, char *dest, int timeout) 01311 { 01312 struct jingle_pvt *p = ast->tech_pvt; 01313 01314 if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { 01315 ast_log(LOG_WARNING, "jingle_call called on %s, neither down nor reserved\n", ast->name); 01316 return -1; 01317 } 01318 01319 ast_setstate(ast, AST_STATE_RING); 01320 p->jointcapability = p->capability; 01321 if (!p->ringrule) { 01322 ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring)); 01323 p->ringrule = iks_filter_add_rule(p->parent->connection->f, jingle_ringing_ack, p, 01324 IKS_RULE_ID, p->ring, IKS_RULE_DONE); 01325 } else 01326 ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n"); 01327 01328 jingle_transmit_invite(p); 01329 jingle_create_candidates(p->parent, p, p->sid, p->from); 01330 01331 return 0; 01332 } 01333 01334 /*! \brief Hangup a call through the jingle proxy channel */ 01335 static int jingle_hangup(struct ast_channel *ast) 01336 { 01337 struct jingle_pvt *p = ast->tech_pvt; 01338 struct jingle *client; 01339 01340 ast_mutex_lock(&p->lock); 01341 client = p->parent; 01342 p->owner = NULL; 01343 ast->tech_pvt = NULL; 01344 if (!p->alreadygone) 01345 jingle_action(client, p, "terminate"); 01346 ast_mutex_unlock(&p->lock); 01347 01348 jingle_free_pvt(client, p); 01349 01350 return 0; 01351 } 01352 01353 /*! \brief Part of PBX interface */ 01354 static struct ast_channel *jingle_request(const char *type, int format, void *data, int *cause) 01355 { 01356 struct jingle_pvt *p = NULL; 01357 struct jingle *client = NULL; 01358 char *sender = NULL, *to = NULL, *s = NULL; 01359 struct ast_channel *chan = NULL; 01360 01361 if (data) { 01362 s = ast_strdupa((char *) data); 01363 if (s) { 01364 sender = strsep(&s, "/"); 01365 if (sender && (sender[0] != '\0')) 01366 to = strsep(&s, "/"); 01367 if (!to) { 01368 ast_log(LOG_ERROR, "Bad arguments in Jingle Dialstring: %s\n", (char*) data); 01369 if (s) 01370 free(s); 01371 return NULL; 01372 } 01373 } 01374 } 01375 client = find_jingle(to, sender); 01376 if (!client) { 01377 ast_log(LOG_WARNING, "Could not find recipient.\n"); 01378 if (s) 01379 free(s); 01380 return NULL; 01381 } 01382 p = jingle_alloc(client, to, NULL); 01383 if (p) 01384 chan = jingle_new(client, p, AST_STATE_DOWN, to); 01385 01386 return chan; 01387 } 01388 01389 #if 0 01390 /*! \brief CLI command "jingle show channels" */ 01391 static int jingle_show(int fd, int argc, char **argv) 01392 { 01393 struct jingle_pvt *p = NULL; 01394 struct jingle *peer = NULL; 01395 struct jingle_candidate *tmp; 01396 struct jingle *client = NULL; 01397 client = ast_aji_get_client("asterisk"); 01398 if (argc != 3) 01399 return RESULT_SHOWUSAGE; 01400 ast_mutex_lock(&jinglelock); 01401 if (client) 01402 p = jingles->p; 01403 while (p) { 01404 ast_mutex_lock(&p->lock); 01405 ast_cli(fd, "SID = %s\n", p->sid); 01406 tmp = p->candidates; 01407 while (tmp) { 01408 ast_verbose("port %d\n", tmp->port); 01409 tmp = tmp->next; 01410 } 01411 ast_mutex_unlock(&p->lock); 01412 p = p->next; 01413 } 01414 if (!jingles->p) 01415 ast_cli(fd, "No jingle channels in use\n"); 01416 ast_mutex_unlock(&jinglelock); 01417 return RESULT_SUCCESS; 01418 } 01419 #endif 01420 01421 static int jingle_parser(void *data, ikspak *pak) 01422 { 01423 struct jingle *client = ASTOBJ_REF((struct jingle *) data); 01424 01425 if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", JINGLE_INITIATE)) { 01426 /* New call */ 01427 jingle_newcall(client, pak); 01428 } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", GOOGLE_NEGOTIATE)) { 01429 if (option_debug > 2) 01430 ast_log(LOG_DEBUG, "About to add candidate!\n"); 01431 jingle_add_candidate(client, pak); 01432 if (option_debug > 2) 01433 ast_log(LOG_DEBUG, "Candidate Added!\n"); 01434 } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", GOOGLE_ACCEPT)) { 01435 jingle_is_answered(client, pak); 01436 } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "content-info")) { 01437 jingle_handle_dtmf(client, pak); 01438 } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "terminate")) { 01439 jingle_hangup_farend(client, pak); 01440 } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "reject")) { 01441 jingle_hangup_farend(client, pak); 01442 } 01443 ASTOBJ_UNREF(client, jingle_member_destroy); 01444 return IKS_FILTER_EAT; 01445 } 01446 /* Not using this anymore probably take out soon 01447 static struct jingle_candidate *jingle_create_candidate(char *args) 01448 { 01449 char *name, *type, *preference, *protocol; 01450 struct jingle_candidate *res; 01451 res = malloc(sizeof(struct jingle_candidate)); 01452 memset(res, 0, sizeof(struct jingle_candidate)); 01453 if (args) 01454 name = args; 01455 if ((args = strchr(args, ','))) { 01456 *args = '\0'; 01457 args++; 01458 preference = args; 01459 } 01460 if ((args = strchr(args, ','))) { 01461 *args = '\0'; 01462 args++; 01463 protocol = args; 01464 } 01465 if ((args = strchr(args, ','))) { 01466 *args = '\0'; 01467 args++; 01468 type = args; 01469 } 01470 if (name) 01471 ast_copy_string(res->name, name, sizeof(res->name)); 01472 if (preference) { 01473 res->preference = atof(preference); 01474 } 01475 if (protocol) { 01476 if (!strcasecmp("udp", protocol)) 01477 res->protocol = AJI_PROTOCOL_UDP; 01478 if (!strcasecmp("ssltcp", protocol)) 01479 res->protocol = AJI_PROTOCOL_SSLTCP; 01480 } 01481 if (type) { 01482 if (!strcasecmp("stun", type)) 01483 res->type = AJI_CONNECT_STUN; 01484 if (!strcasecmp("local", type)) 01485 res->type = AJI_CONNECT_LOCAL; 01486 if (!strcasecmp("relay", type)) 01487 res->type = AJI_CONNECT_RELAY; 01488 } 01489 01490 return res; 01491 } 01492 */ 01493 01494 static int jingle_create_member(char *label, struct ast_variable *var, int allowguest, 01495 struct ast_codec_pref prefs, char *context, 01496 struct jingle *member) 01497 { 01498 struct aji_client *client; 01499 01500 if (!member) 01501 ast_log(LOG_WARNING, "Out of memory.\n"); 01502 01503 ast_copy_string(member->name, label, sizeof(member->name)); 01504 ast_copy_string(member->user, label, sizeof(member->user)); 01505 ast_copy_string(member->context, context, sizeof(member->context)); 01506 member->allowguest = allowguest; 01507 member->prefs = prefs; 01508 while (var) { 01509 #if 0 01510 struct jingle_candidate *candidate = NULL; 01511 #endif 01512 if (!strcasecmp(var->name, "username")) 01513 ast_copy_string(member->user, var->value, sizeof(member->user)); 01514 else if (!strcasecmp(var->name, "disallow")) 01515 ast_parse_allow_disallow(&member->prefs, &member->capability, var->value, 0); 01516 else if (!strcasecmp(var->name, "allow")) 01517 ast_parse_allow_disallow(&member->prefs, &member->capability, var->value, 1); 01518 else if (!strcasecmp(var->name, "context")) 01519 ast_copy_string(member->context, var->value, sizeof(member->context)); 01520 #if 0 01521 else if (!strcasecmp(var->name, "candidate")) { 01522 candidate = jingle_create_candidate(var->value); 01523 if (candidate) { 01524 candidate->next = member->ourcandidates; 01525 member->ourcandidates = candidate; 01526 } 01527 } 01528 #endif 01529 else if (!strcasecmp(var->name, "connection")) { 01530 if ((client = ast_aji_get_client(var->value))) { 01531 member->connection = client; 01532 iks_filter_add_rule(client->f, jingle_parser, member, IKS_RULE_TYPE, 01533 IKS_PAK_IQ, IKS_RULE_FROM_PARTIAL, member->user, 01534 IKS_RULE_NS, "http://jabber.org/protocol/jingle", 01535 IKS_RULE_DONE); 01536 } else { 01537 ast_log(LOG_ERROR, "connection referenced not found!\n"); 01538 return 0; 01539 } 01540 } 01541 var = var->next; 01542 } 01543 if (member->connection && member->user) 01544 member->buddy = ASTOBJ_CONTAINER_FIND(&member->connection->buddies, member->user); 01545 else { 01546 ast_log(LOG_ERROR, "No Connection or Username!\n"); 01547 } 01548 return 1; 01549 } 01550 01551 static int jingle_load_config(void) 01552 { 01553 char *cat = NULL; 01554 struct ast_config *cfg = NULL; 01555 char context[100]; 01556 int allowguest = 1; 01557 struct ast_variable *var; 01558 struct jingle *member; 01559 struct ast_codec_pref prefs; 01560 struct aji_client_container *clients; 01561 struct jingle_candidate *global_candidates = NULL; 01562 01563 cfg = ast_config_load(JINGLE_CONFIG); 01564 if (!cfg) 01565 return 0; 01566 01567 /* Copy the default jb config over global_jbconf */ 01568 memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf)); 01569 01570 cat = ast_category_browse(cfg, NULL); 01571 for (var = ast_variable_browse(cfg, "general"); var; var = var->next) { 01572 /* handle jb conf */ 01573 if (!ast_jb_read_conf(&global_jbconf, var->name, var->value)) 01574 continue; 01575 01576 if (!strcasecmp(var->name, "allowguest")) 01577 allowguest = 01578 (ast_true(ast_variable_retrieve(cfg, "general", "allowguest"))) ? 1 : 0; 01579 else if (!strcasecmp(var->name, "disallow")) 01580 ast_parse_allow_disallow(&prefs, &global_capability, var->value, 0); 01581 else if (!strcasecmp(var->name, "allow")) 01582 ast_parse_allow_disallow(&prefs, &global_capability, var->value, 1); 01583 else if (!strcasecmp(var->name, "context")) 01584 ast_copy_string(context, var->value, sizeof(context)); 01585 else if (!strcasecmp(var->name, "externip")) 01586 ast_copy_string(externip, var->value, sizeof(externip)); 01587 /* Idea to allow for custom candidates */ 01588 /* 01589 else if (!strcasecmp(var->name, "candidate")) { 01590 candidate = jingle_create_candidate(var->value); 01591 if (candidate) { 01592 candidate->next = global_candidates; 01593 global_candidates = candidate; 01594 } 01595 } 01596 */ 01597 } 01598 while (cat) { 01599 if (strcasecmp(cat, "general")) { 01600 var = ast_variable_browse(cfg, cat); 01601 member = (struct jingle *) malloc(sizeof(struct jingle)); 01602 memset(member, 0, sizeof(struct jingle)); 01603 ASTOBJ_INIT(member); 01604 ASTOBJ_WRLOCK(member); 01605 if (!strcasecmp(cat, "guest")) { 01606 ast_copy_string(member->name, "guest", sizeof(member->name)); 01607 ast_copy_string(member->user, "guest", sizeof(member->user)); 01608 ast_copy_string(member->context, context, sizeof(member->context)); 01609 member->allowguest = allowguest; 01610 member->prefs = prefs; 01611 while (var) { 01612 if (!strcasecmp(var->name, "disallow")) 01613 ast_parse_allow_disallow(&member->prefs, &member->capability, 01614 var->value, 0); 01615 else if (!strcasecmp(var->name, "allow")) 01616 ast_parse_allow_disallow(&member->prefs, &member->capability, 01617 var->value, 1); 01618 else if (!strcasecmp(var->name, "context")) 01619 ast_copy_string(member->context, var->value, 01620 sizeof(member->context)); 01621 /* Idea to allow for custom candidates */ 01622 /* 01623 else if (!strcasecmp(var->name, "candidate")) { 01624 candidate = jingle_create_candidate(var->value); 01625 if (candidate) { 01626 candidate->next = member->ourcandidates; 01627 member->ourcandidates = candidate; 01628 } 01629 } 01630 */ 01631 var = var->next; 01632 } 01633 ASTOBJ_UNLOCK(member); 01634 clients = ast_aji_get_clients(); 01635 if (clients) { 01636 ASTOBJ_CONTAINER_TRAVERSE(clients, 1, { 01637 ASTOBJ_WRLOCK(iterator); 01638 ASTOBJ_WRLOCK(member); 01639 member->connection = iterator; 01640 iks_filter_add_rule(iterator->f, jingle_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, 01641 "http://jabber.org/protocol/jingle", IKS_RULE_DONE); 01642 ASTOBJ_UNLOCK(member); 01643 ASTOBJ_CONTAINER_LINK(&jingles, member); 01644 ASTOBJ_UNLOCK(iterator); 01645 }); 01646 } else { 01647 ASTOBJ_UNLOCK(member); 01648 ASTOBJ_UNREF(member, jingle_member_destroy); 01649 } 01650 } else { 01651 ASTOBJ_UNLOCK(member); 01652 if (jingle_create_member(cat, var, allowguest, prefs, context, member)) 01653 ASTOBJ_CONTAINER_LINK(&jingles, member); 01654 ASTOBJ_UNREF(member, jingle_member_destroy); 01655 } 01656 } 01657 cat = ast_category_browse(cfg, cat); 01658 } 01659 jingle_free_candidates(global_candidates); 01660 return 1; 01661 } 01662 01663 /*! \brief Load module into PBX, register channel */ 01664 static int load_module(void) 01665 { 01666 ASTOBJ_CONTAINER_INIT(&jingles); 01667 if (!jingle_load_config()) { 01668 ast_log(LOG_ERROR, "Unable to read config file %s. Not loading module.\n", JINGLE_CONFIG); 01669 return AST_MODULE_LOAD_DECLINE; 01670 } 01671 01672 sched = sched_context_create(); 01673 if (!sched) 01674 ast_log(LOG_WARNING, "Unable to create schedule context\n"); 01675 01676 io = io_context_create(); 01677 if (!io) 01678 ast_log(LOG_WARNING, "Unable to create I/O context\n"); 01679 01680 if (ast_find_ourip(&__ourip, bindaddr)) { 01681 ast_log(LOG_WARNING, "Unable to get own IP address, Jingle disabled\n"); 01682 return 0; 01683 } 01684 01685 ast_rtp_proto_register(&jingle_rtp); 01686 01687 /* Make sure we can register our channel type */ 01688 if (ast_channel_register(&jingle_tech)) { 01689 ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); 01690 return -1; 01691 } 01692 return 0; 01693 } 01694 01695 /*! \brief Reload module */ 01696 static int reload(void) 01697 { 01698 return 0; 01699 } 01700 01701 /*! \brief Unload the jingle channel from Asterisk */ 01702 static int unload_module(void) 01703 { 01704 struct jingle_pvt *privates = NULL; 01705 01706 /* First, take us out of the channel loop */ 01707 ast_channel_unregister(&jingle_tech); 01708 ast_rtp_proto_unregister(&jingle_rtp); 01709 01710 if (!ast_mutex_lock(&jinglelock)) { 01711 /* Hangup all interfaces if they have an owner */ 01712 ASTOBJ_CONTAINER_TRAVERSE(&jingles, 1, { 01713 ASTOBJ_WRLOCK(iterator); 01714 privates = iterator->p; 01715 while(privates) { 01716 if (privates->owner) 01717 ast_softhangup(privates->owner, AST_SOFTHANGUP_APPUNLOAD); 01718 privates = privates->next; 01719 } 01720 iterator->p = NULL; 01721 ASTOBJ_UNLOCK(iterator); 01722 }); 01723 ast_mutex_unlock(&jinglelock); 01724 } else { 01725 ast_log(LOG_WARNING, "Unable to lock the monitor\n"); 01726 return -1; 01727 } 01728 ASTOBJ_CONTAINER_DESTROYALL(&jingles, jingle_member_destroy); 01729 ASTOBJ_CONTAINER_DESTROY(&jingles); 01730 return 0; 01731 } 01732 01733 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Jingle Channel Driver", 01734 .load = load_module, 01735 .unload = unload_module, 01736 .reload = reload, 01737 );