/* * Function: dp_shutdown() * * Parameters: none * * Description: shutdown dialplan and cleanup memory * * * Returns: none */ void dp_shutdown (void) { if (g_dp_int.dial_timer != NULL) { (void)cprDestroyTimer(g_dp_int.dial_timer); g_dp_int.dial_timer = NULL; } FreeDialTemplates(); }
/* * Function: dp_init_template * * Parameters: maxSize - maximum size of the dialplan * * Description: initialize dialplan template from downloaded file * This is triggered by Adapter module when it triggers download of DP. * */ int dp_init_template(const char * dial_plan_string, int length) { static const char fname[] = "dp_init_template"; char *TemplateData = (char *) &dpLoadArea; DPINT_DEBUG(DEB_F_PREFIX"Reading Dialplan string. Length=[%d]\n", DEB_F_PREFIX_ARGS(DIALPLAN, fname), length); /* Clear existing dialplan templates before building a new one */ FreeDialTemplates(); memset(dpLoadArea, 0, sizeof(dpLoadArea)); //Copy over data memcpy (dpLoadArea, dial_plan_string, length); if (length == 0 || ParseDialTemplate(TemplateData) == FALSE) { if (kpml_get_state()) { /** * There is a error in the parsing so set the default dialplan when KPML is enabled */ DPINT_DEBUG(DEB_F_PREFIX"Loading Default Dialplan with KPML enabled", DEB_F_PREFIX_ARGS(DIALPLAN, fname)); memcpy(dpLoadArea, (const char *) KPML_DEFAULT_DIALPLAN, sizeof(KPML_DEFAULT_DIALPLAN)); length = sizeof(KPML_DEFAULT_DIALPLAN); TemplateData[length] = '\00'; (void) ParseDialTemplate(TemplateData); } else { /** * There is a error either in parsing so release any parsed dialplan structures */ DPINT_DEBUG(DEB_F_PREFIX"Loading Default Dialplan with KPML disabled", DEB_F_PREFIX_ARGS(DIALPLAN, fname)); FreeDialTemplates(); } return (-1); } DPINT_DEBUG(DEB_F_PREFIX"Successfully Parsed Dialplan. \n", DEB_F_PREFIX_ARGS(DIALPLAN, fname)); return (0); }
/* * Function: ParseDialTemplate() * * Parameters: parseptr - pointer to bytes to be parsed * * Description: Parse the contents of a dial template XML file * All Start and end tags are ignored * The empty element <TEMPLATE is parsed by ParseDialEntry * * Returns: false if parse fails else true */ boolean ParseDialTemplate (char *parseptr) { char buffer[MAX_TEMPLATE_LENGTH]; XMLToken tok; int LookKey; int LookEndKey; int errors = 0; int insideDialPlan = 0; LookKey = 0; LookEndKey = 0; FreeDialTemplates(); /* * reset the version stamp so that dialplans that do not contain versionStamp * tag will not keep the previous versionstamp. */ g_dp_version_stamp[0] = 0; if (parseptr == NULL) { debugif_printf("ParseDialTempate(): parseptr=NULL Returning.\n"); return (FALSE); } while ((tok = parse_xml_tokens(&parseptr, buffer, sizeof(buffer))) != TOK_EOF) { if (LookEndKey) { if (tok == TOK_RBRACKET) { LookEndKey = 0; } else if ((tok == TOK_KEYWORD) && !cpr_strcasecmp(buffer, "DIALTEMPLATE")) { insideDialPlan = 0; } } else if (tok == TOK_LBRACKET) { LookKey = 1; } else if ((LookKey != 0) && (tok == TOK_KEYWORD) && !cpr_strcasecmp(buffer, "DIALTEMPLATE")) { insideDialPlan = 1; } else if ((LookKey != 0) && (tok == TOK_KEYWORD) && !strcmp(buffer, "TEMPLATE")) { if (insideDialPlan) { errors += ParseDialEntry(&parseptr); } else { errors++; } } else if ((LookKey != 0) && (tok == TOK_KEYWORD) && !cpr_strcasecmp(buffer, "versionStamp")) { if (insideDialPlan) { /* <versionStamp> tag found. parse it */ errors += ParseDialVersion(&parseptr); } else { errors++; } } else if (tok == TOK_ENDLBRACKET) { LookEndKey = 1; } else { LookKey = 0; } } /* * If we had any parse errors, put them into the log */ log_clear(LOG_CFG_PARSE_DIAL); if (errors != 0) { log_msg(LOG_CFG_PARSE_DIAL, errors, DialTemplateFile); return (FALSE); } return (TRUE); }