Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:21 2009

## Asterisk developer's documentation

# asterisk.h File Reference

Asterisk main include file. File version handling, generic pbx functions. More...

Go to the source code of this file.

## Defines

#define | AST_CONFIG_MAX_PATH 255
#define | ASTERISK_FILE_VERSION(file, version)
| Register/unregister a source code file with the core.
#define | DEFAULT_LANGUAGE "en"
#define | sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
#define | setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__

## Functions

void | ast_channels_init (void)
void | ast_register_file_version (const char *file, const char *version)
| Register the version of a source code file with the core.
int | ast_set_priority (int)
void | ast_unregister_file_version (const char *file)
| Unregister a source code file from the core.
int | astdb_init (void)
void | close_logger (void)
int | dnsmgr_init (void)
void | dnsmgr_reload (void)
void | dnsmgr_start_refresh (void)
int | init_framer (void)
int | init_logger (void)
int | load_modules (const int preload_only)
int | load_pbx (void)
int | reload_logger (int)
int | term_init (void)

## Variables

char | ast_config_AST_AGI_DIR [AST_CONFIG_MAX_PATH]
char | ast_config_AST_CONFIG_DIR [AST_CONFIG_MAX_PATH]
char | ast_config_AST_CONFIG_FILE [AST_CONFIG_MAX_PATH]
char | ast_config_AST_CTL [AST_CONFIG_MAX_PATH]
char | ast_config_AST_CTL_GROUP [AST_CONFIG_MAX_PATH]
char | ast_config_AST_CTL_OWNER [AST_CONFIG_MAX_PATH]
char | ast_config_AST_CTL_PERMISSIONS [AST_CONFIG_MAX_PATH]
char | ast_config_AST_DB [AST_CONFIG_MAX_PATH]
char | ast_config_AST_KEY_DIR [AST_CONFIG_MAX_PATH]
char | ast_config_AST_LOG_DIR [AST_CONFIG_MAX_PATH]
char | ast_config_AST_MODULE_DIR [AST_CONFIG_MAX_PATH]
char | ast_config_AST_MONITOR_DIR [AST_CONFIG_MAX_PATH]
char | ast_config_AST_PID [AST_CONFIG_MAX_PATH]
char | ast_config_AST_RUN_DIR [AST_CONFIG_MAX_PATH]
char | ast_config_AST_SOCKET [AST_CONFIG_MAX_PATH]
char | ast_config_AST_SPOOL_DIR [AST_CONFIG_MAX_PATH]
char | ast_config_AST_VAR_DIR [AST_CONFIG_MAX_PATH]

## Detailed Description

Asterisk main include file. File version handling, generic pbx functions.

Definition in file asterisk.h.

## Define Documentation

#define AST_CONFIG_MAX_PATH 255

Definition at line 23 of file asterisk.h.

Referenced by add_module(), build_filename(), csv_log(), file_ok_sel(), reload_logger(), vm_change_password(), and writefile().

#define ASTERISK_FILE_VERSION | ( | file,
|  | version |  | ) |

Register/unregister a source code file with the core.

Parameters:

  | file | the source file name
  | version | the version string (typically a CVS revision keyword string)

This macro will place a file-scope constructor and destructor into the source of the module using it; this will cause the version of this file to registered with the Asterisk core (and unregistered) at the appropriate times.

Example:

     ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")

Note:
  The dollar signs above have been protected with backslashes to keep SVN from modifying them in this file; under normal circumstances they would not be present and SVN would expand the Revision keyword into the file's revision number.

Definition at line 114 of file asterisk.h.

#define DEFAULT_LANGUAGE "en"

Definition at line 21 of file asterisk.h.

#define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__

Definition at line 25 of file asterisk.h.

Referenced by ast_set_priority().

#define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__

Definition at line 24 of file asterisk.h.

Referenced by ast_set_priority().

## Function Documentation

void ast_channels_init | ( | void |  | ) |

Definition at line 3944 of file channel.c.

References ast_cli_register(), and cli_show_channeltypes.

Referenced by main().

    03945 {
    03946    ast_cli_register(&cli_show_channeltypes);
    03947 }

void ast_register_file_version | ( | const char * | file,
|  | const char * | version |
| ) |  |  |

Register the version of a source code file with the core.

