Wed Oct 28 15:49:00 2009

Asterisk developer's documentation


iax2-provision.h File Reference

IAX2 Provisioning protocol. More...

#include "iax2-parser.h"

Include dependency graph for iax2-provision.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PROV_FLAG_DEBUG   (1 << 3)
#define PROV_FLAG_DIS_CALLERID   (1 << 4)
#define PROV_FLAG_DIS_CALLWAIT   (1 << 5)
#define PROV_FLAG_DIS_CIDCW   (1 << 6)
#define PROV_FLAG_DIS_THREEWAY   (1 << 7)
#define PROV_FLAG_HEARTBEAT   (1 << 2)
#define PROV_FLAG_REGISTER   (1 << 0)
#define PROV_FLAG_SECURE   (1 << 1)
#define PROV_IE_AESKEY   14
#define PROV_IE_ALTSERVER   19
#define PROV_IE_FLAGS   12
#define PROV_IE_FORMAT   13
#define PROV_IE_GATEWAY   4
#define PROV_IE_IPADDR   2
#define PROV_IE_LANG   10
#define PROV_IE_NEWAESKEY   17
#define PROV_IE_PASS   7
#define PROV_IE_PORTNO   5
#define PROV_IE_PROVVER   18
#define PROV_IE_SERVERIP   15
#define PROV_IE_SERVERPASS   9
#define PROV_IE_SERVERPORT   16
#define PROV_IE_SERVERUSER   8
#define PROV_IE_SUBNET   3
#define PROV_IE_TOS   11
#define PROV_IE_USEDHCP   1
#define PROV_IE_USER   6

Functions

