コード例 #1
0
ファイル: command.c プロジェクト: ThetaGroup/forask
int taskShow(){
	openDb();
	char *errMsg;
	char **dbResult;
	int nRow,nColumn;
	long currentAreaId;
	
	int ret=sqlite3_get_table(
			conn,
			QUERY_CURRENT_AREA_ID_SQL,
			&dbResult,
			&nRow,
			&nColumn,
			&errMsg
		);
	if (ret==SQLITE_OK){
		currentAreaId=atol(dbResult[1]);
		printf("Current area is %ld...\n",currentAreaId);
	}else{
		printf("Query current area failed...\n");
		closeDb();
		return -1;
	}

	char *selectSql=(char*)malloc(1024);
	sprintf(selectSql,QUERY_TASK_BY_STATE_SQL,TASK_STATE_ACTIVE,currentAreaId);

	ret=sqlite3_get_table(
			conn,
			selectSql,
			&dbResult,
			&nRow,
			&nColumn,
			&errMsg
		);
	if (ret==SQLITE_OK){
		printf("%d tasks to do in total:\n",nRow);
		for (int i=0;i<nRow;i++){
			int startPos=(i+1)*nColumn;
			printf("%s\t%s\n",dbResult[startPos],dbResult[startPos+1]);
		}
	}else{
		printf("Query tasks to do failed...\n");
		closeDb();
		return -1;
	}

	closeDb();
	return 0;
}
コード例 #2
0
ファイル: commercials.C プロジェクト: TravisKraatz/cinelerra
Commercials::
~Commercials()
{
	closeDb();
	delete mdb;
	tracks.remove_all_objects();
}
コード例 #3
0
ファイル: command.c プロジェクト: ThetaGroup/forask
int taskAdd(char *title,char *desc){
	openDb();
	char *errMsg;
	char *insertSql=(char*)malloc(1024);

	char **dbResult;
	int nRow,nColumn;
	long currentAreaId;	

	int ret=sqlite3_get_table(
			conn,
			QUERY_CURRENT_AREA_ID_SQL,
			&dbResult,
			&nRow,
			&nColumn,
			&errMsg
		);

	if (ret==SQLITE_OK){
		currentAreaId=atol(dbResult[1]);
		printf("Current area is %ld...\n",currentAreaId);
	}else{
		printf("Query current area failed...\n");
		closeDb();
		return -1;
	}

	sprintf(insertSql,INSERT_TASK_SQL,title,desc,TASK_STATE_ACTIVE,currentAreaId);	
	ret=sqlite3_exec(
			conn,
			insertSql,
			NULL,
			NULL,
			&errMsg
		);
	if (ret!=SQLITE_OK){
		LOG("%s\n",errMsg);
	}else{
		printf("Task %s added and its initial state is ACTIVE.\n",title);
	}
	free(insertSql);
	closeDb();

	return 0;
}
コード例 #4
0
ファイル: ejsDb.c プロジェクト: jsjohnst/ejscript
/*
 *  Called by the garbage colllector
 */