Parameters:

  | file | the source file name
  | version | the version string (typically a CVS revision keyword string)

Returns:
  nothing

This function should not be called directly, but instead the ASTERISK_FILE_VERSION macro should be used to register a file with the core.

Definition at line 252 of file asterisk.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_strdupa, ast_strip_quoted(), calloc, and list.

    00253 {
    00254    struct file_version *new;
    00255    char *work;
    00256    size_t version_length;
    00257
    00258    work = ast_strdupa(version);
    00259    work = ast_strip(ast_strip_quoted(work, "$", "$"));
    00260    version_length = strlen(work) + 1;
    00261
    00262    new = calloc(1, sizeof(*new) + version_length);
    00263    if (!new)
    00264       return;
    00265
    00266    new->file = file;
    00267    new->version = (char *) new + sizeof(*new);
    00268    memcpy(new->version, work, version_length);
    00269    AST_LIST_LOCK(&file_versions);
    00270    AST_LIST_INSERT_HEAD(&file_versions, new, list);
    00271    AST_LIST_UNLOCK(&file_versions);
    00272 }

int ast_set_priority | ( | int | pri | ) |

We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing.

Definition at line 793 of file asterisk.c.

References ast_log(), ast_verbose(), LOG_WARNING, sched_setscheduler, and setpriority.

Referenced by app_exec(), ast_safe_system(), icesencode(), launch_script(), main(), mp3play(), NBScatplay(), send_waveform_to_fd(), spawn_mp3(), and spawn_ras().

    00794 {
    00795    struct sched_param sched;
    00796    memset(&sched, 0, sizeof(sched));
    00797 #ifdef __linux__
    00798 #undef sched_setscheduler
    00799    if (pri) {
    00800       sched.sched_priority = 10;
    00801       if (sched_setscheduler(0, SCHED_RR, &sched)) {
    00802          ast_log(LOG_WARNING, "Unable to set high priority\n");
    00803          return -1;
    00804       } else
    00805          if (option_verbose)
    00806             ast_verbose("Set to realtime thread\n");
    00807    } else {
    00808       sched.sched_priority = 0;
    00809       /* According to the manpage, this can never fail, with these parameters. */
    00810       sched_setscheduler(0, SCHED_OTHER, &sched);
    00811    }
    00812 #else
    00813 #undef setpriority
    00814    if (pri) {
    00815       if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
    00816          ast_log(LOG_WARNING, "Unable to set high priority\n");
    00817          return -1;
    00818       } else
    00819          if (option_verbose)
    00820             ast_verbose("Set to high priority\n");
    00821    } else {
    00822       /* According to the manpage, this can never fail, with these parameters. */
    00823       setpriority(PRIO_PROCESS, 0, 0);
    00824    }
    00825 #endif
    00826    return 0;
    00827 }

void ast_unregister_file_version | ( | const char * | file | ) |

Unregister a source code file from the core.

Parameters:

  | file | the source file name

Returns:
  nothing

This function should not be called directly, but instead the ASTERISK_FILE_VERSION macro should be used to automatically unregister the file when the module is unloaded.

Definition at line 274 of file asterisk.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, free, and list.

    00275 {
    00276    struct file_version *find;
    00277
    00278    AST_LIST_LOCK(&file_versions);
    00279    AST_LIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
    00280       if (!strcasecmp(find->file, file)) {
    00281          AST_LIST_REMOVE_CURRENT(&file_versions, list);
    00282          break;
    00283       }
    00284    }
    00285    AST_LIST_TRAVERSE_SAFE_END;
    00286    AST_LIST_UNLOCK(&file_versions);
    00287    if (find)
    00288       free(find);
    00289 }

int astdb_init | ( | void |  | ) |

Definition at line 581 of file db.c.

References ast_cli_register(), ast_manager_register, dbinit(), EVENT_FLAG_SYSTEM, manager_dbget(), and manager_dbput().

