authme-unix/src/cnffile.c
authme_err_t
authme_load_cnf(authme_service_config_t * psc, FILE * input_file, int flags)
{
    /* Line by line scan */
    
    char buf[1024];
    char * command, * arg;
    while (authme_cnf_parse_line(input_file, &command, &arg, buf, 1024) == 0)
    {
        if (strcasecmp(command, "ServiceUserId") == 0)
        {
			if (!(flags & AUTHME_CNF_IGNORE_USER_ID))
			{
				if (psc->psc_user_id != NULL)
					free(psc->psc_user_id);
				psc->psc_user_id = strdup(arg);
			}
        }
        else if (strcasecmp(command, "ServiceURL") == 0)
        {
			if (!(flags & AUTHME_CNF_IGNORE_SERVICE_URL))
			{
				if (psc->psc_url != NULL)
					free(psc->psc_url);
				psc->psc_url = strdup(arg);
			}
        }
		else if (strcasecmp(command, "KeyFileName") == 0)
		{
			if (!(flags & AUTHME_CNF_IGNORE_KEY_FILENAME))
			{
				if (psc->psc_key_file != NULL)
					free(psc->psc_key_file);
				psc->psc_key_file = strdup(arg);
			}
		}
		else if (strcasecmp(command, "KeyFilePass") == 0)
		{
			if (!(flags & AUTHME_CNF_IGNORE_KEY_FILENAME))
			{
				if (psc->psc_key_file_pass.password_data != NULL)
				{
					free(psc->psc_key_file_pass.password_data);
					psc->psc_key_file_pass.password_data = NULL;
				}

				/* Now have to split it apart */
				if (strlen(arg) < 3 || arg[1] != '!')
					return AUTHME_ERR_UNKNOWN_CNF_OPTION;

				psc->psc_key_file_pass.password_format = arg[0] - '0';
				psc->psc_key_file_pass.password_data = strdup(&arg[2]);
			}
		}
		else
        {
            bfr_t * e = new_bfr();
            append_bfr(e, "Unknown command option: ");
            append_bfr(e, command);
            psc->psc_last_error = strdup(e->b);
            free_bfr(e);
            return AUTHME_ERR_UNKNOWN_CNF_OPTION;
        }
    }
    
    return AUTHME_ERR_OK;
}
/* Given a configuration file - load data into the provided service 
 * config. 
 *
 * The input_file is previously opened to allow the caller to pass
 * arbitrary config files
 *
 * the flags variable tells us what *not* to load from the file
*/
Given a configuration file - load data into the provided service
config.

The input_file is previously opened to allow the caller to pass
arbitrary config files

the flags variable tells us what *not* to load from the file
Given a configuration file - load data into the provided service config . The input_file is previously opened to allow the caller to pass arbitrary config files the flags variable tells us what * not * to load from the file
authme_err_t
authme_load_cnf(authme_service_config_t * psc, FILE * input_file, int flags)
{
    char buf[1024];
    char * command, * arg;
    while (authme_cnf_parse_line(input_file, &command, &arg, buf, 1024) == 0)
    {
        if (strcasecmp(command, "ServiceUserId") == 0)
        {
			if (!(flags & AUTHME_CNF_IGNORE_USER_ID))
			{
				if (psc->psc_user_id != NULL)
					free(psc->psc_user_id);
				psc->psc_user_id = strdup(arg);
			}
        }
        else if (strcasecmp(command, "ServiceURL") == 0)
        {
			if (!(flags & AUTHME_CNF_IGNORE_SERVICE_URL))
			{
				if (psc->psc_url != NULL)
					free(psc->psc_url);
				psc->psc_url = strdup(arg);
			}
        }
		else if (strcasecmp(command, "KeyFileName") == 0)
		{
			if (!(flags & AUTHME_CNF_IGNORE_KEY_FILENAME))
			{
				if (psc->psc_key_file != NULL)
					free(psc->psc_key_file);
				psc->psc_key_file = strdup(arg);
			}
		}
		else if (strcasecmp(command, "KeyFilePass") == 0)
		{
			if (!(flags & AUTHME_CNF_IGNORE_KEY_FILENAME))
			{
				if (psc->psc_key_file_pass.password_data != NULL)
				{
					free(psc->psc_key_file_pass.password_data);
					psc->psc_key_file_pass.password_data = NULL;
				}
				if (strlen(arg) < 3 || arg[1] != '!')
					return AUTHME_ERR_UNKNOWN_CNF_OPTION;
				psc->psc_key_file_pass.password_format = arg[0] - '0';
				psc->psc_key_file_pass.password_data = strdup(&arg[2]);
			}
		}
		else
        {
            bfr_t * e = new_bfr();
            append_bfr(e, "Unknown command option: ");
            append_bfr(e, command);
            psc->psc_last_error = strdup(e->b);
            free_bfr(e);
            return AUTHME_ERR_UNKNOWN_CNF_OPTION;
        }
    }
    return AUTHME_ERR_OK;
}
authme_err_t authme_load_cnf ( authme_service_config_t * psc , FILE * input_file , int flags ) { char buf [ 1024 ] ; char * command , * arg ; while ( authme_cnf_parse_line ( input_file , & command , & arg , buf , 1024 ) == 0 ) { if ( strcasecmp ( command , " " ) == 0 ) { if ( ! ( flags & AUTHME_CNF_IGNORE_USER_ID ) ) { if ( psc -> psc_user_id != NULL ) free ( psc -> psc_user_id ) ; psc -> psc_user_id = strdup ( arg ) ; } } else if ( strcasecmp ( command , " " ) == 0 ) { if ( ! ( flags & AUTHME_CNF_IGNORE_SERVICE_URL ) ) { if ( psc -> psc_url != NULL ) free ( psc -> psc_url ) ; psc -> psc_url = strdup ( arg ) ; } } else if ( strcasecmp ( command , " " ) == 0 ) { if ( ! ( flags & AUTHME_CNF_IGNORE_KEY_FILENAME ) ) { if ( psc -> psc_key_file != NULL ) free ( psc -> psc_key_file ) ; psc -> psc_key_file = strdup ( arg ) ; } } else if ( strcasecmp ( command , " " ) == 0 ) { if ( ! ( flags & AUTHME_CNF_IGNORE_KEY_FILENAME ) ) { if ( psc -> psc_key_file_pass . password_data != NULL ) { free ( psc -> psc_key_file_pass . password_data ) ; psc -> psc_key_file_pass . password_data = NULL ; } if ( strlen ( arg ) < 3 || arg [ 1 ] != ' ' ) return AUTHME_ERR_UNKNOWN_CNF_OPTION ; psc -> psc_key_file_pass . password_format = arg [ 0 ] - ' ' ; psc -> psc_key_file_pass . password_data = strdup ( & arg [ 2 ] ) ; } } else { bfr_t * e = new_bfr ( ) ; append_bfr ( e , " " ) ; append_bfr ( e , command ) ; psc -> psc_last_error = strdup ( e -> b ) ; free_bfr ( e ) ; return AUTHME_ERR_UNKNOWN_CNF_OPTION ; } } return AUTHME_ERR_OK ; }
Given a configuration file - load data into the provided service
 config.
Given a configuration file - load data into the provided service config .
/* Line by line scan */ /* Now have to split it apart */