Skip to content
Browse files

pluginify the config

  • Loading branch information...
1 parent 4c0c801 commit e6cadeaef9b2236d6d3dfeaa1599b3736d8e7cd8 @sugendran sugendran committed Dec 13, 2012
Showing with 91 additions and 24 deletions.
  1. +70 −23 graphdat.c
  2. +20 −0 php_graphdat.h
  3. +1 −1 scripts/graphdat.php
View
93 graphdat.c
@@ -99,9 +99,13 @@ ZEND_GET_MODULE(graphdat)
* Grab values from the php.ini file
*/
PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("graphdat.socketFile", "/tmp/gd.agent.sock", PHP_INI_ALL, OnUpdateString, socketFile, zend_graphdat_globals, graphdat_globals)
- STD_PHP_INI_ENTRY("graphdat.socketPort", "26873", PHP_INI_ALL, OnUpdateLong, socketPort, zend_graphdat_globals, graphdat_globals)
- STD_PHP_INI_ENTRY("graphdat.debug", "false", PHP_INI_ALL, OnUpdateBool, debug, zend_graphdat_globals, graphdat_globals)
+ STD_PHP_INI_ENTRY("graphdat.socketFile", "/tmp/gd.agent.sock", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, socketFile, zend_graphdat_globals, graphdat_globals)
+ STD_PHP_INI_ENTRY("graphdat.socketPort", "26873", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateLong, socketPort, zend_graphdat_globals, graphdat_globals)
+ STD_PHP_INI_ENTRY("graphdat.debug", "false", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, debug, zend_graphdat_globals, graphdat_globals)
+ STD_PHP_INI_ENTRY("graphdat.enable_joomla", "false", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, enable_joomla, zend_graphdat_globals, graphdat_globals)
+ STD_PHP_INI_ENTRY("graphdat.enable_drupal", "false", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, enable_drupal, zend_graphdat_globals, graphdat_globals)
+ STD_PHP_INI_ENTRY("graphdat.enable_magento", "false", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, enable_magento, zend_graphdat_globals, graphdat_globals)
+ STD_PHP_INI_ENTRY("graphdat.enable_cakephp", "false", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, enable_cakephp, zend_graphdat_globals, graphdat_globals)
PHP_INI_END()
/*
@@ -113,13 +117,60 @@ static void php_graphdat_init_globals(zend_graphdat_globals *graphdat_globals TS
graphdat_globals->socketFD = -1;
}
+void setPlugins(TSRMLS_D)
+{
+ // work out what plugins are needed
+ if(!GRAPHDAT_GLOBALS(enable_joomla) && !GRAPHDAT_GLOBALS(enable_drupal) && !GRAPHDAT_GLOBALS(enable_magento) && !GRAPHDAT_GLOBALS(enable_cakephp))
+ {
+ // if none are enabled then we enable them all
+ GRAPHDAT_GLOBALS(enable_joomla) = 1;
+ GRAPHDAT_GLOBALS(enable_drupal) = 1;
+ GRAPHDAT_GLOBALS(enable_magento) = 1;
+ GRAPHDAT_GLOBALS(enable_cakephp) = 1;
+ GRAPHDAT_GLOBALS(all_plugins_enabled) = 1;
+ }
+ else
+ {
+ GRAPHDAT_GLOBALS(plugins).count = GRAPHDAT_GLOBALS(enable_joomla) + GRAPHDAT_GLOBALS(enable_drupal) + GRAPHDAT_GLOBALS(enable_magento) + GRAPHDAT_GLOBALS(enable_cakephp);
+ GRAPHDAT_GLOBALS(plugins).array = malloc(sizeof(struct graphdat_plugin) * GRAPHDAT_GLOBALS(plugins).count);
+ int index = 0;
+ if(GRAPHDAT_GLOBALS(enable_joomla))
+ {
+ struct graphdat_plugin *plugin = &GRAPHDAT_GLOBALS(plugins).array[index++];
+ plugin->isAvailable = hasJoomla;
+ plugin->getPath = getJoomlaPath;
+ }
+ if(GRAPHDAT_GLOBALS(enable_drupal))
+ {
+ struct graphdat_plugin *plugin = &GRAPHDAT_GLOBALS(plugins).array[index++];
+ plugin->isAvailable = hasDrupal7;
+ plugin->getPath = getDrupal7Path;
+ }
+ if(GRAPHDAT_GLOBALS(enable_magento))
+ {
+ struct graphdat_plugin *plugin = &GRAPHDAT_GLOBALS(plugins).array[index++];
+ plugin->isAvailable = hasMagento;
+ plugin->getPath = getMagentoPath;
+ }
+ if(GRAPHDAT_GLOBALS(enable_cakephp))
+ {
+ struct graphdat_plugin *plugin = &GRAPHDAT_GLOBALS(plugins).array[index++];
+ plugin->isAvailable = hasCake;
+ plugin->getPath = getCakePath;
+ }
+ }
+}
+
/*
* What to do at module init
*/
PHP_MINIT_FUNCTION(graphdat)
{
ZEND_INIT_MODULE_GLOBALS(graphdat, php_graphdat_init_globals, NULL);
REGISTER_INI_ENTRIES();
+
+ setPlugins(TSRMLS_C);
+
return SUCCESS;
}
@@ -169,6 +220,13 @@ PHP_MINFO_FUNCTION(graphdat)
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
+
+ if(GRAPHDAT_GLOBALS(all_plugins_enabled))
+ {
+ php_info_print_table_start();
+ php_info_print_table_header(1, "All plugins are enabled because none where chosen");
+ php_info_print_table_end();
+ }
}
PHP_FUNCTION(graphdat_begin)
@@ -200,34 +258,23 @@ static char* getRequestPath(size_t *slen TSRMLS_DC)
char * result;
size_t pluginLen;
zval **requestUriData;
- int found = 1;
- if(hasMagento(TSRMLS_C))
+ int count = GRAPHDAT_GLOBALS(plugins).count;
+ int i;
+ for(i=0; i < count && result == NULL; i++)
{
- result = getMagentoPath(&pluginLen TSRMLS_CC);
+ struct graphdat_plugin *plugin = &GRAPHDAT_GLOBALS(plugins).array[i];
+ if(plugin->isAvailable(TSRMLS_C))
+ {
+ result = plugin->getPath(&pluginLen TSRMLS_CC);
+ }
}
- else if(hasDrupal7(TSRMLS_C))
- {
- result = getDrupal7Path(&pluginLen TSRMLS_CC);
- }
- else if(hasJoomla(TSRMLS_C))
- {
- result = getJoomlaPath(&pluginLen TSRMLS_CC);
- }
- else if(hasCake(TSRMLS_C))
- {
- result = getCakePath(&pluginLen TSRMLS_CC);
- }
- // disabled until we can get to the route info
- // else if(hasWordpress(TSRMLS_C))
- // {
- // result = getWordpressPath(&pluginLen TSRMLS_CC);
- // }
if(result != NULL)
{
*slen = pluginLen;
return result;
}
// looks like we can't do any magic
+ int found = 1;
zval *zServerVars = PG(http_globals)[TRACK_VARS_SERVER];
// the server globals should never be null....
if(zServerVars == NULL)
View
20 php_graphdat.h
@@ -35,7 +35,20 @@ extern zend_module_entry graphdat_module_entry;
# define PHP_GRAPHDAT_API
#endif
+typedef int (*pfnAvail)(TSRMLS_D);
+typedef char* (*pfnGetPath)(size_t *slen TSRMLS_DC);
+struct graphdat_plugin
+{
+ pfnAvail isAvailable;
+ pfnGetPath getPath;
+};
+
+struct graphdat_plugin_list
+{
+ int count;
+ struct graphdat_plugin *array;
+};
PHP_MINIT_FUNCTION(graphdat);
PHP_MSHUTDOWN_FUNCTION(graphdat);
@@ -60,6 +73,13 @@ ZEND_BEGIN_MODULE_GLOBALS(graphdat)
int isDirty;
struct timeval requestStart;
struct graphdat_timer_list timers;
+ struct graphdat_plugin_list plugins;
+ // ini file items for plugins
+ int enable_joomla;
+ int enable_drupal;
+ int enable_magento;
+ int enable_cakephp;
+ int all_plugins_enabled;
ZEND_END_MODULE_GLOBALS(graphdat)
View
2 scripts/graphdat.php
@@ -17,7 +17,7 @@
graphdat_end("validate module");
//sleep(0.2);
graphdat_begin("get info");
- phpinfo(INFO_VARIABLES);
+ phpinfo();
graphdat_end("get info");
//sleep(0.5);

0 comments on commit e6cadea

Please sign in to comment.
Something went wrong with that request. Please try again.