/*
 * Function: pg_connect
 *
 * Parses a Zabbix agent request and returns a PostgreSQL connection.
 *
 * See: http://www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-PQCONNECTDB
 *
 * Parameter [request]: Zabbix agent request structure.
 *          The following parameters may be set:
 *
 *          0: connection string (default: DEFAULT_CONN_STRING)
 *          1: connection database (default: DEFAULT_CONN_DBNAME)
 *
 * Returns: Valid PostgreSQL connection or NULL on error
 */
 PGconn    *pg_connect(AGENT_REQUEST *request)
 {
    const char  *__function_name = "pg_connect";
    PGconn      *conn = NULL;
    char        *param_connstring = NULL, *param_dbname = NULL;
    char        connstring[MAX_STRING_LEN], *c = NULL;
    int         param_connstring_len = 0, param_dbname_len = 0, connstring_len = 0;;

    zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
    
    // get connection string from first parameter
    param_connstring = get_rparam(request, PARAM_CONN_STRING);
    param_connstring = (NULL == param_connstring) ? DEFAULT_CONN_STRING : param_connstring;
    param_connstring_len = strlen(param_connstring);

    // get database name from second parameter
    param_dbname = get_rparam(request, PARAM_DBNAME);
    param_dbname = (NULL == param_dbname) ? DEFAULT_CONN_DBNAME : param_dbname;
    param_dbname_len = strisnull(param_dbname) ? 0 : strlen(param_dbname);

    // create buffer to concat connection string and database name
    zbx_strlcpy(connstring, param_connstring, sizeof(connstring));
    c = connstring;

    // append dbname= key
    if (!strisnull(param_dbname)) {
        if (!strisnull(connstring))
            c = strcat2(c, " ");

        c = strcat(c, "dbname=");
        c = strcat(c, param_dbname);
    }

    // append application name
    if (!strisnull(connstring))
        c = strcat2(c, " ");
    c = strcat(c, "application_name='" STRVER "'");

    // connect
    zabbix_log(LOG_LEVEL_DEBUG, "Connecting to PostgreSQL with: %s", connstring);
    conn = PQconnectdb(connstring);
    if(CONNECTION_OK != PQstatus(conn)) {
        zabbix_log(LOG_LEVEL_ERR, "Failed to connect to PostgreSQL in %s():\n%s", __function_name, PQerrorMessage(conn));
        PQfinish(conn);
        conn = NULL;
    }

    zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
    return conn;
 }
예제 #2
0
/*
 * Custom key pg.index.discovery
 *
 * Parameters:
 *   0:  connection string
 *   1:  connection database
 *   2:  search mode: deep (default) | shallow
 *   3:  filter by schema name
 *   4:  filter by table name
 *
 * Returns all known indexes in a PostgreSQL database
 *
 * Returns:
 * {
 *        "data":[
 *                {
 *                        "{#OID}":"12345",
 *                        "{#INDEX}":"MyIndex",
 *                        "{#DATABASE}":"MyDatabase",
 *                        "{#SCHEMA}":"public",
 *                        "{#TABLE}":"MyTable",
 *                        "{#OWNER}":"postgres",
 *                        "{#ACCESS}":"btree|hash"}]}
 */
