00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _ASTERISK_PBX_H
00024 #define _ASTERISK_PBX_H
00025
00026 #include "asterisk/sched.h"
00027 #include "asterisk/channel.h"
00028
00029 #if defined(__cplusplus) || defined(c_plusplus)
00030 extern "C" {
00031 #endif
00032
00033 #define AST_PBX_KEEP 0
00034 #define AST_PBX_REPLACE 1
00035
00036
00037 #define AST_MAX_APP 32
00038
00039
00040 #define AST_PBX_KEEPALIVE 10
00041 #define AST_PBX_NO_HANGUP_PEER 11
00042
00043
00044 #define PRIORITY_HINT -1
00045
00046
00047 enum ast_extension_states {
00048
00049 AST_EXTENSION_REMOVED = -2,
00050
00051 AST_EXTENSION_DEACTIVATED = -1,
00052
00053 AST_EXTENSION_NOT_INUSE = 0,
00054
00055 AST_EXTENSION_INUSE = 1 << 0,
00056
00057 AST_EXTENSION_BUSY = 1 << 1,
00058
00059 AST_EXTENSION_UNAVAILABLE = 1 << 2,
00060
00061 AST_EXTENSION_RINGING = 1 << 3,
00062 };
00063
00064
00065 static const struct cfextension_states {
00066 int extension_state;
00067 const char * const text;
00068 } extension_states[] = {
00069 { AST_EXTENSION_NOT_INUSE, "Idle" },
00070 { AST_EXTENSION_INUSE, "InUse" },
00071 { AST_EXTENSION_BUSY, "Busy" },
00072 { AST_EXTENSION_UNAVAILABLE, "Unavailable" },
00073 { AST_EXTENSION_RINGING, "Ringing" },
00074 { AST_EXTENSION_INUSE | AST_EXTENSION_RINGING, "InUse&Ringing" }
00075 };
00076
00077 struct ast_context;
00078 struct ast_exten;
00079 struct ast_include;
00080 struct ast_ignorepat;
00081 struct ast_sw;
00082
00083 typedef int (*ast_state_cb_type)(char *context, char* id, enum ast_extension_states state, void *data);
00084
00085
00086 struct ast_custom_function {
00087 char *name;
00088 char *synopsis;
00089 char *desc;
00090 char *syntax;
00091 char *(*read)(struct ast_channel *, char *, char *, char *, size_t);
00092 void (*write)(struct ast_channel *, char *, char *, const char *);
00093 struct ast_custom_function *next;
00094 };
00095
00096
00097 struct ast_switch {
00098
00099 struct ast_switch *next;
00100
00101 const char *name;
00102
00103 const char *description;
00104
00105 int (*exists)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
00106
00107 int (*canmatch)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
00108
00109 int (*exec)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data);
00110
00111 int (*matchmore)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
00112 };
00113
00114 struct ast_timing {
00115 int hastime;
00116 unsigned int monthmask;
00117 unsigned int daymask;
00118 unsigned int dowmask;
00119 unsigned int minmask[24];
00120 };
00121
00122 extern int ast_build_timing(struct ast_timing *i, char *info);
00123 extern int ast_check_timing(struct ast_timing *i);
00124
00125 struct ast_pbx {
00126 int dtimeout;
00127 int rtimeout;
00128
00129 };
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 extern int ast_register_switch(struct ast_switch *sw);
00140
00141
00142
00143
00144
00145
00146
00147 extern void ast_unregister_switch(struct ast_switch *sw);
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 extern struct ast_app *pbx_findapp(const char *app);
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 int pbx_exec(struct ast_channel *c, struct ast_app *app, void *data, int newstack);
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 struct ast_context *ast_context_create(struct ast_context **extcontexts, const char *name, const char *registrar);
00183
00184
00185
00186
00187
00188
00189 void ast_merge_contexts_and_delete(struct ast_context **extcontexts, const char *registrar);
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 void ast_context_destroy(struct ast_context *con, const char *registrar);
00200
00201
00202
00203
00204
00205
00206
00207 struct ast_context *ast_context_find(const char *name);
00208
00209 enum ast_pbx_result {
00210 AST_PBX_SUCCESS = 0,
00211 AST_PBX_FAILED = -1,
00212 AST_PBX_CALL_LIMIT = -2,
00213 };
00214
00215
00216
00217
00218
00219
00220 enum ast_pbx_result ast_pbx_start(struct ast_channel *c);
00221
00222
00223
00224
00225
00226
00227
00228
00229 enum ast_pbx_result ast_pbx_run(struct ast_channel *c);
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid,
00247 const char *application, void *data, void (*datad)(void *), const char *registrar);
00248
00249
00250
00251
00252
00253 int ast_add_extension2(struct ast_context *con,
00254 int replace, const char *extension, int priority, const char *label, const char *callerid,
00255 const char *application, void *data, void (*datad)(void *),
00256 const char *registrar);
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 int ast_register_application(const char *app, int (*execute)(struct ast_channel *, void *),
00273 const char *synopsis, const char *description);
00274
00275
00276
00277
00278
00279
00280
00281 int ast_unregister_application(const char *app);
00282
00283
00284
00285
00286
00287
00288
00289
00290 int ast_extension_state(struct ast_channel *c, char *context, char *exten);
00291
00292
00293
00294
00295
00296
00297 const char *ast_extension_state2str(int extension_state);
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 int ast_extension_state_add(const char *context, const char *exten,
00309 ast_state_cb_type callback, void *data);
00310
00311
00312
00313
00314
00315
00316
00317
00318 int ast_extension_state_del(int id, ast_state_cb_type callback);
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 int ast_get_hint(char *hint, int maxlen, char *name, int maxnamelen, struct ast_channel *c, const char *context, const char *exten);
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid);
00359
00360 int ast_findlabel_extension2(struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid);
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
00388
00389
00390
00391
00392
00393
00394
00395
00396 int ast_extension_match(const char *pattern, const char *extension);
00397 int ast_extension_close(const char *pattern, const char *data, int needmore);
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 int ast_exec_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid);
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431 int ast_context_add_include(const char *context, const char *include, const char *registrar);
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 int ast_context_add_include2(struct ast_context *con, const char *include, const char *registrar);
00442
00443
00444
00445
00446
00447 int ast_context_remove_include(const char *context, const char *include,const char *registrar);
00448
00449
00450
00451
00452 int ast_context_remove_include2(struct ast_context *con, const char *include, const char *registrar);
00453
00454
00455
00456
00457
00458
00459 int ast_context_verify_includes(struct ast_context *con);
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 int ast_context_add_switch(const char *context, const char *sw, const char *data, int eval, const char *registrar);
00472
00473
00474
00475
00476 int ast_context_add_switch2(struct ast_context *con, const char *sw, const char *data, int eval, const char *registrar);
00477
00478
00479
00480
00481
00482
00483 int ast_context_remove_switch(const char *context, const char *sw, const char *data, const char *registrar);
00484 int ast_context_remove_switch2(struct ast_context *con, const char *sw, const char *data, const char *registrar);
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 int ast_context_remove_extension(const char *context, const char *extension, int priority,
00496 const char *registrar);
00497 int ast_context_remove_extension2(struct ast_context *con, const char *extension,
00498 int priority, const char *registrar);
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508 int ast_context_add_ignorepat(const char *context, const char *ignorepat, const char *registrar);
00509 int ast_context_add_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar);
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 int ast_context_remove_ignorepat(const char *context, const char *ignorepat, const char *registrar);
00520 int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar);
00521
00522
00523
00524
00525
00526
00527
00528
00529 int ast_ignore_pattern(const char *context, const char *pattern);
00530
00531
00532
00533
00534
00535
00536 int ast_lock_contexts(void);
00537
00538
00539
00540
00541
00542 int ast_unlock_contexts(void);
00543
00544
00545
00546
00547
00548
00549
00550 int ast_lock_context(struct ast_context *con);
00551
00552
00553
00554
00555
00556
00557 int ast_unlock_context(struct ast_context *con);
00558
00559
00560 int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
00561
00562 int ast_async_goto_by_name(const char *chan, const char *context, const char *exten, int priority);
00563
00564
00565
00566 int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel);
00567
00568
00569
00570 int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel);
00571
00572
00573 int pbx_checkcondition(char *condition);
00574
00575
00576 const char *ast_get_context_name(struct ast_context *con);
00577 const char *ast_get_extension_name(struct ast_exten *exten);
00578 const char *ast_get_include_name(struct ast_include *include);
00579 const char *ast_get_ignorepat_name(struct ast_ignorepat *ip);
00580 const char *ast_get_switch_name(struct ast_sw *sw);
00581 const char *ast_get_switch_data(struct ast_sw *sw);
00582
00583
00584 int ast_get_extension_priority(struct ast_exten *exten);
00585 int ast_get_extension_matchcid(struct ast_exten *e);
00586 const char *ast_get_extension_cidmatch(struct ast_exten *e);
00587 const char *ast_get_extension_app(struct ast_exten *e);
00588 const char *ast_get_extension_label(struct ast_exten *e);
00589 void *ast_get_extension_app_data(struct ast_exten *e);
00590
00591
00592 const char *ast_get_context_registrar(struct ast_context *c);
00593 const char *ast_get_extension_registrar(struct ast_exten *e);
00594 const char *ast_get_include_registrar(struct ast_include *i);
00595 const char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip);
00596 const char *ast_get_switch_registrar(struct ast_sw *sw);
00597
00598
00599 struct ast_context *ast_walk_contexts(struct ast_context *con);
00600 struct ast_exten *ast_walk_context_extensions(struct ast_context *con,
00601 struct ast_exten *priority);
00602 struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten,
00603 struct ast_exten *priority);
00604 struct ast_include *ast_walk_context_includes(struct ast_context *con,
00605 struct ast_include *inc);
00606 struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con,
00607 struct ast_ignorepat *ip);
00608 struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw);
00609
00610 int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size);
00611 extern char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name);
00612 extern void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value);
00613 extern void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value);
00614 extern void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp);
00615 extern void pbx_builtin_clear_globals(void);
00616 extern int pbx_builtin_setvar(struct ast_channel *chan, void *data);
00617 extern void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count);
00618 extern void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count);
00619
00620 int ast_extension_patmatch(const char *pattern, const char *data);
00621
00622
00623
00624
00625 extern int pbx_set_autofallthrough(int newval);
00626 int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority);
00627
00628 int ast_parseable_goto(struct ast_channel *chan, const char *goto_string);
00629 int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
00630 int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority);
00631
00632 struct ast_custom_function* ast_custom_function_find(char *name);
00633 int ast_custom_function_unregister(struct ast_custom_function *acf);
00634 int ast_custom_function_register(struct ast_custom_function *acf);
00635
00636
00637 int ast_active_calls(void);
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650 char *ast_func_read(struct ast_channel *chan, const char *in, char *workspace, size_t len);
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 void ast_func_write(struct ast_channel *chan, const char *in, const char *value);
00661
00662 void ast_hint_state_changed(const char *device);
00663
00664 #if defined(__cplusplus) || defined(c_plusplus)
00665 }
00666 #endif
00667
00668 #endif