Referenced by main().

    00582 {
    00583    dbinit();
    00584    ast_cli_register(&cli_database_show);
    00585    ast_cli_register(&cli_database_showkey);
    00586    ast_cli_register(&cli_database_get);
    00587    ast_cli_register(&cli_database_put);
    00588    ast_cli_register(&cli_database_del);
    00589    ast_cli_register(&cli_database_deltree);
    00590    ast_manager_register("DBGet", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry");
    00591    ast_manager_register("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry");
    00592    return 0;
    00593 }

void close_logger | ( | void |  | ) |

Definition at line 644 of file logger.c.

References ast_mutex_lock(), ast_mutex_unlock(), free, last, list, msglist::msg, msgcnt, and msglist::next.

Referenced by quit_handler().

    00645 {
    00646    struct msglist *m, *tmp;
    00647
    00648    ast_mutex_lock(&msglist_lock);
    00649    m = list;
    00650    while(m) {
    00651       if (m->msg) {
    00652          free(m->msg);
    00653       }
    00654       tmp = m->next;
    00655       free(m);
    00656       m = tmp;
    00657    }
    00658    list = last = NULL;
    00659    msgcnt = 0;
    00660    ast_mutex_unlock(&msglist_lock);
    00661    return;
    00662 }

int dnsmgr_init | ( | void |  | ) |

Definition at line 285 of file dnsmgr.c.

References ast_cli_register(), ast_log(), cli_reload, cli_status, do_reload(), LOG_ERROR, and sched_context_create().

Referenced by main().

    00286 {
    00287    sched = sched_context_create();
    00288    if (!sched) {
    00289       ast_log(LOG_ERROR, "Unable to create schedule context.\n");
    00290       return -1;
    00291    }
    00292    ast_cli_register(&cli_reload);
    00293    ast_cli_register(&cli_status);
    00294    return do_reload(1);
    00295 }

void dnsmgr_reload | ( | void |  | ) |

Definition at line 297 of file dnsmgr.c.

References do_reload().

Referenced by ast_module_reload().

    00298 {
    00299    do_reload(0);
    00300 }

void dnsmgr_start_refresh | ( | void |  | ) |

Definition at line 194 of file dnsmgr.c.

References ast_sched_add_variable(), ast_sched_del(), master_refresh_info, and refresh_list().

Referenced by main().

    00195 {
    00196    if (refresh_sched > -1) {
    00197       ast_sched_del(sched, refresh_sched);
    00198       refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);
    00199    }
    00200 }

int init_framer | ( | void |  | ) |

Definition at line 871 of file frame.c.

References ast_cli_register_multiple().

Referenced by main().

    00872 {
    00873    ast_cli_register_multiple(my_clis, sizeof(my_clis)/sizeof(my_clis[0]) );
    00874    return 0;
    00875 }

int init_logger | ( | void |  | ) |

Definition at line 603 of file logger.c.

References ast_cli_register(), ast_config_AST_LOG_DIR, ast_log(), ast_queue_log(), ast_verbose(), eventlog, EVENTLOG, handle_SIGXFSZ(), init_logger_chain(), LOG_ERROR, LOG_EVENT, logfiles, option_verbose, qlog, and QUEUELOG.

Referenced by main().

    00604 {
    00605    char tmp[256];
    00606    int res = 0;
    00607
    00608    /* auto rotate if sig SIGXFSZ comes a-knockin */
    00609    (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ);
    00610
    00611    /* register the relaod logger cli command */
    00612    ast_cli_register(&reload_logger_cli);
    00613    ast_cli_register(&rotate_logger_cli);
    00614    ast_cli_register(&logger_show_channels_cli);
    00615
    00616    mkdir((char *)ast_config_AST_LOG_DIR, 0755);
    00617
    00618    /* create log channels */
    00619    init_logger_chain();
    00620
    00621    /* create the eventlog */
    00622    if (logfiles.event_log) {
    00623       mkdir((char *)ast_config_AST_LOG_DIR, 0755);
    00624       snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
    00625       eventlog = fopen((char *)tmp, "a");
    00626       if (eventlog) {
    00627          ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
    00628          if (option_verbose)
    00629             ast_verbose("Asterisk Event Logger Started %s\n",(char *)tmp);
    00630       } else {
    00631          ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
    00632          res = -1;
    00633       }
    00634    }
    00635
    00636    if (logfiles.queue_log) {
    00637       snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG);
    00638       qlog = fopen(tmp, "a");
    00639       ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
    00640    }
    00641    return res;
    00642 }

int load_modules | ( | const int | preload_only | ) |

Definition at line 466 of file loader.c.

