--- pbx_dundi.c-orig 2008-10-31 12:22:55.000000000 +0100 +++ pbx_dundi.c 2008-10-31 15:02:32.000000000 +0100 @@ -101,6 +101,7 @@ static int netsocket = -1; static pthread_t netthreadid = AST_PTHREADT_NULL; static pthread_t precachethreadid = AST_PTHREADT_NULL; +static pthread_t clearcachethreadid = AST_PTHREADT_NULL; static unsigned int tos = 0; static int dundidebug = 0; static int authdebug = 0; @@ -2156,6 +2157,39 @@ return NULL; } +static void *process_clearcache(void *ignore) +{ + struct ast_db_entry *db_entry, *db_winner; + char expiry[64]; + char *end; + int strip = strlen("/dundi/cache") + 1; + + while (!dundi_shutdown) { + db_entry = ast_db_gettree("dundi/cache", NULL); + while (db_entry) { + if ((end = strchr(db_entry->data, '|'))) { + strncpy(expiry, db_entry->data, end - db_entry->data); + expiry[end - db_entry->data] = '\0'; + if (atol(expiry) < time(NULL)) { + db_winner = db_entry; + if (dundidebug) + ast_verbose("DUNDI cache entry expired, clearing %s\n", db_winner->key); + } else + db_winner = NULL; + } else + db_winner = NULL; + db_entry = db_entry->next; + if (db_winner) { + ast_db_del("dundi/cache", db_winner->key + strip); + } + } + sleep(300); + } + + clearcachethreadid = AST_PTHREADT_NULL; + return NULL; +} + static void *process_precache(void *ign) { struct dundi_precache_queue *qe; @@ -2197,6 +2231,7 @@ { ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL); ast_pthread_create_background(&precachethreadid, NULL, process_precache, NULL); + ast_pthread_create_background(&clearcachethreadid, NULL, process_clearcache, NULL); return 0; } @@ -4776,7 +4811,7 @@ static int unload_module(void) { - pthread_t previous_netthreadid = netthreadid, previous_precachethreadid = precachethreadid; + pthread_t previous_netthreadid = netthreadid, previous_precachethreadid = precachethreadid, previous_clearcachethreadid = clearcachethreadid; ast_module_user_hangup_all(); /* Stop all currently running threads */ @@ -4789,7 +4824,11 @@ pthread_kill(previous_precachethreadid, SIGURG); pthread_join(previous_precachethreadid, NULL); } - + if (previous_clearcachethreadid != AST_PTHREADT_NULL) { + pthread_kill(previous_clearcachethreadid, SIGURG); + pthread_join(previous_clearcachethreadid, NULL); + } + ast_cli_unregister_multiple(cli_dundi, sizeof(cli_dundi) / sizeof(struct ast_cli_entry)); ast_unregister_switch(&dundi_switch); ast_custom_function_unregister(&dundi_function);