int    PG_INDEX_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
    int         ret = SYSINFO_RET_FAIL;                 // Request result code
    const char  *__function_name = "PG_DB_DISCOVERY";   // Function name for log file
    
    char        query[MAX_STRING_LEN], buffer[MAX_STRING_LEN];
    char        *c = NULL;

    char        *param_mode = NULL, *param_table = NULL, *param_schema = NULL;
    
    zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

    // build the query
    zbx_strlcpy(query, PGSQL_DISCOVER_INDEXES, sizeof(query));
    c = query;

    // filter by schema name
    param_schema = get_rparam(request, PARAM_FIRST + 1);
    if(!strisnull(param_schema)) {
        zbx_snprintf(buffer, sizeof(buffer), " AND n.nspname = '%s'", param_schema);
        c = strcat2(c, buffer);
    }

    // filter by table name
    param_table = get_rparam(request, PARAM_FIRST + 2);
    if(!strisnull(param_table)) {
        zbx_snprintf(buffer, sizeof(buffer), " AND t.relname = '%s'", param_table);
        c = strcat2(c, buffer);
    }

    // build results
    param_mode = get_rparam(request, PARAM_FIRST);
    if (strisnull(param_mode) || 0 == strcmp(param_mode, "deep")) {
        ret = pg_get_discovery_wide(request, result, query, NULL);
    } else if (0 == strcmp(param_mode, "shallow")) {
        ret = pg_get_discovery(request, result, query, NULL);
    } else {
        SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Invalid search mode parameter: %s", param_mode));
    }

    zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
    return ret;
}
예제 #3
0
int main(void)
{
  $tainted char *x, *z, *a, *b, *e;
  char *y, *w, *c, *d, *f;

  char *a1 = strcat1(x, y);
  char *a2 = strcat2(w, z);
  strcat(a, c, e);
  strcat(d, b, f);
}
int main()
{
   char s[] = "foo";
   char t[] = "bar";
   strcat2(&s[0], &t[0]);
   printf("This is the new one %s\n", s);

   int i;   
   for(i = 0; s[i] != '\0'; i++)		//print out the new concatenated string.
       printf("%c\n", s[i]);
   return 0;
}
예제 #5
0
파일: dso.cpp 프로젝트: DennyDL/spiderPro
int DsoManager::load(char* path,const char*name)
{
	Module *module  = new Module();
	char * npath = strcat2(3, path, name, ".so");

	void* handle = dlopen(npath,RTLD_GLOBAL | RTLD_NOW);
	if(handle == NULL)
		return MODULE_ERR;

	void *rv = (dlsym(handle,name));
	if(rv == NULL)
        return MODULE_ERR;


//	dlclose(handle);
	module = (Module *)rv;//module结构体的入口
//	module->init();//调用初始化函数
//暂时不需要init();找到module入口地址就可以了

	this->m_modules.insert(pair<string,Module*>(name,module));//插入管理的map中以便以后查询找到快速找到相应的模块入口地址

	return MODULE_OK;

}
예제 #6
0
static void playmedia(char *rootpath, char *modname)
{
    char filename[200];
    u32 buttonsold;
    SceCtrlData pad;
    u32 remoteButtons, remoteButtonsOld = 0;
    int codec;
    int finished = 0;

    filename[0] = 0;
    strcat2(filename, rootpath);
    strcat2(filename, modname);

    pspDebugScreenClear();
    printf("%s\n\n", banner);
    printf("loading media File : %s\n", modname);

    //determine codec of the file
    for (codec = 0; codec <= codecnum; codec++) {
	char *ptr = &(stubs[codec].extension[0]);
	while (*ptr != 0) {
	    if (strncasecmp(&modname[strlen(modname) - 3], ptr, 3) == 0) {
		decoder = &stubs[codec];
		break;
	    }
	    ptr += 4;
	}
    }

    decoder->init(0);
    if (decoder->load(filename)) {
	decoder->play();

	pspDebugScreenSetXY(0, 32);
	printf("X = Pause/Resume.  START = Tune Select\n");
	pspDebugScreenSetXY(0, 26);
	printf("Playing\n\n");

	forceskip = 0;

	sceCtrlReadBufferPositive(&pad, 1);
	sceHprmPeekCurrentKey(&remoteButtons);

	buttonsold = pad.Buttons;
	remoteButtonsOld = remoteButtons;
	while (finished == 0) {
	    sceDisplayWaitVblankStart();
	    sceCtrlReadBufferPositive(&pad, 1);
	    sceHprmPeekCurrentKey(&remoteButtons);

	    // Check if we have hit the end of tune
	    if (loopmode != 0) {
		if (decoder->eos != 0) {
		    if (decoder->eos() == 1) {	// End of file, advance in playlist
			pad.Buttons = PSP_CTRL_RTRIGGER;
		    }
		}
	    }

	    if (pad.Buttons != buttonsold) {
		if (pad.Buttons & PSP_CTRL_LTRIGGER) {	// Previous tune
		    forceskip = 1;
		    finished = 1;
		}
		if (pad.Buttons & PSP_CTRL_RTRIGGER) {	// Next tune
		    forceskip = 2;
		    finished = 1;
		}
		if (pad.Buttons & PSP_CTRL_TRIANGLE)
		    loopmode = !loopmode;
		if (pad.Buttons & PSP_CTRL_CIRCLE)
		    decoder->stop();
		if (pad.Buttons & PSP_CTRL_CROSS)
		    decoder->pause();
		if (pad.Buttons & PSP_CTRL_START)
		    finished = 1;
		buttonsold = pad.Buttons;
	    }
	    if (remoteButtons != remoteButtonsOld && !(remoteButtons & PSP_HPRM_HOLD)) {
		if (remoteButtons & PSP_HPRM_PLAYPAUSE)
		    decoder->pause();
		if (remoteButtons & PSP_HPRM_BACK) {
		    forceskip = 1;
		    finished = 1;
		}
		if (remoteButtons & PSP_HPRM_FORWARD) {
		    forceskip = 2;
		    finished = 1;
		}
		remoteButtonsOld = remoteButtons;
	    }
	    //  Show loop status
	    pspDebugScreenSetXY(58, 1);
	    if (loopmode == 0) {
		printf(" LOOP  ");
	    } else {
		printf("ADVANCE");
	    }
	    //  Show the time
	    if (decoder->time != NULL) {
		char time[200];
		decoder->time(time);
		pspDebugScreenSetXY(58, 0);
		printf("%s", time);
		pspDebugScreenSetXY(0, 32);
	    }
	}
	decoder->stop();
	decoder->end();
    }
}