References __load_resource(), ast_config_AST_MODULE_DIR, ast_config_destroy(), ast_config_load(), ast_log(), AST_MODULE_CONFIG, ast_resource_exists(), ast_true(), ast_variable_browse(), ast_variable_retrieve(), ast_verbose(), cfg, COLOR_BRWHITE, LOG_DEBUG, LOG_WARNING, ast_variable::name, ast_variable::next, option_debug, option_quiet, option_verbose, term_color(), ast_variable::value, and VERBOSE_PREFIX_1.

Referenced by main().

    00467 {
    00468    struct ast_config *cfg;
    00469    struct ast_variable *v;
    00470    char tmp[80];
    00471
    00472    if (option_verbose) {
    00473       if (preload_only)
    00474          ast_verbose("Asterisk Dynamic Loader loading preload modules:\n");
    00475       else
    00476          ast_verbose("Asterisk Dynamic Loader Starting:\n");
    00477    }
    00478
    00479    cfg = ast_config_load(AST_MODULE_CONFIG);
    00480    if (cfg) {
    00481       int doload;
    00482
    00483       /* Load explicitly defined modules */
    00484       for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {
    00485          doload = 0;
    00486
    00487          if (preload_only)
    00488             doload = !strcasecmp(v->name, "preload");
    00489          else
    00490             doload = !strcasecmp(v->name, "load");
    00491
    00492              if (doload) {
    00493             if (option_debug && !option_verbose)
    00494                ast_log(LOG_DEBUG, "Loading module %s\n", v->value);
    00495             if (option_verbose) {
    00496                ast_verbose(VERBOSE_PREFIX_1 "[%s]", term_color(tmp, v->value, COLOR_BRWHITE, 0, sizeof(tmp)));
    00497                fflush(stdout);
    00498             }
    00499             if (__load_resource(v->value, cfg)) {
    00500                ast_log(LOG_WARNING, "Loading module %s failed!\n", v->value);
    00501                ast_config_destroy(cfg);
    00502                return -1;
    00503             }
    00504          }
    00505       }
    00506    }
    00507
    00508    if (preload_only) {
    00509       ast_config_destroy(cfg);
    00510       return 0;
    00511    }
    00512
    00513    if (!cfg || ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
    00514       /* Load all modules */
    00515       DIR *mods;
    00516       struct dirent *d;
    00517       int x;
    00518
    00519       /* Loop through each order */
    00520       for (x=0; x<sizeof(loadorder) / sizeof(loadorder[0]); x++) {
    00521          mods = opendir((char *)ast_config_AST_MODULE_DIR);
    00522          if (mods) {
    00523             while((d = readdir(mods))) {
    00524                /* Must end in .so to load it.  */
    00525                if ((strlen(d->d_name) > 3) &&
    00526                    (!loadorder[x] || !strncasecmp(d->d_name, loadorder[x], strlen(loadorder[x]))) &&
    00527                    !strcasecmp(d->d_name + strlen(d->d_name) - 3, ".so") &&
    00528                   !ast_resource_exists(d->d_name)) {
    00529                   /* It's a shared library -- Just be sure we're allowed to load it -- kinda
    00530                      an inefficient way to do it, but oh well. */
    00531                   if (cfg) {
    00532                      v = ast_variable_browse(cfg, "modules");
    00533                      while(v) {
    00534                         if (!strcasecmp(v->name, "noload") &&
    00535                             !strcasecmp(v->value, d->d_name))
    00536                            break;
    00537                         v = v->next;
    00538                      }
    00539                      if (v) {
    00540                         if (option_verbose) {
    00541                            ast_verbose( VERBOSE_PREFIX_1 "[skipping %s]\n", d->d_name);
    00542                            fflush(stdout);
    00543                         }
    00544                         continue;
    00545                      }
    00546
    00547                   }
    00548                   if (option_debug && !option_verbose)
    00549                      ast_log(LOG_DEBUG, "Loading module %s\n", d->d_name);
    00550                   if (option_verbose) {
    00551                      ast_verbose( VERBOSE_PREFIX_1 "[%s]", term_color(tmp, d->d_name, COLOR_BRWHITE, 0, sizeof(tmp)));
    00552                      fflush(stdout);
    00553                   }
    00554                   if (__load_resource(d->d_name, cfg)) {
    00555                      ast_log(LOG_WARNING, "Loading module %s failed!\n", d->d_name);
    00556                      if (cfg)
    00557                         ast_config_destroy(cfg);
    00558                      return -1;
    00559                   }
    00560                }
    00561             }
    00562             closedir(mods);
    00563          } else {
    00564             if (!option_quiet)
    00565                ast_log(LOG_WARNING, "Unable to open modules directory %s.\n", (char *)ast_config_AST_MODULE_DIR);
    00566          }
    00567       }
    00568    }
    00569    ast_config_destroy(cfg);
    00570    return 0;
    00571 }

