/*
 * svnauthz-validate.c : load and validate an authz file, returns 
 *       value == 0 when authz file is correct.
 *

 *  To compile on unix against Subversion and APR libraries, try
 *  something like:
 *
 *  cc svnauthz-validate.c -o svnauthz-validate \
 *  -I/usr/local/include/subversion-1 -I/usr/local/apache2/include \
 *  -L/usr/local/apache2/lib -L/usr/local/lib \
 *  -lsvn_client-1 -lapr-0 -laprutil-0
 *
 */

#include "svn_pools.h"
#include "svn_repos.h"
#include "svn_cmdline.h"

int
main (int argc, const char **argv)
{
  apr_pool_t *pool;
  svn_error_t *err;
  svn_authz_t *authz;
  const char *authz_file;

  if (argc <= 1)
    {
      printf ("Usage:  %s PATH \n", argv[0]);  
      printf ("    Loads the authz file at PATH and validates its content. Returns 0 when content is ok.\n");
      return EXIT_FAILURE;
    }
  authz_file = argv[1];

  /* Initialize the app.  Send all error messages to 'stderr'.  */
  if (svn_cmdline_init ("minimal_client", stderr) != EXIT_SUCCESS)
    return EXIT_FAILURE;

  /* Create top-level memory pool. Be sure to read the HACKING file to
     understand how to properly use/free subpools. */
  pool = svn_pool_create (NULL);

  /* read the access file and validate */
  err = svn_repos_authz_read (&authz, authz_file, TRUE, pool);

  /* shouldn't I clean the pool object here? */
  if (err) goto hit_error;

  return EXIT_SUCCESS;

 hit_error:
  svn_handle_error2 (err, stderr, FALSE, "svnauthz-validate: ");
  return EXIT_FAILURE;
}


