// -*-c++-*-
/* $Id: sfsserv.h,v 1.8 2001/04/15 23:22:54 dm Exp $ */

/*
 *
 * Copyright (C) 2000 David Mazieres (dm@uun.org)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 *
 */

#include "sfsmisc.h"
#include "arpc.h"
#include "crypt.h"
#include "seqno.h"

class sfsserv {
  struct condat {
    sfs_connectinfo ci;
    sfs_connectres cr;
  };

  ptr<rabin_priv> sk;
public:
  const ref<axprt_crypt> xc;
  const ref<axprt> x;
  const ref<bool> destroyed;
private:
  vec<size_t> authfreelist;
  rpc_ptr<condat> cd;
  sfs_hashcharge charge;

protected:
  ref<asrv> sfssrv;
  void dispatch (svccb *sbp);
  virtual ptr<rabin_priv> doconnect (const sfs_connectarg *,
				     sfs_servinfo *) = 0;

public:
  seqcheck seqstate;
  bool authid_valid;
  sfs_hash sessid;
  sfs_hash authid;
  vec<auto_auth> authtab;
  vec<sfsauth_cred> credtab;

  explicit sfsserv (ref<axprt_crypt> xc, ptr<axprt> x = NULL);
  virtual ~sfsserv ();
  u_int32_t authalloc ();
  void authfree (size_t n);
  AUTH *getauth (size_t n) {
    return n < authtab.size () ? implicit_cast<AUTH *> (authtab[n])
      : (AUTH *) NULL;
  }

  virtual void sfs_connect (svccb *sbp);
  virtual void sfs_encrypt (svccb *sbp);
  virtual void sfs_getfsinfo (svccb *sbp) { sbp->reject (PROC_UNAVAIL); }
  virtual void sfs_login (svccb *sbp);
  virtual void sfs_logout (svccb *sbp);
  virtual void sfs_idnames (svccb *sbp);
  virtual void sfs_idnums (svccb *sbp);
  virtual void sfs_getcred (svccb *sbp);
  virtual void sfs_badproc (svccb *sbp) { sbp->reject (PROC_UNAVAIL); }
};

typedef callback<void, ptr<axprt_crypt> >::ref sfsserv_cb;
void sfssd_slave (sfsserv_cb cb);
ptr<aclnt> getauthclnt ();

