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 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 358907 $")
00033
00034 #include <unistd.h>
00035 #include <fcntl.h>
00036
00037 #include "asterisk/channel.h"
00038 #include "asterisk/stringfields.h"
00039 #include "asterisk/data.h"
00040 #include "asterisk/indications.h"
00041 #include "asterisk/channel_internal.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 struct ast_channel {
00058 const struct ast_channel_tech *tech;
00059 void *tech_pvt;
00060 void *music_state;
00061 void *generatordata;
00062 struct ast_generator *generator;
00063 struct ast_channel * bridged_channel;
00064
00065
00066 struct ast_channel *masq;
00067 struct ast_channel *masqr;
00068 const char *blockproc;
00069 const char *appl;
00070 const char *data;
00071 struct ast_sched_context *sched;
00072 struct ast_filestream *stream;
00073 struct ast_filestream *vstream;
00074 ast_timing_func_t timingfunc;
00075 void *timingdata;
00076 struct ast_pbx *pbx;
00077 struct ast_trans_pvt *writetrans;
00078 struct ast_trans_pvt *readtrans;
00079 struct ast_audiohook_list *audiohooks;
00080 struct ast_framehook_list *framehooks;
00081 struct ast_cdr *cdr;
00082 struct ast_tone_zone *zone;
00083
00084 struct ast_channel_monitor *monitor;
00085 #ifdef HAVE_EPOLL
00086 struct ast_epoll_data *epfd_data[AST_MAX_FDS];
00087 #endif
00088
00089 AST_DECLARE_STRING_FIELDS(
00090 AST_STRING_FIELD(name);
00091 AST_STRING_FIELD(language);
00092 AST_STRING_FIELD(musicclass);
00093 AST_STRING_FIELD(accountcode);
00094 AST_STRING_FIELD(peeraccount);
00095 AST_STRING_FIELD(userfield);
00096 AST_STRING_FIELD(call_forward);
00097 AST_STRING_FIELD(uniqueid);
00098 AST_STRING_FIELD(linkedid);
00099 AST_STRING_FIELD(parkinglot);
00100 AST_STRING_FIELD(hangupsource);
00101 AST_STRING_FIELD(dialcontext);
00102 );
00103
00104 struct timeval whentohangup;
00105 pthread_t blocker;
00106
00107
00108
00109
00110
00111
00112 struct ast_party_dialed dialed;
00113
00114
00115
00116
00117
00118
00119 struct ast_party_caller caller;
00120
00121
00122
00123
00124
00125
00126 struct ast_party_connected_line connected;
00127
00128
00129 struct ast_party_redirecting redirecting;
00130
00131 struct ast_frame dtmff;
00132 struct varshead varshead;
00133 ast_group_t callgroup;
00134 ast_group_t pickupgroup;
00135 struct ast_readq_list readq;
00136 struct ast_jb jb;
00137 struct timeval dtmf_tv;
00138 struct ast_datastore_list datastores;
00139 struct ast_autochan_list autochans;
00140 unsigned long insmpl;
00141 unsigned long outsmpl;
00142
00143 int fds[AST_MAX_FDS];
00144
00145
00146 int softhangup;
00147
00148 int fdno;
00149 int streamid;
00150 int vstreamid;
00151 struct ast_format oldwriteformat;
00152 int timingfd;
00153 enum ast_channel_state state;
00154 int rings;
00155 int priority;
00156 int macropriority;
00157 int amaflags;
00158 enum ast_channel_adsicpe adsicpe;
00159 unsigned int fin;
00160
00161 unsigned int fout;
00162
00163 int hangupcause;
00164 unsigned int finalized:1;
00165 struct ast_flags flags;
00166 int alertpipe[2];
00167 struct ast_format_cap *nativeformats;
00168 struct ast_format readformat;
00169 struct ast_format writeformat;
00170 struct ast_format rawreadformat;
00171 struct ast_format rawwriteformat;
00172 unsigned int emulate_dtmf_duration;
00173 #ifdef HAVE_EPOLL
00174 int epfd;
00175 #endif
00176 int visible_indication;
00177
00178 unsigned short transfercapability;
00179
00180 struct ast_bridge *bridge;
00181 struct ast_timer *timer;
00182
00183 char context[AST_MAX_CONTEXT];
00184 char exten[AST_MAX_EXTENSION];
00185 char macrocontext[AST_MAX_CONTEXT];
00186 char macroexten[AST_MAX_EXTENSION];
00187 char dtmf_digit_to_emulate;
00188 };
00189
00190
00191
00192 #if 0
00193 #define DATA_EXPORT_CALLERID(MEMBER) \
00194 MEMBER(ast_callerid, cid_dnid, AST_DATA_STRING) \
00195 MEMBER(ast_callerid, cid_num, AST_DATA_STRING) \
00196 MEMBER(ast_callerid, cid_name, AST_DATA_STRING) \
00197 MEMBER(ast_callerid, cid_ani, AST_DATA_STRING) \
00198 MEMBER(ast_callerid, cid_pres, AST_DATA_INTEGER) \
00199 MEMBER(ast_callerid, cid_ani2, AST_DATA_INTEGER) \
00200 MEMBER(ast_callerid, cid_tag, AST_DATA_STRING)
00201
00202 AST_DATA_STRUCTURE(ast_callerid, DATA_EXPORT_CALLERID);
00203 #endif
00204
00205 #define DATA_EXPORT_CHANNEL(MEMBER) \
00206 MEMBER(ast_channel, blockproc, AST_DATA_STRING) \
00207 MEMBER(ast_channel, appl, AST_DATA_STRING) \
00208 MEMBER(ast_channel, data, AST_DATA_STRING) \
00209 MEMBER(ast_channel, name, AST_DATA_STRING) \
00210 MEMBER(ast_channel, language, AST_DATA_STRING) \
00211 MEMBER(ast_channel, musicclass, AST_DATA_STRING) \
00212 MEMBER(ast_channel, accountcode, AST_DATA_STRING) \
00213 MEMBER(ast_channel, peeraccount, AST_DATA_STRING) \
00214 MEMBER(ast_channel, userfield, AST_DATA_STRING) \
00215 MEMBER(ast_channel, call_forward, AST_DATA_STRING) \
00216 MEMBER(ast_channel, uniqueid, AST_DATA_STRING) \
00217 MEMBER(ast_channel, linkedid, AST_DATA_STRING) \
00218 MEMBER(ast_channel, parkinglot, AST_DATA_STRING) \
00219 MEMBER(ast_channel, hangupsource, AST_DATA_STRING) \
00220 MEMBER(ast_channel, dialcontext, AST_DATA_STRING) \
00221 MEMBER(ast_channel, rings, AST_DATA_INTEGER) \
00222 MEMBER(ast_channel, priority, AST_DATA_INTEGER) \
00223 MEMBER(ast_channel, macropriority, AST_DATA_INTEGER) \
00224 MEMBER(ast_channel, adsicpe, AST_DATA_INTEGER) \
00225 MEMBER(ast_channel, fin, AST_DATA_UNSIGNED_INTEGER) \
00226 MEMBER(ast_channel, fout, AST_DATA_UNSIGNED_INTEGER) \
00227 MEMBER(ast_channel, emulate_dtmf_duration, AST_DATA_UNSIGNED_INTEGER) \
00228 MEMBER(ast_channel, visible_indication, AST_DATA_INTEGER) \
00229 MEMBER(ast_channel, context, AST_DATA_STRING) \
00230 MEMBER(ast_channel, exten, AST_DATA_STRING) \
00231 MEMBER(ast_channel, macrocontext, AST_DATA_STRING) \
00232 MEMBER(ast_channel, macroexten, AST_DATA_STRING)
00233
00234 AST_DATA_STRUCTURE(ast_channel, DATA_EXPORT_CHANNEL);
00235
00236 static void channel_data_add_flags(struct ast_data *tree,
00237 struct ast_channel *chan)
00238 {
00239 ast_data_add_bool(tree, "DEFER_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF));
00240 ast_data_add_bool(tree, "WRITE_INT", ast_test_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT));
00241 ast_data_add_bool(tree, "BLOCKING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING));
00242 ast_data_add_bool(tree, "ZOMBIE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE));
00243 ast_data_add_bool(tree, "EXCEPTION", ast_test_flag(ast_channel_flags(chan), AST_FLAG_EXCEPTION));
00244 ast_data_add_bool(tree, "MOH", ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH));
00245 ast_data_add_bool(tree, "SPYING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_SPYING));
00246 ast_data_add_bool(tree, "NBRIDGE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_NBRIDGE));
00247 ast_data_add_bool(tree, "IN_AUTOLOOP", ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP));
00248 ast_data_add_bool(tree, "OUTGOING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING));
00249 ast_data_add_bool(tree, "IN_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF));
00250 ast_data_add_bool(tree, "EMULATE_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF));
00251 ast_data_add_bool(tree, "END_DTMF_ONLY", ast_test_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY));
00252 ast_data_add_bool(tree, "ANSWERED_ELSEWHERE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_ANSWERED_ELSEWHERE));
00253 ast_data_add_bool(tree, "MASQ_NOSTREAM", ast_test_flag(ast_channel_flags(chan), AST_FLAG_MASQ_NOSTREAM));
00254 ast_data_add_bool(tree, "BRIDGE_HANGUP_RUN", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_HANGUP_RUN));
00255 ast_data_add_bool(tree, "BRIDGE_HANGUP_DONT", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_HANGUP_DONT));
00256 ast_data_add_bool(tree, "DISABLE_WORKAROUNDS", ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS));
00257 }
00258
00259 int ast_channel_data_add_structure(struct ast_data *tree,
00260 struct ast_channel *chan, int add_bridged)
00261 {
00262 struct ast_channel *bc;
00263 struct ast_data *data_bridged;
00264 struct ast_data *data_cdr;
00265 struct ast_data *data_flags;
00266 struct ast_data *data_zones;
00267 struct ast_data *enum_node;
00268 struct ast_data *data_softhangup;
00269 #if 0
00270 struct ast_data *data_callerid;
00271 char value_str[100];
00272 #endif
00273
00274 if (!tree) {
00275 return -1;
00276 }
00277
00278 ast_data_add_structure(ast_channel, tree, chan);
00279
00280 if (add_bridged) {
00281 bc = ast_bridged_channel(chan);
00282 if (bc) {
00283 data_bridged = ast_data_add_node(tree, "bridged");
00284 if (!data_bridged) {
00285 return -1;
00286 }
00287 ast_channel_data_add_structure(data_bridged, bc, 0);
00288 }
00289 }
00290
00291 ast_data_add_codec(tree, "oldwriteformat", ast_channel_oldwriteformat(chan));
00292 ast_data_add_codec(tree, "readformat", ast_channel_readformat(chan));
00293 ast_data_add_codec(tree, "writeformat", ast_channel_writeformat(chan));
00294 ast_data_add_codec(tree, "rawreadformat", ast_channel_rawreadformat(chan));
00295 ast_data_add_codec(tree, "rawwriteformat", ast_channel_rawwriteformat(chan));
00296 ast_data_add_codecs(tree, "nativeformats", ast_channel_nativeformats(chan));
00297
00298
00299 enum_node = ast_data_add_node(tree, "state");
00300 if (!enum_node) {
00301 return -1;
00302 }
00303 ast_data_add_str(enum_node, "text", ast_state2str(ast_channel_state(chan)));
00304 ast_data_add_int(enum_node, "value", ast_channel_state(chan));
00305
00306
00307 enum_node = ast_data_add_node(tree, "hangupcause");
00308 if (!enum_node) {
00309 return -1;
00310 }
00311 ast_data_add_str(enum_node, "text", ast_cause2str(ast_channel_hangupcause(chan)));
00312 ast_data_add_int(enum_node, "value", ast_channel_hangupcause(chan));
00313
00314
00315 enum_node = ast_data_add_node(tree, "amaflags");
00316 if (!enum_node) {
00317 return -1;
00318 }
00319 ast_data_add_str(enum_node, "text", ast_cdr_flags2str(ast_channel_amaflags(chan)));
00320 ast_data_add_int(enum_node, "value", ast_channel_amaflags(chan));
00321
00322
00323 enum_node = ast_data_add_node(tree, "transfercapability");
00324 if (!enum_node) {
00325 return -1;
00326 }
00327 ast_data_add_str(enum_node, "text", ast_transfercapability2str(ast_channel_transfercapability(chan)));
00328 ast_data_add_int(enum_node, "value", ast_channel_transfercapability(chan));
00329
00330
00331 data_softhangup = ast_data_add_node(tree, "softhangup");
00332 if (!data_softhangup) {
00333 return -1;
00334 }
00335 ast_data_add_bool(data_softhangup, "dev", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_DEV);
00336 ast_data_add_bool(data_softhangup, "asyncgoto", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO);
00337 ast_data_add_bool(data_softhangup, "shutdown", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_SHUTDOWN);
00338 ast_data_add_bool(data_softhangup, "timeout", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_TIMEOUT);
00339 ast_data_add_bool(data_softhangup, "appunload", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_APPUNLOAD);
00340 ast_data_add_bool(data_softhangup, "explicit", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_EXPLICIT);
00341 ast_data_add_bool(data_softhangup, "unbridge", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_UNBRIDGE);
00342
00343
00344 data_flags = ast_data_add_node(tree, "flags");
00345 if (!data_flags) {
00346 return -1;
00347 }
00348 channel_data_add_flags(data_flags, chan);
00349
00350 ast_data_add_uint(tree, "timetohangup", ast_channel_whentohangup(chan)->tv_sec);
00351
00352 #if 0
00353
00354 data_callerid = ast_data_add_node(tree, "callerid");
00355 if (!data_callerid) {
00356 return -1;
00357 }
00358 ast_data_add_structure(ast_callerid, data_callerid, &(chan->cid));
00359
00360 enum_node = ast_data_add_node(data_callerid, "cid_ton");
00361 if (!enum_node) {
00362 return -1;
00363 }
00364 ast_data_add_int(enum_node, "value", chan->cid.cid_ton);
00365 snprintf(value_str, sizeof(value_str), "TON: %s/Plan: %s",
00366 party_number_ton2str(chan->cid.cid_ton),
00367 party_number_plan2str(chan->cid.cid_ton));
00368 ast_data_add_str(enum_node, "text", value_str);
00369 #endif
00370
00371
00372 if (ast_channel_zone(chan)) {
00373 data_zones = ast_data_add_node(tree, "zone");
00374 if (!data_zones) {
00375 return -1;
00376 }
00377 ast_tone_zone_data_add_structure(data_zones, ast_channel_zone(chan));
00378 }
00379
00380
00381 data_cdr = ast_data_add_node(tree, "cdr");
00382 if (!data_cdr) {
00383 return -1;
00384 }
00385
00386 ast_cdr_data_add_structure(data_cdr, ast_channel_cdr(chan), 1);
00387
00388 return 0;
00389 }
00390
00391 int ast_channel_data_cmp_structure(const struct ast_data_search *tree,
00392 struct ast_channel *chan, const char *structure_name)
00393 {
00394 return ast_data_search_cmp_structure(tree, ast_channel, chan, structure_name);
00395 }
00396
00397
00398
00399 #define DEFINE_STRINGFIELD_SETTERS_FOR(field) \
00400 void ast_channel_##field##_set(struct ast_channel *chan, const char *value) \
00401 { \
00402 ast_string_field_set(chan, field, value); \
00403 } \
00404 \
00405 void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) \
00406 { \
00407 ast_string_field_build_va(chan, field, fmt, ap); \
00408 } \
00409 void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) \
00410 { \
00411 va_list ap; \
00412 va_start(ap, fmt); \
00413 ast_channel_##field##_build_va(chan, fmt, ap); \
00414 va_end(ap); \
00415 }
00416
00417 DEFINE_STRINGFIELD_SETTERS_FOR(name);
00418 DEFINE_STRINGFIELD_SETTERS_FOR(language);
00419 DEFINE_STRINGFIELD_SETTERS_FOR(musicclass);
00420 DEFINE_STRINGFIELD_SETTERS_FOR(accountcode);
00421 DEFINE_STRINGFIELD_SETTERS_FOR(peeraccount);
00422 DEFINE_STRINGFIELD_SETTERS_FOR(userfield);
00423 DEFINE_STRINGFIELD_SETTERS_FOR(call_forward);
00424 DEFINE_STRINGFIELD_SETTERS_FOR(uniqueid);
00425 DEFINE_STRINGFIELD_SETTERS_FOR(linkedid);
00426 DEFINE_STRINGFIELD_SETTERS_FOR(parkinglot);
00427 DEFINE_STRINGFIELD_SETTERS_FOR(hangupsource);
00428 DEFINE_STRINGFIELD_SETTERS_FOR(dialcontext);
00429
00430 #define DEFINE_STRINGFIELD_GETTER_FOR(field) const char *ast_channel_##field(const struct ast_channel *chan) \
00431 { \
00432 return chan->field; \
00433 }
00434
00435 DEFINE_STRINGFIELD_GETTER_FOR(name);
00436 DEFINE_STRINGFIELD_GETTER_FOR(language);
00437 DEFINE_STRINGFIELD_GETTER_FOR(musicclass);
00438 DEFINE_STRINGFIELD_GETTER_FOR(accountcode);
00439 DEFINE_STRINGFIELD_GETTER_FOR(peeraccount);
00440 DEFINE_STRINGFIELD_GETTER_FOR(userfield);
00441 DEFINE_STRINGFIELD_GETTER_FOR(call_forward);
00442 DEFINE_STRINGFIELD_GETTER_FOR(uniqueid);
00443 DEFINE_STRINGFIELD_GETTER_FOR(linkedid);
00444 DEFINE_STRINGFIELD_GETTER_FOR(parkinglot);
00445 DEFINE_STRINGFIELD_GETTER_FOR(hangupsource);
00446 DEFINE_STRINGFIELD_GETTER_FOR(dialcontext);
00447
00448 const char *ast_channel_appl(const struct ast_channel *chan)
00449 {
00450 return chan->appl;
00451 }
00452 void ast_channel_appl_set(struct ast_channel *chan, const char *value)
00453 {
00454 chan->appl = value;
00455 }
00456 const char *ast_channel_blockproc(const struct ast_channel *chan)
00457 {
00458 return chan->blockproc;
00459 }
00460 void ast_channel_blockproc_set(struct ast_channel *chan, const char *value)
00461 {
00462 chan->blockproc = value;
00463 }
00464 const char *ast_channel_data(const struct ast_channel *chan)
00465 {
00466 return chan->data;
00467 }
00468 void ast_channel_data_set(struct ast_channel *chan, const char *value)
00469 {
00470 chan->data = value;
00471 }
00472
00473 const char *ast_channel_context(const struct ast_channel *chan)
00474 {
00475 return chan->context;
00476 }
00477 void ast_channel_context_set(struct ast_channel *chan, const char *value)
00478 {
00479 ast_copy_string(chan->context, value, sizeof(chan->context));
00480 }
00481 const char *ast_channel_exten(const struct ast_channel *chan)
00482 {
00483 return chan->exten;
00484 }
00485 void ast_channel_exten_set(struct ast_channel *chan, const char *value)
00486 {
00487 ast_copy_string(chan->exten, value, sizeof(chan->exten));
00488 }
00489 const char *ast_channel_macrocontext(const struct ast_channel *chan)
00490 {
00491 return chan->macrocontext;
00492 }
00493 void ast_channel_macrocontext_set(struct ast_channel *chan, const char *value)
00494 {
00495 ast_copy_string(chan->macrocontext, value, sizeof(chan->macrocontext));
00496 }
00497 const char *ast_channel_macroexten(const struct ast_channel *chan)
00498 {
00499 return chan->macroexten;
00500 }
00501 void ast_channel_macroexten_set(struct ast_channel *chan, const char *value)
00502 {
00503 ast_copy_string(chan->macroexten, value, sizeof(chan->macroexten));
00504 }
00505
00506 char ast_channel_dtmf_digit_to_emulate(const struct ast_channel *chan)
00507 {
00508 return chan->dtmf_digit_to_emulate;
00509 }
00510 void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value)
00511 {
00512 chan->dtmf_digit_to_emulate = value;
00513 }
00514 int ast_channel_amaflags(const struct ast_channel *chan)
00515 {
00516 return chan->amaflags;
00517 }
00518 void ast_channel_amaflags_set(struct ast_channel *chan, int value)
00519 {
00520 chan->amaflags = value;
00521 }
00522 #ifdef HAVE_EPOLL
00523 int ast_channel_epfd(const struct ast_channel *chan)
00524 {
00525 return chan->epfd;
00526 }
00527 void ast_channel_epfd_set(struct ast_channel *chan, int value)
00528 {
00529 chan->epfd = value;
00530 }
00531 #endif
00532 int ast_channel_fdno(const struct ast_channel *chan)
00533 {
00534 return chan->fdno;
00535 }
00536 void ast_channel_fdno_set(struct ast_channel *chan, int value)
00537 {
00538 chan->fdno = value;
00539 }
00540 int ast_channel_hangupcause(const struct ast_channel *chan)
00541 {
00542 return chan->hangupcause;
00543 }
00544 void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
00545 {
00546 chan->hangupcause = value;
00547 }
00548 int ast_channel_macropriority(const struct ast_channel *chan)
00549 {
00550 return chan->macropriority;
00551 }
00552 void ast_channel_macropriority_set(struct ast_channel *chan, int value)
00553 {
00554 chan->macropriority = value;
00555 }
00556 int ast_channel_priority(const struct ast_channel *chan)
00557 {
00558 return chan->priority;
00559 }
00560 void ast_channel_priority_set(struct ast_channel *chan, int value)
00561 {
00562 chan->priority = value;
00563 }
00564 int ast_channel_rings(const struct ast_channel *chan)
00565 {
00566 return chan->rings;
00567 }
00568 void ast_channel_rings_set(struct ast_channel *chan, int value)
00569 {
00570 chan->rings = value;
00571 }
00572 int ast_channel_streamid(const struct ast_channel *chan)
00573 {
00574 return chan->streamid;
00575 }
00576 void ast_channel_streamid_set(struct ast_channel *chan, int value)
00577 {
00578 chan->streamid = value;
00579 }
00580 int ast_channel_timingfd(const struct ast_channel *chan)
00581 {
00582 return chan->timingfd;
00583 }
00584 void ast_channel_timingfd_set(struct ast_channel *chan, int value)
00585 {
00586 chan->timingfd = value;
00587 }
00588 int ast_channel_visible_indication(const struct ast_channel *chan)
00589 {
00590 return chan->visible_indication;
00591 }
00592 void ast_channel_visible_indication_set(struct ast_channel *chan, int value)
00593 {
00594 chan->visible_indication = value;
00595 }
00596 int ast_channel_vstreamid(const struct ast_channel *chan)
00597 {
00598 return chan->vstreamid;
00599 }
00600 void ast_channel_vstreamid_set(struct ast_channel *chan, int value)
00601 {
00602 chan->vstreamid = value;
00603 }
00604 unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
00605 {
00606 return chan->transfercapability;
00607 }
00608 void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
00609 {
00610 chan->transfercapability = value;
00611 }
00612 unsigned int ast_channel_emulate_dtmf_duration(const struct ast_channel *chan)
00613 {
00614 return chan->emulate_dtmf_duration;
00615 }
00616 void ast_channel_emulate_dtmf_duration_set(struct ast_channel *chan, unsigned int value)
00617 {
00618 chan->emulate_dtmf_duration = value;
00619 }
00620 unsigned int ast_channel_fin(const struct ast_channel *chan)
00621 {
00622 return chan->fin;
00623 }
00624 void ast_channel_fin_set(struct ast_channel *chan, unsigned int value)
00625 {
00626 chan->fin = value;
00627 }
00628 unsigned int ast_channel_fout(const struct ast_channel *chan)
00629 {
00630 return chan->fout;
00631 }
00632 void ast_channel_fout_set(struct ast_channel *chan, unsigned int value)
00633 {
00634 chan->fout = value;
00635 }
00636 unsigned long ast_channel_insmpl(const struct ast_channel *chan)
00637 {
00638 return chan->insmpl;
00639 }
00640 void ast_channel_insmpl_set(struct ast_channel *chan, unsigned long value)
00641 {
00642 chan->insmpl = value;
00643 }
00644 unsigned long ast_channel_outsmpl(const struct ast_channel *chan)
00645 {
00646 return chan->outsmpl;
00647 }
00648 void ast_channel_outsmpl_set(struct ast_channel *chan, unsigned long value)
00649 {
00650 chan->outsmpl = value;
00651 }
00652 void *ast_channel_generatordata(const struct ast_channel *chan)
00653 {
00654 return chan->generatordata;
00655 }
00656 void ast_channel_generatordata_set(struct ast_channel *chan, void *value)
00657 {
00658 chan->generatordata = value;
00659 }
00660 void *ast_channel_music_state(const struct ast_channel *chan)
00661 {
00662 return chan->music_state;
00663 }
00664 void ast_channel_music_state_set(struct ast_channel *chan, void *value)
00665 {
00666 chan->music_state = value;
00667 }
00668 void *ast_channel_tech_pvt(const struct ast_channel *chan)
00669 {
00670 return chan->tech_pvt;
00671 }
00672 void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
00673 {
00674 chan->tech_pvt = value;
00675 }
00676 void *ast_channel_timingdata(const struct ast_channel *chan)
00677 {
00678 return chan->timingdata;
00679 }
00680 void ast_channel_timingdata_set(struct ast_channel *chan, void *value)
00681 {
00682 chan->timingdata = value;
00683 }
00684 struct ast_audiohook_list *ast_channel_audiohooks(const struct ast_channel *chan)
00685 {
00686 return chan->audiohooks;
00687 }
00688 void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
00689 {
00690 chan->audiohooks = value;
00691 }
00692 struct ast_cdr *ast_channel_cdr(const struct ast_channel *chan)
00693 {
00694 return chan->cdr;
00695 }
00696 void ast_channel_cdr_set(struct ast_channel *chan, struct ast_cdr *value)
00697 {
00698 chan->cdr = value;
00699 }
00700 struct ast_channel *ast_channel_masq(const struct ast_channel *chan)
00701 {
00702 return chan->masq;
00703 }
00704 void ast_channel_masq_set(struct ast_channel *chan, struct ast_channel *value)
00705 {
00706 chan->masq = value;
00707 }
00708 struct ast_channel *ast_channel_masqr(const struct ast_channel *chan)
00709 {
00710 return chan->masqr;
00711 }
00712 void ast_channel_masqr_set(struct ast_channel *chan, struct ast_channel *value)
00713 {
00714 chan->masqr = value;
00715 }
00716 struct ast_channel_monitor *ast_channel_monitor(const struct ast_channel *chan)
00717 {
00718 return chan->monitor;
00719 }
00720 void ast_channel_monitor_set(struct ast_channel *chan, struct ast_channel_monitor *value)
00721 {
00722 chan->monitor = value;
00723 }
00724 struct ast_filestream *ast_channel_stream(const struct ast_channel *chan)
00725 {
00726 return chan->stream;
00727 }
00728 void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
00729 {
00730 chan->stream = value;
00731 }
00732 struct ast_filestream *ast_channel_vstream(const struct ast_channel *chan)
00733 {
00734 return chan->vstream;
00735 }
00736 void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value)
00737 {
00738 chan->vstream = value;
00739 }
00740 struct ast_format_cap *ast_channel_nativeformats(const struct ast_channel *chan)
00741 {
00742 return chan->nativeformats;
00743 }
00744 void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
00745 {
00746 chan->nativeformats = value;
00747 }
00748 struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan)
00749 {
00750 return chan->framehooks;
00751 }
00752 void ast_channel_framehooks_set(struct ast_channel *chan, struct ast_framehook_list *value)
00753 {
00754 chan->framehooks = value;
00755 }
00756 struct ast_generator *ast_channel_generator(const struct ast_channel *chan)
00757 {
00758 return chan->generator;
00759 }
00760 void ast_channel_generator_set(struct ast_channel *chan, struct ast_generator *value)
00761 {
00762 chan->generator = value;
00763 }
00764 struct ast_pbx *ast_channel_pbx(const struct ast_channel *chan)
00765 {
00766 return chan->pbx;
00767 }
00768 void ast_channel_pbx_set(struct ast_channel *chan, struct ast_pbx *value)
00769 {
00770 chan->pbx = value;
00771 }
00772 struct ast_sched_context *ast_channel_sched(const struct ast_channel *chan)
00773 {
00774 return chan->sched;
00775 }
00776 void ast_channel_sched_set(struct ast_channel *chan, struct ast_sched_context *value)
00777 {
00778 chan->sched = value;
00779 }
00780 struct ast_timer *ast_channel_timer(const struct ast_channel *chan)
00781 {
00782 return chan->timer;
00783 }
00784 void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value)
00785 {
00786 chan->timer = value;
00787 }
00788 struct ast_tone_zone *ast_channel_zone(const struct ast_channel *chan)
00789 {
00790 return chan->zone;
00791 }
00792 void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
00793 {
00794 chan->zone = value;
00795 }
00796 struct ast_trans_pvt *ast_channel_readtrans(const struct ast_channel *chan)
00797 {
00798 return chan->readtrans;
00799 }
00800 void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
00801 {
00802 chan->readtrans = value;
00803 }
00804 struct ast_trans_pvt *ast_channel_writetrans(const struct ast_channel *chan)
00805 {
00806 return chan->writetrans;
00807 }
00808 void ast_channel_writetrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
00809 {
00810 chan->writetrans = value;
00811 }
00812 const struct ast_channel_tech *ast_channel_tech(const struct ast_channel *chan)
00813 {
00814 return chan->tech;
00815 }
00816 void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
00817 {
00818 chan->tech = value;
00819 }
00820 enum ast_channel_adsicpe ast_channel_adsicpe(const struct ast_channel *chan)
00821 {
00822 return chan->adsicpe;
00823 }
00824 void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
00825 {
00826 chan->adsicpe = value;
00827 }
00828 enum ast_channel_state ast_channel_state(const struct ast_channel *chan)
00829 {
00830 return chan->state;
00831 }
00832 void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state value)
00833 {
00834 chan->state = value;
00835 }
00836 struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan)
00837 {
00838 return &chan->oldwriteformat;
00839 }
00840 struct ast_format *ast_channel_rawreadformat(struct ast_channel *chan)
00841 {
00842 return &chan->rawreadformat;
00843 }
00844 struct ast_format *ast_channel_rawwriteformat(struct ast_channel *chan)
00845 {
00846 return &chan->rawwriteformat;
00847 }
00848 struct ast_format *ast_channel_readformat(struct ast_channel *chan)
00849 {
00850 return &chan->readformat;
00851 }
00852 struct ast_format *ast_channel_writeformat(struct ast_channel *chan)
00853 {
00854 return &chan->writeformat;
00855 }
00856 struct ast_datastore_list *ast_channel_datastores(struct ast_channel *chan)
00857 {
00858 return &chan->datastores;
00859 }
00860 struct ast_autochan_list *ast_channel_autochans(struct ast_channel *chan)
00861 {
00862 return &chan->autochans;
00863 }
00864 struct ast_readq_list *ast_channel_readq(struct ast_channel *chan)
00865 {
00866 return &chan->readq;
00867 }
00868 struct ast_frame *ast_channel_dtmff(struct ast_channel *chan)
00869 {
00870 return &chan->dtmff;
00871 }
00872 struct ast_jb *ast_channel_jb(struct ast_channel *chan)
00873 {
00874 return &chan->jb;
00875 }
00876 struct ast_party_caller *ast_channel_caller(struct ast_channel *chan)
00877 {
00878 return &chan->caller;
00879 }
00880 struct ast_party_connected_line *ast_channel_connected(struct ast_channel *chan)
00881 {
00882 return &chan->connected;
00883 }
00884 struct ast_party_dialed *ast_channel_dialed(struct ast_channel *chan)
00885 {
00886 return &chan->dialed;
00887 }
00888 struct ast_party_redirecting *ast_channel_redirecting(struct ast_channel *chan)
00889 {
00890 return &chan->redirecting;
00891 }
00892 struct timeval *ast_channel_dtmf_tv(struct ast_channel *chan)
00893 {
00894 return &chan->dtmf_tv;
00895 }
00896 struct timeval *ast_channel_whentohangup(struct ast_channel *chan)
00897 {
00898 return &chan->whentohangup;
00899 }
00900 struct varshead *ast_channel_varshead(struct ast_channel *chan)
00901 {
00902 return &chan->varshead;
00903 }
00904 void ast_channel_dtmff_set(struct ast_channel *chan, struct ast_frame *value)
00905 {
00906 chan->dtmff = *value;
00907 }
00908 void ast_channel_jb_set(struct ast_channel *chan, struct ast_jb *value)
00909 {
00910 chan->jb = *value;
00911 }
00912 void ast_channel_caller_set(struct ast_channel *chan, struct ast_party_caller *value)
00913 {
00914 chan->caller = *value;
00915 }
00916 void ast_channel_connected_set(struct ast_channel *chan, struct ast_party_connected_line *value)
00917 {
00918 chan->connected = *value;
00919 }
00920 void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value)
00921 {
00922 chan->dialed = *value;
00923 }
00924 void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value)
00925 {
00926 chan->redirecting = *value;
00927 }
00928 void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value)
00929 {
00930 chan->dtmf_tv = *value;
00931 }
00932 void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
00933 {
00934 chan->whentohangup = *value;
00935 }
00936 void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value)
00937 {
00938 chan->varshead = *value;
00939 }
00940
00941
00942 int ast_channel_softhangup_internal_flag(struct ast_channel *chan)
00943 {
00944 return chan->softhangup;
00945 }
00946 void ast_channel_softhangup_internal_flag_set(struct ast_channel *chan, int value)
00947 {
00948 chan->softhangup = value;
00949 }
00950 void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
00951 {
00952 chan->softhangup |= value;
00953 }
00954 void ast_channel_softhangup_internal_flag_clear(struct ast_channel *chan, int value)
00955 {
00956 chan ->softhangup &= ~value;
00957 }
00958
00959
00960 ast_group_t ast_channel_callgroup(const struct ast_channel *chan)
00961 {
00962 return chan->callgroup;
00963 }
00964 void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
00965 {
00966 chan->callgroup = value;
00967 }
00968 ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
00969 {
00970 return chan->pickupgroup;
00971 }
00972 void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
00973 {
00974 chan->pickupgroup = value;
00975 }
00976
00977
00978 int ast_channel_alert_write(struct ast_channel *chan)
00979 {
00980 char blah = 0x7F;
00981 return ast_channel_alert_writable(chan) && write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah);
00982 }
00983
00984 ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
00985 {
00986 int flags;
00987 char blah;
00988
00989 if (!ast_channel_internal_alert_readable(chan)) {
00990 return AST_ALERT_NOT_READABLE;
00991 }
00992
00993 flags = fcntl(chan->alertpipe[0], F_GETFL);
00994
00995
00996 if ((flags & O_NONBLOCK) == 0) {
00997 ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", ast_channel_name(chan));
00998 if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
00999 ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
01000 return AST_ALERT_READ_FATAL;
01001 }
01002 }
01003 if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) {
01004 if (errno != EINTR && errno != EAGAIN) {
01005 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
01006 return AST_ALERT_READ_FAIL;
01007 }
01008 }
01009
01010 return AST_ALERT_READ_SUCCESS;
01011 }
01012
01013 int ast_channel_alert_writable(struct ast_channel *chan)
01014 {
01015 return chan->alertpipe[1] > -1;
01016 }
01017
01018 int ast_channel_internal_alert_readable(struct ast_channel *chan)
01019 {
01020 return chan->alertpipe[0] > -1;
01021 }
01022
01023 void ast_channel_internal_alertpipe_clear(struct ast_channel *chan)
01024 {
01025 chan->alertpipe[0] = chan->alertpipe[1] = -1;
01026 }
01027
01028 void ast_channel_internal_alertpipe_close(struct ast_channel *chan)
01029 {
01030 if (ast_channel_internal_alert_readable(chan)) {
01031 close(chan->alertpipe[0]);
01032 }
01033 if (ast_channel_alert_writable(chan)) {
01034 close(chan->alertpipe[1]);
01035 }
01036 }
01037
01038 int ast_channel_internal_alertpipe_init(struct ast_channel *chan)
01039 {
01040 if (pipe(chan->alertpipe)) {
01041 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n");
01042 return -1;
01043 } else {
01044 int flags = fcntl(chan->alertpipe[0], F_GETFL);
01045 if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
01046 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
01047 return -1;
01048 }
01049 flags = fcntl(chan->alertpipe[1], F_GETFL);
01050 if (fcntl(chan->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) {
01051 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
01052 return -1;
01053 }
01054 }
01055 return 0;
01056 }
01057
01058 int ast_channel_internal_alert_readfd(struct ast_channel *chan)
01059 {
01060 return chan->alertpipe[0];
01061 }
01062
01063 void ast_channel_internal_alertpipe_swap(struct ast_channel *chan1, struct ast_channel *chan2)
01064 {
01065 int i;
01066 for (i = 0; i < ARRAY_LEN(chan1->alertpipe); i++) {
01067 SWAP(chan1->alertpipe[i], chan2->alertpipe[i]);
01068 }
01069 }
01070
01071
01072 void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)
01073 {
01074 chan->fds[which] = value;
01075 }
01076 void ast_channel_internal_fd_clear(struct ast_channel *chan, int which)
01077 {
01078 ast_channel_internal_fd_set(chan, which, -1);
01079 }
01080 void ast_channel_internal_fd_clear_all(struct ast_channel *chan)
01081 {
01082 int i;
01083 for (i = 0; i < AST_MAX_FDS; i++) {
01084 ast_channel_internal_fd_clear(chan, i);
01085 }
01086 }
01087 int ast_channel_fd(const struct ast_channel *chan, int which)
01088 {
01089 return chan->fds[which];
01090 }
01091 int ast_channel_fd_isset(const struct ast_channel *chan, int which)
01092 {
01093 return ast_channel_fd(chan, which) > -1;
01094 }
01095
01096 #ifdef HAVE_EPOLL
01097 struct ast_epoll_data *ast_channel_internal_epfd_data(const struct ast_channel *chan, int which)
01098 {
01099 return chan->epfd_data[which];
01100 }
01101 void ast_channel_internal_epfd_data_set(struct ast_channel *chan, int which , struct ast_epoll_data *value)
01102 {
01103 chan->epfd_data[which] = value;
01104 }
01105 #endif
01106
01107 pthread_t ast_channel_blocker(const struct ast_channel *chan)
01108 {
01109 return chan->blocker;
01110 }
01111 void ast_channel_blocker_set(struct ast_channel *chan, pthread_t value)
01112 {
01113 chan->blocker = value;
01114 }
01115
01116 ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
01117 {
01118 return chan->timingfunc;
01119 }
01120 void ast_channel_timingfunc_set(struct ast_channel *chan, ast_timing_func_t value)
01121 {
01122 chan->timingfunc = value;
01123 }
01124
01125 struct ast_bridge *ast_channel_internal_bridge(const struct ast_channel *chan)
01126 {
01127 return chan->bridge;
01128 }
01129 void ast_channel_internal_bridge_set(struct ast_channel *chan, struct ast_bridge *value)
01130 {
01131 chan->bridge = value;
01132 }
01133
01134 struct ast_channel *ast_channel_internal_bridged_channel(const struct ast_channel *chan)
01135 {
01136 return chan->bridged_channel;
01137 }
01138 void ast_channel_internal_bridged_channel_set(struct ast_channel *chan, struct ast_channel *value)
01139 {
01140 chan->bridged_channel = value;
01141 }
01142
01143 struct ast_flags *ast_channel_flags(struct ast_channel *chan)
01144 {
01145 return &chan->flags;
01146 }
01147
01148 struct ast_channel *__ast_channel_internal_alloc(void (*destructor)(void *obj), const char *file, int line, const char *function)
01149 {
01150 struct ast_channel *tmp;
01151 #if defined(REF_DEBUG)
01152 tmp = __ao2_alloc_debug(sizeof(*tmp), destructor,
01153 AO2_ALLOC_OPT_LOCK_MUTEX, "", file, line, function, 1);
01154 #elif defined(__AST_DEBUG_MALLOC)
01155 tmp = __ao2_alloc_debug(sizeof(*tmp), destructor,
01156 AO2_ALLOC_OPT_LOCK_MUTEX, "", file, line, function, 0);
01157 #else
01158 tmp = ao2_alloc(sizeof(*tmp), destructor);
01159 #endif
01160
01161 if ((ast_string_field_init(tmp, 128))) {
01162 return ast_channel_unref(tmp);
01163 }
01164
01165 return tmp;
01166 }
01167
01168 void ast_channel_internal_cleanup(struct ast_channel *chan)
01169 {
01170 ast_string_field_free_memory(chan);
01171 }
01172
01173 void ast_channel_internal_finalize(struct ast_channel *chan)
01174 {
01175 chan->finalized = 1;
01176 }
01177
01178 int ast_channel_internal_is_finalized(struct ast_channel *chan)
01179 {
01180 return chan->finalized;
01181 }