static EjsVar *finalizeDb(Ejs *ejs, EjsDb *db)
{
    if (db->sdb) {
        ejsSetDbMemoryContext(db->tls, db->arena);
        closeDb(ejs, db, 0, 0);
        db->sdb = 0;
    }
    return 0;
}
コード例 #5
0
ファイル: bmclient.c プロジェクト: JackWangCUMT/bitmeteros
int main(int argc, char **argv){
 // Interpret the command-lin arguments and decide if they make sense
	int status = parseArgs(argc, argv, &prefs);

    printf(COPYRIGHT);
	setLogLevel(LOG_INFO);
	
	if (status == FAIL){
	 // The command-line was duff...
		if (prefs.errorMsg != NULL){
		 // ...and we have a specific error to show the user
			printf("Error: %s\n", prefs.errorMsg);
		} else {
		 // ...and we have no specific error message, so show a vague one
			printf("BitMeter did not understand. ");
		}
		printf("Use the '-h' option to display help.\n");

	} else if (prefs.help){
	 // Dump the help info and stop
		doHelp();

	} else if (prefs.version){
	 // Show the version and stop
		doVersion();

	} else {
	 // We will need to go to the database if we end up here
		openDb();
        dbVersionCheck();

		switch(prefs.mode){
			case PREF_MODE_DUMP:
				doDump();
				break;
			case PREF_MODE_SUMMARY:
				doSummary();
				break;
			case PREF_MODE_MONITOR:
				doMonitor();
				break;
			case PREF_MODE_QUERY:
				doQuery();
				break;
			default:
				assert(FALSE); // Any other mode value should cause parseArgs to fail
				break;
		}

		closeDb();
	}

	return 0;
}
コード例 #6
0
ファイル: bmws.c プロジェクト: JackWangCUMT/bitmeteros
static void readDbConfig(){
 // Read in some config parameters from the database
	openDb();
	setCustomLogLevel();
	dbVersionCheck();
	int allowRemote = getConfigInt(CONFIG_WEB_ALLOW_REMOTE, 0);
	allowRemoteConnect = (allowRemote >= ALLOW_REMOTE_CONNECT);
	allowRemoteAdmin   = (allowRemote == ALLOW_REMOTE_ADMIN);
	port = getPort();
    getWebRootPath(webRoot);
	closeDb();
}
コード例 #7
0
ファイル: commercials.C プロジェクト: TravisKraatz/cinelerra
int Commercials::
scan_media()
{
	cancelled = 0;
	scan_status = new ScanStatus(this, 30, 30, 2, 2,
		cancelled, "Cutting Ads");
	if( !openDb() ) {
		scan_video();
		commitDb();
		closeDb();
	}
	delete scan_status;
	scan_status = 0;
	return 0;
}
コード例 #8
0
ファイル: command.c プロジェクト: ThetaGroup/forask
int areaShow(){
	openDb();
	char *errMsg;
	char **dbResult;
	int nRow,nColumn;
	
	int ret=sqlite3_get_table(
			conn,
			QUERY_ALL_AREA_SQL,
			&dbResult,
			&nRow,
			&nColumn,
			&errMsg
		);
	if (ret==SQLITE_OK){
		printf("%d areas in total:\n",nRow);
		for (int i=0;i<nRow;i++){
			printf("%s\n",dbResult[(i+1)*nColumn]);
		}
	}else{
		printf("Query all areas failed...\n");
	}

	ret=sqlite3_get_table(
			conn,
			QUERY_CURRENT_AREA_SQL,
			&dbResult,
			&nRow,
			&nColumn,
			&errMsg
		);
	if (ret==SQLITE_OK){
		if (dbResult[1]==NULL){
			printf("No selected area.\n");
		}else{
			printf("Selected area:%s\n",dbResult[1]);
		}
	}


	closeDb();
	return 0;
}
コード例 #9
0
int PinnedMediaDBManager::openDb()
{
    int rv = 0;
    char path[CCD_PATH_MAX_LENGTH];
    memset(path, 0, sizeof(path));
    DiskCache::getPathForPIN(sizeof(path), path);

    m_dbpath.assign(path);
    m_dbpath.append("db");

    rv = Util_CreatePath(m_dbpath.c_str(), VPL_FALSE);
    if (rv) {
        LOG_ERROR("Failed to create directory for %s", m_dbpath.c_str());
        goto end;
    }

    rv = Util_OpenDbHandle(m_dbpath.c_str(), true, true, &m_db);
    if (rv) {
        LOG_ERROR("Util_OpenDbHandle(%s):%d", m_dbpath.c_str(), rv);
        goto end;
    }

    CHECK_DB_HANDLE(rv, m_db, end);

    {
        int err = 0;
        char* errmsg = NULL;
        err = sqlite3_exec(m_db, SQL_CREATE_PINNED_MEDIA_ITEM_TABLE, NULL, NULL, &errmsg);
        if (err != SQLITE_OK) {
            LOG_ERROR("Failed to test/create tables: %d, %s", err, errmsg);
            sqlite3_free(errmsg);
            rv = err;
            goto end;
        }
    }

end:
    if (rv) {
        closeDb();
    }
    return rv;
}
コード例 #10
0
ファイル: command.c プロジェクト: ThetaGroup/forask
int areaSwitch(char *area){
	openDb();
	char **dbResult;
	int nRow,nColumn;
	char *errMsg;
	char *selectSql=(char*)malloc(1024);
	sprintf(selectSql,QUERY_CERTAIN_AREA_SQL,area);
	int ret=sqlite3_get_table(
			conn,
			selectSql,
			&dbResult,
			&nRow,
			&nColumn,
			&errMsg
		);
	if (ret!=SQLITE_OK){
		LOG("%s\n",errMsg);
	}else{
		if (nRow<1){
			printf("No such area.\n");
		}else{
			char *updateSql=(char*)malloc(1024);
			sprintf(updateSql,UPDATE_SWITHCED_AREA_SQL,dbResult[1]);
			ret=sqlite3_exec(
					conn,
					updateSql,
					NULL,
					NULL,
					&errMsg
				);
			if (ret!=SQLITE_OK){
				LOG("%s\n",errMsg);
			}else{
				printf("Current arear swithced to %s.\n",area);
			}
			free(updateSql);
		}
	}
	free(selectSql);
	closeDb();
	return 0;
}
コード例 #11
0
ファイル: command.c プロジェクト: ThetaGroup/forask
int taskShowId(long taskId){
	openDb();
	char *errMsg;
	char **dbResult;
	int nRow,nColumn;
	
	char *selectSql=(char*)malloc(1024);
	sprintf(selectSql,QUERY_TASK_BY_ID_SQL,taskId);

	int ret=sqlite3_get_table(
			conn,
			selectSql,
			&dbResult,
			&nRow,
			&nColumn,
			&errMsg
		);
	if (ret==SQLITE_OK){
		if (nRow<1){
			printf("No such task with the given id!");
		}else{
			printf("Id:%ld\n",taskId);
			printf("Title:%s\n",dbResult[nColumn]);
			printf("Content:%s\n",dbResult[nColumn+1]);
			char *stateCode=dbResult[nColumn+2];
			char *stateString=NULL;
			if (strcmp(stateCode,TASK_STATE_ACTIVE)==0){
				stateString=TASK_STATE_ACTIVE_STRING;
			}else if (strcmp(stateCode,TASK_STATE_DONE)){
				stateString=TASK_STATE_DONE_STRING;
			}else
				LOG("Unrecognized task state code:%s\n",stateCode);
			if (stateString!=NULL)
				printf("State:%s\n",stateString);
		}
	}else{
		printf("Query task failed...\n");
	}

	closeDb();
	return 0;
}
コード例 #12
0
ファイル: command.c プロジェクト: ThetaGroup/forask
int areaAdd(char *area){
	openDb();
	char *errMsg;
	char *insertSql=(char*)malloc(1024);
	sprintf(insertSql,INSERT_AREA_SQL,area);	
	int	ret=sqlite3_exec(
			conn,
			insertSql,
			NULL,
			NULL,
			&errMsg
		);
	if (ret!=SQLITE_OK){
		LOG("%s\n",errMsg);
	}else{
		printf("Area %s added.\n",area);
	}
	free(insertSql);
	closeDb();
	return 0;
}
コード例 #13
0
ファイル: command.c プロジェクト: ThetaGroup/forask
int taskDone(long taskId){
	openDb();
	char *errMsg;
	char *updateSql=(char*)malloc(1024);
	sprintf(updateSql,UPDATE_TASK_STATE_SQL,TASK_STATE_DONE,taskId);
	int ret=sqlite3_exec(
			conn,
			updateSql,
			NULL,
			NULL,
			&errMsg
		);
	if (ret!=SQLITE_OK){
		LOG("%s\n",errMsg);
	}else{
		printf("Task %ld has been done.\n",taskId);
	}
	closeDb();
	free(updateSql);
	return 0;
}
コード例 #14
0
ファイル: process.c プロジェクト: JackWangCUMT/bitmeteros
void shutdownCapture(){
 // Called when the application shuts down
 	writeUnwrittenDiffs();
		
	closeDb();
}
コード例 #15
0
ファイル: backup.c プロジェクト: chmoder/tdcross_vulcan
int main(void)
{
    char               *db_name = "srecDB.fql";
    struct DB          *db;
    char               print_buf[BUFSIZ];
    /*struct Node        db[4];*/
    int                quitter = 1;
    int                recieved = 0;
    char               buf[ BUFSIZ ];
    int                sd, sd_current/*, cc, fromlen, tolen*/;
    socklen_t          addrlen;
    struct sockaddr_in sin;
    struct sockaddr_in pin;
 

    /* Get an internet domain socket */
    if ( ( sd = socket( AF_INET, SOCK_STREAM, 0) ) == -1 )
    {
        perror( "socket");
        exit( 1 );
    }

    /* Complete the socket structure */
    memset( &sin, 0, sizeof(sin) );
    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = INADDR_ANY;
    sin.sin_port = htons( PORT );

    /* Bind the socket to the port number */
    if ( bind( sd, ( struct sockaddr *) &sin, sizeof( sin ) ) == -1) 
    {
        perror( "bind" );
        exit( 1 );
    }

    /* Listen for clients that want to connect.         */
    /* In a real "server" we would get a connection and */
    /* then "fork" or create a thread for that one, but */
    /* here we only handle one connection.              */
    if ( listen( sd, 5 ) == -1 ) 
    {
        perror( "listen" );
        exit( 1 );
    }

    /* Wait for a client connection, then accept it. */
    addrlen = sizeof(pin); 
    if ( ( sd_current = accept( sd, ( struct sockaddr *)&pin, &addrlen ) ) == -1 )
    {
        perror( "accept");
        exit( 1 );
    }

    /* Let's show the incoming stuff just for fun. */
    /*printf( "Coming from port %d\n", ntohs( pin.sin_port ) );*/

    /* If this is a server that needs to keep taking messages */
    /* from the client, then put a "while" loop here to keep  */
    /* reading data. The easy way to do this is to have the   */
    /* client send "exit" or some special string to terminate */
    /* the "while" loop. Otherwise you tend to get SIGPIPE or */
    /* other errors from the "recv" and "send" calls.         */

    /* Open database file*/
    db = openDb(db_name);

    /* get a message from the client */
    while((recieved = recv(sd_current, buf, sizeof(buf), 0)) > 0 && quitter)
    {
        char delims[] = " ";
        char *request = NULL;
        char *data = NULL; 

        request = strtok(buf, delims);
        data = strtok(NULL, delims);

        if(!strcmp(request, "stop"))
        {
            closeDb(db, db_name);
            quitter = 0;
        }
        else if(!strcmp(request, "get"))
        {
            getRecord(db, data, print_buf, sd_current);
        }
        else if(!strcmp(request, "put"))
        {
            putRecord(db, data);
        }
        else if(!strcmp(request, "delete"))
        {
            deleteRecord(db, data);
        }
    }

    /* close up both sockets */
    close( sd_current ); 
    close( sd );

    return( 0 );
}
コード例 #16
0
static authn_status authn_check_otp(request_rec *r, const char *user,
                                    const char *password)
{
    apr_status_t rv;
    apr_dbm_t *userDbm = NULL;
    yubiauth_dir_cfg *cfg = ap_get_module_config(r->per_dir_config, &authn_yubikey_module);

    apr_datum_t key,dbUserRecord;
    key.dptr = NULL;
    dbUserRecord.dptr = NULL;

    char *lookedUpToken = NULL;
    char *lookedUpPassword = NULL; //This is the OTP token
    char *dbUserKey = (char *) malloc(sizeof(user));
    apr_size_t passwordLength = 0;
    apr_time_t lookedUpDate = 0;



    /* No username and no password is set */
    if (!*user || !*password)
        return AUTH_DENIED;

    /* Since the password field contains possibly a password and the OTP token, we 
     * have to break that up here
     */
    passwordLength = (apr_size_t) strlen(password) - YUBIKEY_TOKEN_LENGTH;

    ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r,
                  LOG_PREFIX "Username is: %s and password is: %s", user, &password[passwordLength]);

    /* Now open the User DB and see if the user really is one of us.
     * for that we save the 12char token:username combo.
     * Ideally we can fill that with the htpasswd utility
     * NOTE: enter full password here
     */
    if (!isUserValid(user, password, cfg, r)) {
      return AUTH_DENIED;
    }

    openDb(&userDbm, cfg->tmpAuthDbFilename, r);

    dbUserKey = strcpy(dbUserKey, user);
    dbUserKey = getDbKey(dbUserKey, cfg, r);
    key = string2datum(dbUserKey, r);
    ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r, LOG_PREFIX "Fetching token (pw:time) for user %s from db ...", user);
    rv = apr_dbm_fetch(userDbm, key, &dbUserRecord);
    if (rv != APR_SUCCESS) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, LOG_PREFIX "unable to fetch the user (%s) from the"
                      "Database, better abort here.", user);
        closeDb(userDbm, r);
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    if (dbUserRecord.dptr != NULL) {

        /* it's separated pw:time here */
        const char *sep = ":";
        char *time;

        lookedUpToken = apr_pstrmemdup(r->pool, dbUserRecord.dptr, dbUserRecord.dsize);
        /* Break down the token into it's pw:time components */
        lookedUpPassword = apr_strtok(lookedUpToken, sep, &time);
        lookedUpDate = (apr_time_t) apr_atoi64(time);


        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r,
                      LOG_PREFIX "We could extrace these values from the token:");
        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r,
                      LOG_PREFIX "The looked up token for the user: %s",
                      user);
        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r,
                      LOG_PREFIX "The looked up password: %s",
                      lookedUpPassword);
        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r,
                      LOG_PREFIX "The looked up time: %" APR_TIME_T_FMT,
                      lookedUpDate);
        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r,
                      LOG_PREFIX "The looked up token: %s",
                      lookedUpToken);
    }
    ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r, LOG_PREFIX "Fetched token (%s) ...", lookedUpToken);

    /* password has to be set, if the pw content is NULL or empty, we have 
     * catched that earlier ...
     */
    if (lookedUpPassword != NULL && !strcmp(lookedUpPassword, &password[passwordLength])) {
        /* The date expired */
        if (passwordExpired(user, lookedUpDate, cfg->timeoutSeconds, r)) {
            /* Delete user record */
            ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r,
			LOG_PREFIX "Remove expired entry for user : %s",
			user);
            deleteKeyFromDb(userDbm, user, cfg, r);
            closeDb(userDbm, r);
            return AUTH_DENIED;
        }
        else {
            closeDb(userDbm, r);
            return AUTH_GRANTED;
        }
    }
    else {
        int authenticationSuccessful = 0;
        int ret = YUBIKEY_CLIENT_BAD_OTP;
        /* We could not lookup the password, verify the sent password */
        ret = yubikey_client_simple_request(&password[passwordLength], 1, 0, NULL, r);
            if (ret == YUBIKEY_CLIENT_OK) {
                authenticationSuccessful = 1;
            } else {
                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                              LOG_PREFIX "Authentication failed, reason: %s",
                              yubikey_client_strerror(ret));
                return AUTH_DENIED;
            }

        /* We could successfully authenticate the user */
        if (authenticationSuccessful) {
            /* Try to write the user into the db */
            if (setUserInDb(userDbm, user, &password[passwordLength], cfg, r)
		!= APR_SUCCESS) {
                /* Abort, we could not write the user into the db after
                 * authenticating him ...
                 */
                closeDb(userDbm, r);
                return HTTP_INTERNAL_SERVER_ERROR;
            }

            /* User could be written to the db*/
            closeDb(userDbm, r);
            return AUTH_GRANTED;
        }

        /* Could not authenticate successful */
        closeDb(userDbm, r);
        return AUTH_DENIED;
    }

    /* Something went wrong or we did not think about it, better deny */
    closeDb(userDbm, r);
    return AUTH_DENIED;
}
コード例 #17
0
ファイル: cheapdb.cpp プロジェクト: tungpt00179/myrepo
CheapDB::~CheapDB()
{
    closeDb();
}