int load_pbx | ( | void |  | ) |

Definition at line 6266 of file pbx.c.

References ast_cli_register_multiple(), AST_LIST_HEAD_INIT_NOLOCK, ast_log(), ast_register_application(), ast_verbose(), builtins, description, globals, LOG_ERROR, name, option_verbose, synopsis, and VERBOSE_PREFIX_1.

Referenced by main().

    06267 {
    06268    int x;
    06269
    06270    /* Initialize the PBX */
    06271    if (option_verbose) {
    06272       ast_verbose( "Asterisk PBX Core Initializing\n");
    06273       ast_verbose( "Registering builtin applications:\n");
    06274    }
    06275    AST_LIST_HEAD_INIT_NOLOCK(&globals);
    06276    ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(pbx_cli[0]));
    06277
    06278    /* Register builtin applications */
    06279    for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {
    06280       if (option_verbose)
    06281          ast_verbose( VERBOSE_PREFIX_1 "[%s]\n", builtins[x].name);
    06282       if (ast_register_application(builtins[x].name, builtins[x].execute, builtins[x].synopsis, builtins[x].description)) {
    06283          ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
    06284          return -1;
    06285       }
    06286    }
    06287    return 0;
    06288 }

int reload_logger | ( | int |  | ) |

Definition at line 382 of file logger.c.

References ast_config_AST_LOG_DIR, AST_CONFIG_MAX_PATH, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_queue_log(), ast_verbose(), logchannel::disabled, EVENT_FLAG_SYSTEM, EVENTLOG, eventlog, logchannel::filename, logchannel::fileptr, filesize_reload_needed, init_logger_chain(), LOG_ERROR, LOG_EVENT, logfiles, manager_event(), logchannel::next, option_verbose, qlog, and QUEUELOG.

Referenced by ast_log(), handle_logger_reload(), handle_logger_rotate(), and main().

    00383 {
    00384    char old[AST_CONFIG_MAX_PATH] = "";
    00385    char new[AST_CONFIG_MAX_PATH];
    00386    int event_rotate = rotate, queue_rotate = rotate;
    00387    struct logchannel *f;
    00388    FILE *myf;
    00389    int x, res = 0;
    00390
    00391    ast_mutex_lock(&msglist_lock);   /* to avoid deadlock */
    00392    ast_mutex_lock(&loglock);
    00393    if (eventlog)
    00394       fclose(eventlog);
    00395    else
    00396       event_rotate = 0;
    00397    eventlog = NULL;
    00398
    00399    if (qlog)
    00400       fclose(qlog);
    00401    else
    00402       queue_rotate = 0;
    00403    qlog = NULL;
    00404
    00405    mkdir((char *)ast_config_AST_LOG_DIR, 0755);
    00406
    00407    f = logchannels;
    00408    while(f) {
    00409       if (f->disabled) {
    00410          f->disabled = 0;  /* Re-enable logging at reload */
    00411          manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
    00412       }
    00413       if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
    00414          fclose(f->fileptr);  /* Close file */
    00415          f->fileptr = NULL;
    00416          if(rotate) {
    00417             ast_copy_string(old, f->filename, sizeof(old));
    00418
    00419             for(x=0;;x++) {
    00420                snprintf(new, sizeof(new), "%s.%d", f->filename, x);
    00421                myf = fopen((char *)new, "r");
    00422                if (myf) {
    00423                   fclose(myf);
    00424                } else {
    00425                   break;
    00426                }
    00427             }
    00428
    00429             /* do it */
    00430             if (rename(old,new))
    00431                fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
    00432          }
    00433       }
    00434       f = f->next;
    00435    }
    00436
    00437    filesize_reload_needed = 0;
    00438
    00439    init_logger_chain();
    00440
    00441    if (logfiles.event_log) {
    00442       snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
    00443       if (event_rotate) {
    00444          for (x=0;;x++) {
    00445             snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
    00446             myf = fopen((char *)new, "r");
    00447             if (myf)    /* File exists */
    00448                fclose(myf);
    00449             else
    00450                break;
    00451          }
    00452
    00453          /* do it */
    00454          if (rename(old,new))
    00455             ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
    00456       }
    00457
    00458       eventlog = fopen(old, "a");
    00459       if (eventlog) {
    00460          ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
    00461          if (option_verbose)
    00462             ast_verbose("Asterisk Event Logger restarted\n");
    00463       } else {
    00464          ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
    00465          res = -1;
    00466       }
    00467    }
    00468
    00469    if (logfiles.queue_log) {
    00470       snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG);
    00471       if (queue_rotate) {
    00472          for (x = 0; ; x++) {
    00473             snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, QUEUELOG, x);
    00474             myf = fopen((char *)new, "r");
    00475             if (myf)    /* File exists */
    00476                fclose(myf);
    00477             else
    00478                break;
    00479          }
    00480
    00481          /* do it */
    00482          if (rename(old, new))
    00483             ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
    00484       }
    00485
    00486       qlog = fopen(old, "a");
    00487       if (qlog) {
    00488          ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
    00489          ast_log(LOG_EVENT, "Restarted Asterisk Queue Logger\n");
    00490          if (option_verbose)
    00491             ast_verbose("Asterisk Queue Logger restarted\n");
    00492       } else {
    00493          ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
    00494          res = -1;
    00495       }
    00496    }
    00497    ast_mutex_unlock(&loglock);
    00498    ast_mutex_unlock(&msglist_lock);
    00499
    00500    return res;
    00501 }