char * iax_prov_complete_template (char *line, char *word, int pos, int state)
char * iax_provflags2str (char *buf, int buflen, unsigned int flags)
int iax_provision_build (struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
int iax_provision_reload (void)
int iax_provision_unload (void)
int iax_provision_version (unsigned int *signature, const char *template, int force)


Detailed Description

IAX2 Provisioning protocol.

Definition in file iax2-provision.h.


Define Documentation

#define PROV_FLAG_DEBUG   (1 << 3)

Definition at line 41 of file iax2-provision.h.

#define PROV_FLAG_DIS_CALLERID   (1 << 4)

Definition at line 43 of file iax2-provision.h.

#define PROV_FLAG_DIS_CALLWAIT   (1 << 5)

Definition at line 44 of file iax2-provision.h.

#define PROV_FLAG_DIS_CIDCW   (1 << 6)

Definition at line 45 of file iax2-provision.h.

#define PROV_FLAG_DIS_THREEWAY   (1 << 7)

Definition at line 46 of file iax2-provision.h.

#define PROV_FLAG_HEARTBEAT   (1 << 2)

Definition at line 40 of file iax2-provision.h.

#define PROV_FLAG_REGISTER   (1 << 0)

Definition at line 38 of file iax2-provision.h.

#define PROV_FLAG_SECURE   (1 << 1)

Definition at line 39 of file iax2-provision.h.

#define PROV_IE_AESKEY   14

Definition at line 31 of file iax2-provision.h.

#define PROV_IE_ALTSERVER   19

Definition at line 36 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_FLAGS   12

Definition at line 29 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_FORMAT   13

Definition at line 30 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_GATEWAY   4

Definition at line 21 of file iax2-provision.h.

#define PROV_IE_IPADDR   2

Definition at line 19 of file iax2-provision.h.

#define PROV_IE_LANG   10

Definition at line 27 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_NEWAESKEY   17

Definition at line 34 of file iax2-provision.h.

#define PROV_IE_PASS   7

Definition at line 24 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_PORTNO   5

Definition at line 22 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_PROVVER   18

Definition at line 35 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_SERVERIP   15

Definition at line 32 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_SERVERPASS   9

Definition at line 26 of file iax2-provision.h.

#define PROV_IE_SERVERPORT   16

Definition at line 33 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_SERVERUSER   8

Definition at line 25 of file iax2-provision.h.

#define PROV_IE_SUBNET   3

Definition at line 20 of file iax2-provision.h.

#define PROV_IE_TOS   11

Definition at line 28 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_USEDHCP   1

Definition at line 18 of file iax2-provision.h.

#define PROV_IE_USER   6

Definition at line 23 of file iax2-provision.h.

Referenced by iax_provision_build().


Function Documentation

char* iax_prov_complete_template ( char *  line,
char *  word,
int  pos,
int  state 
)

Definition at line 155 of file iax2-provision.c.

References ast_mutex_lock(), ast_mutex_unlock(), iax_template::name, iax_template::next, strdup, and templates.

Referenced by iax2_prov_complete_template_3rd().

00156 {
00157    struct iax_template *c;
00158    int which=0;
00159    char *ret;
00160    ast_mutex_lock(&provlock);
00161    c = templates;
00162    while(c) {
00163       if (!strncasecmp(word, c->name, strlen(word))) {
00164          if (++which > state)
00165             break;
00166       }
00167       c = c->next;
00168    }
00169    if (c) {
00170       ret = strdup(c->name);
00171    } else
00172       ret = NULL;
00173    ast_mutex_unlock(&provlock);
00174    return ret;
00175 }

char* iax_provflags2str ( char *  buf,
int  buflen,
unsigned int  flags 
)

Definition at line 88 of file iax2-provision.c.

References iax_flags, and name.

Referenced by dump_prov_flags(), and iax_show_provisioning().

00089 {
00090    int x;
00091    if (!buf || buflen < 1) {
00092       return(NULL);
00093    }
00094    buf[0] = '\0';
00095    for (x=0;x<sizeof(iax_flags) / sizeof(iax_flags[0]); x++) {
00096       if (flags & iax_flags[x].value){
00097          strncat(buf, iax_flags[x].name, buflen - strlen(buf) - 1);
00098          strncat(buf, ",", buflen - strlen(buf) - 1);
00099       }
00100    }
00101    if (strlen(buf)) 
00102       buf[strlen(buf) - 1] = '\0';
00103    else
00104       strncpy(buf, "none", buflen - 1);
00105    return buf;
00106 }

int iax_provision_build ( struct iax_ie_data provdata,
unsigned int *  signature,
const char *  template,
int  force 
)

Definition at line 187 of file iax2-provision.c.

References iax_template::altserver, ast_db_put(), ast_mutex_lock(), ast_mutex_unlock(), iax_template::flags, iax_template::format, iax_ie_append_byte(), iax_ie_append_int(), iax_ie_append_short(), iax_ie_append_str(), iax_template_find(), iax_template::lang, iax_template::pass, iax_template::port, PROV_IE_ALTSERVER, PROV_IE_FLAGS, PROV_IE_FORMAT, PROV_IE_LANG, PROV_IE_PASS, PROV_IE_PORTNO, PROV_IE_PROVVER, PROV_IE_SERVERIP, PROV_IE_SERVERPORT, PROV_IE_TOS, PROV_IE_USER, prov_ver_calc(), iax_template::server, iax_template::serverport, iax_template::tos, and iax_template::user.

Referenced by iax2_provision(), and iax_provision_version().

00188 {
00189    struct iax_template *cur;
00190    unsigned int sig;
00191    char tmp[40];
00192    memset(provdata, 0, sizeof(*provdata));
00193    ast_mutex_lock(&provlock);
00194    cur = iax_template_find(template, 1);
00195    /* If no match, try searching for '*' */
00196    if (!cur)
00197       cur = iax_template_find("*", 1);
00198    if (cur) {
00199       /* found it -- add information elements as appropriate */
00200       if (force || strlen(cur->user))
00201          iax_ie_append_str(provdata, PROV_IE_USER, cur->user);
00202       if (force || strlen(cur->pass))
00203          iax_ie_append_str(provdata, PROV_IE_PASS, cur->pass);
00204       if (force || strlen(cur->lang))
00205          iax_ie_append_str(provdata, PROV_IE_LANG, cur->lang);
00206       if (force || cur->port)
00207          iax_ie_append_short(provdata, PROV_IE_PORTNO, cur->port);
00208       if (force || cur->server)
00209          iax_ie_append_int(provdata, PROV_IE_SERVERIP, cur->server);
00210       if (force || cur->serverport)
00211          iax_ie_append_short(provdata, PROV_IE_SERVERPORT, cur->serverport);
00212       if (force || cur->altserver)
00213          iax_ie_append_int(provdata, PROV_IE_ALTSERVER, cur->altserver);
00214       if (force || cur->flags)
00215          iax_ie_append_int(provdata, PROV_IE_FLAGS, cur->flags);
00216       if (force || cur->format)
00217          iax_ie_append_int(provdata, PROV_IE_FORMAT, cur->format);
00218       if (force || cur->tos)
00219          iax_ie_append_byte(provdata, PROV_IE_TOS, cur->tos);
00220       
00221       /* Calculate checksum of message so far */
00222       sig = prov_ver_calc(provdata);
00223       if (signature)
00224          *signature = sig;
00225       /* Store signature */
00226       iax_ie_append_int(provdata, PROV_IE_PROVVER, sig);
00227       /* Cache signature for later verification so we need not recalculate all this */
00228       snprintf(tmp, sizeof(tmp), "v0x%08x", sig);
00229       ast_db_put("iax/provisioning/cache", template, tmp);
00230    } else
00231       ast_db_put("iax/provisioning/cache", template, "u");
00232    ast_mutex_unlock(&provlock);
00233    return cur ? 0 : -1;
00234 }

int iax_provision_reload ( void   ) 

Definition at line 486 of file iax2-provision.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_db_deltree(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), cfg, iax_template::dead, free, iax_process_template(), iax_provision_init(), LOG_NOTICE, iax_template::next, option_verbose, templates, and VERBOSE_PREFIX_3.

Referenced by load_module().

00487 {
00488    struct ast_config *cfg;
00489    struct iax_template *cur, *prev, *next;
00490    char *cat;
00491    int found = 0;
00492    if (!provinit)
00493       iax_provision_init();
00494    /* Mark all as dead.  No need for locking */
00495    cur = templates;
00496    while(cur) {
00497       cur->dead = 1;
00498       cur = cur->next;
00499    }
00500    cfg = ast_config_load("iaxprov.conf");
00501    if (cfg) {
00502       /* Load as appropriate */
00503       cat = ast_category_browse(cfg, NULL);
00504       while(cat) {
00505          if (strcasecmp(cat, "general")) {
00506             iax_process_template(cfg, cat, found ? "default" : NULL);
00507             found++;
00508             if (option_verbose > 2)
00509                ast_verbose(VERBOSE_PREFIX_3 "Loaded provisioning template '%s'\n", cat);
00510          }
00511          cat = ast_category_browse(cfg, cat);
00512       }
00513       ast_config_destroy(cfg);
00514    } else
00515       ast_log(LOG_NOTICE, "No IAX provisioning configuration found, IAX provisioning disabled.\n");
00516    ast_mutex_lock(&provlock);
00517    /* Drop dead entries while locked */
00518    prev = NULL;
00519    cur = templates;
00520    while(cur) {
00521       next = cur->next;
00522       if (cur->dead) {
00523          if (prev)
00524             prev->next = next;
00525          else
00526             templates = next;
00527          free(cur);
00528       } else 
00529          prev = cur;
00530       cur = next;
00531    }
00532    ast_mutex_unlock(&provlock);
00533    /* Purge cached signature DB entries */
00534    ast_db_deltree("iax/provisioning/cache", NULL);
00535    return 0;
00536    
00537 }

int iax_provision_unload ( void   ) 

Definition at line 479 of file iax2-provision.c.

References ast_cli_unregister().

Referenced by __unload_module().

00480 {
00481    provinit = 0;
00482    ast_cli_unregister(&cli_show_provisioning);
00483    return 0;
00484 }

int iax_provision_version ( unsigned int *  signature,
const char *  template,
int  force 
)

Definition at line 236 of file iax2-provision.c.

References ast_db_get(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), iax_provision_build(), LOG_DEBUG, and option_debug.

Referenced by check_provisioning().

00237 {
00238    char tmp[80] = "";
00239    struct iax_ie_data ied;
00240    int ret=0;
00241    memset(&ied, 0, sizeof(ied));
00242 
00243    ast_mutex_lock(&provlock);
00244    ast_db_get("iax/provisioning/cache", template, tmp, sizeof(tmp));
00245    if (sscanf(tmp, "v%30x", version) != 1) {
00246       if (strcmp(tmp, "u")) {
00247          ret = iax_provision_build(&ied, version, template, force);
00248          if (ret)
00249             ast_log(LOG_DEBUG, "Unable to create provisioning packet for '%s'\n", template);
00250       } else
00251          ret = -1;
00252    } else if (option_debug)
00253       ast_log(LOG_DEBUG, "Retrieved cached version '%s' = '%08x'\n", tmp, *version);
00254    ast_mutex_unlock(&provlock);
00255    return ret;
00256 }


Generated on Wed Oct 28 15:49:00 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6