]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-5168 --resolve
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 7 May 2013 19:09:42 +0000 (14:09 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 7 May 2013 19:10:03 +0000 (14:10 -0500)
src/switch_loadable_module.c

index 6f4b8638a7c90c66cd782b0d208153ec382140df..19c3c6b3cdb0c7691bff8ec018dc20becba0d008 100644 (file)
@@ -131,6 +131,7 @@ static void switch_loadable_module_runtime(void)
 static switch_status_t switch_loadable_module_process(char *key, switch_loadable_module_t *new_module)
 {
        switch_event_t *event;
+       int added = 0;
 
        new_module->key = switch_core_strdup(new_module->pool, key);
 
@@ -151,6 +152,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                        }
                }
@@ -198,6 +200,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                                switch_event_fire(&event);
+                                               added++;
                                        }
                                }
                        }
@@ -218,6 +221,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.dialplan_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -238,6 +242,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.timer_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -260,6 +265,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.application_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -282,6 +288,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.chat_application_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -304,6 +311,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.api_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -328,6 +336,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                                switch_event_fire(&event);
+                                               added++;
                                        }
                                        switch_core_hash_insert(loadable_modules.file_hash, ptr->extens[i], (const void *) ptr);
                                }
@@ -349,6 +358,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.speech_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -369,6 +379,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.asr_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -389,6 +400,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.directory_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -409,6 +421,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.chat_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -429,6 +442,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                        switch_event_fire(&event);
+                                       added++;
                                }
                                switch_core_hash_insert(loadable_modules.say_hash, ptr->interface_name, (const void *) ptr);
                        }
@@ -455,6 +469,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                                switch_event_fire(&event);
+                                               added++;
                                        }
                                }
 
@@ -481,6 +496,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
                                                switch_event_fire(&event);
+                                               added++;
                                        }
                                }
 
@@ -488,6 +504,17 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
                }
        }
 
+       if (!added) {
+               if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) {
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "generic");
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", new_module->key);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
+                       switch_event_fire(&event);
+                       added++;
+               }
+       }
+
        switch_mutex_unlock(loadable_modules.mutex);
        return SWITCH_STATUS_SUCCESS;
 
@@ -835,6 +862,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_chat_deliver(const char *dest_proto,
 static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t *old_module)
 {
        switch_event_t *event;
+       int removed = 0;
 
        switch_mutex_lock(loadable_modules.mutex);
 
@@ -858,6 +886,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "endpoint");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.endpoint_hash, ptr->interface_name);
                        }
@@ -893,6 +922,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "codec");
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                                switch_event_fire(&event);
+                                               removed++;
                                        }
                                }
                        }
@@ -909,6 +939,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "dialplan");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.dialplan_hash, ptr->interface_name);
                        }
@@ -925,6 +956,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "timer");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.timer_hash, ptr->interface_name);
                        }
@@ -951,6 +983,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "description", switch_str_nil(ptr->short_desc));
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "syntax", switch_str_nil(ptr->syntax));
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.application_hash, ptr->interface_name);
                        }
@@ -977,6 +1010,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "description", switch_str_nil(ptr->short_desc));
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "syntax", switch_str_nil(ptr->syntax));
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.chat_application_hash, ptr->interface_name);
                        }
@@ -1006,6 +1040,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "description", switch_str_nil(ptr->desc));
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "syntax", switch_str_nil(ptr->syntax));
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.api_hash, ptr->interface_name);
                        }
@@ -1034,6 +1069,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "file");
                                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->extens[i]);
                                                switch_event_fire(&event);
+                                               removed++;
                                        }
                                        switch_core_hash_delete(loadable_modules.file_hash, ptr->extens[i]);
                                }
@@ -1062,6 +1098,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "speech");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.speech_hash, ptr->interface_name);
                        }
@@ -1088,6 +1125,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "asr");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.asr_hash, ptr->interface_name);
                        }
@@ -1114,6 +1152,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "directory");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.directory_hash, ptr->interface_name);
                        }
@@ -1140,6 +1179,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "chat");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.chat_hash, ptr->interface_name);
                        }
@@ -1164,6 +1204,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "say");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                                switch_core_hash_delete(loadable_modules.say_hash, ptr->interface_name);
                        }
@@ -1182,6 +1223,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "management");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->relative_oid);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                        }
                }
@@ -1199,11 +1241,20 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "limit");
                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
                                        switch_event_fire(&event);
+                                       removed++;
                                }
                        }
                }
        }
 
+       if (!removed) {
+               if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "generic");
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", old_module->key);
+                       switch_event_fire(&event);
+                       removed++;
+               }
+       }
        switch_mutex_unlock(loadable_modules.mutex);
 
        return SWITCH_STATUS_SUCCESS;