int term_init | ( | void |  | ) |

Definition at line 74 of file term.c.

References ATTR_BRIGHT, ATTR_RESET, COLOR_BLACK, COLOR_BROWN, COLOR_WHITE, convshort(), ESC, option_console, option_nocolor, and option_nofork.

Referenced by main().

    00075 {
    00076    char *term = getenv("TERM");
    00077    char termfile[256] = "";
    00078    char buffer[512] = "";
    00079    int termfd = -1, parseokay = 0, i;
    00080
    00081    if (!term)
    00082       return 0;
    00083    if (!option_console || option_nocolor || !option_nofork)
    00084       return 0;
    00085
    00086    for (i=0 ;; i++) {
    00087       if (termpath[i] == NULL) {
    00088          break;
    00089       }
    00090       snprintf(termfile, sizeof(termfile), "%s/%c/%s", termpath[i], *term, term);
    00091       termfd = open(termfile, O_RDONLY);
    00092       if (termfd > -1) {
    00093          break;
    00094       }
    00095    }
    00096    if (termfd > -1) {
    00097       int actsize = read(termfd, buffer, sizeof(buffer) - 1);
    00098       short sz_names = convshort(buffer + 2);
    00099       short sz_bools = convshort(buffer + 4);
    00100       short n_nums   = convshort(buffer + 6);
    00101
    00102       /* if ((sz_names + sz_bools) & 1)
    00103          sz_bools++; */
    00104
    00105       if (sz_names + sz_bools + n_nums < actsize) {
    00106          /* Offset 13 is defined in /usr/include/term.h, though we do not
    00107           * include it here, as it conflicts with include/asterisk/term.h */
    00108          short max_colors = convshort(buffer + 12 + sz_names + sz_bools + 13 * 2);
    00109          if (max_colors > 0) {
    00110             vt100compat = 1;
    00111          }
    00112          parseokay = 1;
    00113       }
    00114       close(termfd);
    00115    }
    00116
    00117    if (!parseokay) {
    00118       /* These comparisons should not be substrings nor case-insensitive, as
    00119        * terminal types are very particular about how they treat suffixes and
    00120        * capitalization.  For example, terminal type 'linux-m' does NOT
    00121        * support color, while 'linux' does.  Not even all vt100* terminals
    00122        * support color, either (e.g. 'vt100+fnkeys'). */
    00123       if (!strcmp(term, "linux")) {
    00124          vt100compat = 1;
    00125       } else if (!strcmp(term, "xterm")) {
    00126          vt100compat = 1;
    00127       } else if (!strcmp(term, "xterm-color")) {
    00128          vt100compat = 1;
    00129       } else if (!strncmp(term, "Eterm", 5)) {
    00130          /* Both entries which start with Eterm support color */
    00131          vt100compat = 1;
    00132       } else if (!strcmp(term, "vt100")) {
    00133          vt100compat = 1;
    00134       } else if (!strncmp(term, "crt", 3)) {
    00135          /* Both crt terminals support color */
    00136          vt100compat = 1;
    00137       }
    00138    }
    00139
    00140    if (vt100compat) {
    00141       /* Make commands show up in nice colors */
    00142       snprintf(prepdata, sizeof(prepdata), "%c[%d;%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN, COLOR_BLACK + 10);
    00143       snprintf(enddata, sizeof(enddata), "%c[%d;%d;%dm", ESC, ATTR_RESET, COLOR_WHITE, COLOR_BLACK + 10);
    00144       snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
    00145    }
    00146    return 0;
    00147 }

## Variable Documentation

char ast_config_AST_AGI_DIR[AST_CONFIG_MAX_PATH]

Definition at line 219 of file asterisk.c.

Referenced by launch_script().

char ast_config_AST_CONFIG_DIR[AST_CONFIG_MAX_PATH]

Definition at line 212 of file asterisk.c.

Referenced by ast_ael_compile(), compile_script(), config_text_file_load(), config_text_file_save(), handle_save_dialplan(), ices_exec(), and vm_change_password().

char ast_config_AST_CONFIG_FILE[AST_CONFIG_MAX_PATH]

Definition at line 213 of file asterisk.c.

char ast_config_AST_CTL[AST_CONFIG_MAX_PATH]

Definition at line 230 of file asterisk.c.

char ast_config_AST_CTL_GROUP[AST_CONFIG_MAX_PATH]

Definition at line 229 of file asterisk.c.

char ast_config_AST_CTL_OWNER[AST_CONFIG_MAX_PATH]

Definition at line 228 of file asterisk.c.

char ast_config_AST_CTL_PERMISSIONS[AST_CONFIG_MAX_PATH]

Definition at line 227 of file asterisk.c.

char ast_config_AST_DB[AST_CONFIG_MAX_PATH]

Definition at line 220 of file asterisk.c.

Referenced by dbinit().

char ast_config_AST_KEY_DIR[AST_CONFIG_MAX_PATH]

Definition at line 221 of file asterisk.c.

char ast_config_AST_LOG_DIR[AST_CONFIG_MAX_PATH]

Definition at line 218 of file asterisk.c.

Referenced by csv_log(), init_logger(), load_config(), load_module(), make_logchannel(), reload_logger(), testclient_exec(), testserver_exec(), and writefile().

char ast_config_AST_MODULE_DIR[AST_CONFIG_MAX_PATH]

Definition at line 214 of file asterisk.c.

Referenced by __load_resource(), add_module(), complete_fn(), file_ok_sel(), and load_modules().

char ast_config_AST_MONITOR_DIR[AST_CONFIG_MAX_PATH]

Definition at line 216 of file asterisk.c.

Referenced by ast_monitor_change_fname(), ast_monitor_start(), ast_monitor_stop(), chanspy_exec(), and mixmonitor_exec().

char ast_config_AST_PID[AST_CONFIG_MAX_PATH]

Definition at line 222 of file asterisk.c.

char ast_config_AST_RUN_DIR[AST_CONFIG_MAX_PATH]

Definition at line 224 of file asterisk.c.

char ast_config_AST_SOCKET[AST_CONFIG_MAX_PATH]

Definition at line 223 of file asterisk.c.

char ast_config_AST_SPOOL_DIR[AST_CONFIG_MAX_PATH]

Definition at line 215 of file asterisk.c.

Referenced by conf_run(), dictate_exec(), hasvoicemail_internal(), load_module(), and play_mailbox_owner().

char ast_config_AST_VAR_DIR[AST_CONFIG_MAX_PATH]

Definition at line 217 of file asterisk.c.

Referenced by ast_linear_stream(), build_filename(), dial_exec_full(), make_filename(), and reload_firmware().