== AsteriskSource/PbxConfig == * pbx/pbx_config.c * load_module * static char *config = "extensions.conf"; * cfg = ast_load(config); * static_config ¼³Á¤ * general category ¿¡ static variable ÀÌ ÀÖÀ¸¸é, ±× °ª¿¡ µû¶ó ¼³Á¤ * cxt = ast_category_browse(cfg, NULL); * ù¹ø° category struct pointer return * while(cxt) * category ¸íÀÌ general À̸é * cxt = ast_category_browse(cfg, cxt); * ´ÙÀ½ category ¸íÀ» ctx ¿¡ assign * continue * if ((con=ast_context_create(cxt))) * category ¸íÀÌ general ÀÌ ¾Æ´Ï¸é, ÀÌ À̸§¿¡ ¼ÓÇÏ´Â ast_struct con À» »ý¼ºÇÑ´Ù. {{{ struct ast_context { char name[AST_MAX_EXTENSION]; pthread_mutex_t lock; struct ast_exten *root; struct ast_context *next; }; }}} * * * * ast_context struct ÀÎ con ¿¡ ¼ÓÇÏ´Â variavle µéÀ» Àо con ¿¡ Ãß°¡ÇÑ´Ù. * v = ast_variable_browse(cfg, cxt); * while(v) * tc = strdup(v->value); * ext, pri, appl, data * ast_add_extension2(con, 0, ext, atoi(pri), appl, strdup(data), free) * v = v->next; * free(tc); * cxt = ast_category_browse(cfg, cxt); * ctx ¿¡ ´ÙÀ½ category struct pointer ¼³Á¤ * ast_destroy(cfg); * return 0; * pbx.c {{{ /* An extension context */ struct ast_context { /* Name of the context */ char name[AST_MAX_EXTENSION]; /* A lock to prevent multiple threads from clobbering the context */ pthread_mutex_t lock; /* The root of the list of extensions */ struct ast_exten *root; /* Link them together */ struct ast_context *next; }; }}} * struct ast_context *ast_context_create(char *name) * ÀÌ¹Ì Á¸ÀçÇϴ°¡ Á¡°Ë * tmp = malloc(sizeof(struct ast_context)); * strncpy(tmp->name, name, sizeof(tmp->name)); * category ¸íÀ» tpm->name ¿¡ assign ÇÑ´Ù. * contexts ¿Í ¿¬°á * return tmp; * int ast_add_extension2(struct ast_context *con, int replace, char *extension, int priority, char *application, void *data, void (*datad)(void *)) {{{ /* An extension */ struct ast_exten { char exten[AST_MAX_EXTENSION]; int priority; /* An extension */ struct ast_context *parent; /* Application to execute */ char app[AST_MAX_EXTENSION]; /* Data to use */ void *data; /* Data destructor */ void (*datad)(void *); /* Next highest priority with our extension */ struct ast_exten *peer; /* Extension with a greater ID */ struct ast_exten *next; }; }}} * tmp = malloc(sizeof(struct ast_exten)); * tmp struct ¿¡ ÇÊ¿äÇÑ °ª ¼³Á¤ * e = con->root; * while(e) * res= strcasecmp(e->exten, extension); * if (res == 0) * ÀÌ¹Ì °°Àº extension ÀÌ µî·ÏµÇ¾î ÀÖ´Â °æ¿ì * while(e) * if (e->priority == tmp->priority) * else if (e->priority > tmp->priority) * } * ep = e; * e = e->peer; * ep->peer = tmp; * return 0; * else if (res > 0) * con¿¡ ÀÌ¹Ì µî·ÏµÈ extension º¸´Ù »õ·Î¿î extension ÀÌ lexically Å©¸é * Insert ourselves just before 'e' * tmp->next = e; * el->next = tmp; or con->root = tmp; * return 0; * el = e; * e = e->next; * el->next = tmp; or con->root = tmp; * return 0; == config.c == * struct ast_config *ast_load(char *configfile) * configfile ÀÌ / ·Î ½ÃÀÛÇϸé fn ¿¡ ±×´ë·Î º¹»çÇÏ°í, ¾Æ´Ï¸é AST_CONFIG_DIR À» ¾Õ¿¡´Ù ºÙ¿©¼­ fn ¿¡ º¹»çÇÑ´Ù. * fn ÆÄÀÏÀ» open ÇÑ ÈÄ, ÇÑ ÁÙ¾¿ Àо ÇÊ¿äÇÑ ÀÛ¾÷À» ÇÑ´Ù. * ast_config struct ÀÎ tmp ¸¦ ¸¸µç´Ù. {{{ struct ast_config { /* Maybe this structure isn't necessary but we'll keep it for now */ struct ast_category *root; }; }}} * [ À¸·Î ½ÃÀÛÇϸé * ast_category struct ÀÎ tempc ¸¦ ¸¸µç´Ù. {{{ struct ast_category { char name[80]; struct ast_variable *root; struct ast_category *next; }; }}} * * tempc->name ¿¡ [] »çÀÌÀÇ À̸§À» asiign ÇÑ´Ù. * temp->root ¿¡´Â »õ·ÎÀÌ ¸¸µé¾îÁø tempc ¸¦ assign ÇÑ´Ù. * ¾Õ¿¡¼­ ¸¸µé¾îÁø tempc ¸¦ »õ·Î ¸¸µé¾îÁø tempc->next ¿¡ assign ÇÑ´Ù. * Áï [ ·Î ½ÃÀÛÇÏ¿© ] ·Î ³¡³ª´Â ÁÙÀº category list ·Î ¿¬°áÇÑ´Ù. * [ ·Î ½ÃÀÛÇÏÁö ¾Ê°í = ÀÌ ÀÖÀ¸¸é, * ast_variable struct ÀÎ v ¸¦ ¸¸µç´Ù. {{{ struct ast_variable { char *name; char *value; struct ast_variable *next; }; }}} * * = ¾ÕºÎºÐÀº name ¿¡ µÞºÎºÐÀº value ¿¡ assign ÇÑ´Ù. * category ÀÇ root ¿¡ v ¸¦ assign ÇÑ´Ù. * variable list ·Î ¿¬°á½ÃŲ´Ù. * temp ¸¦ return ÇÑ´Ù. * char *ast_category_browse(struct ast_config *config, char *prev) * prev °¡ NULL À̸é config->root->name À» return * prev À̸§ÀÇ category °¡ ÀÖÀ¸¸é, ´ÙÀ½ caterogy ÀÇ name À» return * struct ast_variable *ast_variable_browse(struct ast_config *config, char *category) * ÇØ´ç category ÀÇ Ã¹¹ø° ast_variable struct ¸¦ return * char *ast_variable_retrieve(struct ast_config *config, char *category, char *value) * ÇØ´çµÇ´Â category Áß ÇØ´çµÇ´Â variable ÀÇ value ¸¦ return