/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
 *
 * n4: A fast userspace NFSv4 server.
 * $Id: rpc.h,v 1.1 2001/05/30 05:37:19 mbp Exp $
 * 
 * Copyright (C) 2001 by Martin Pool <mbp@samba.org>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

enum rpc_msg_type {
    RPC_CALL = 0,
    RPC_REPLY = 1
};


enum {
    RPC_VERSION2 = 2
};

enum rpc_auth_flavor {
    RPC_AUTH_NONE       = 0,
    RPC_AUTH_SYS        = 1,
    RPC_AUTH_SHORT      = 2
    /* and more to be defined */
};



enum rpc_reply_stat {
    RPC_MSG_ACCEPTED = 0,
    RPC_MSG_DENIED   = 1
};

enum rpc_accept_stat {
    RPC_SUCCESS       = 0, /* RPC executed successfully             */
    RPC_PROG_UNAVAIL  = 1, /* remote hasn't exported program        */
    RPC_PROG_MISMATCH = 2, /* remote can't support version #        */
    RPC_PROC_UNAVAIL  = 3, /* program can't support procedure       */
    RPC_GARBAGE_ARGS  = 4, /* procedure can't decode params         */
    RPC_SYSTEM_ERR    = 5  /* errors like memory allocation failure */
};

enum rpc_reject_stat {
    RPC_MISMATCH = 0, /* RPC version number != 2          */
    RPC_AUTH_ERROR = 1    /* remote can't authenticate caller */
};


enum rpc_auth_stat {
    AUTH_OK           = 0,  /* success                          */

    /*
     * failed at remote end
     */
    AUTH_BADCRED      = 1,  /* bad credential (seal broken)     */
    AUTH_REJECTEDCRED = 2,  /* client must begin new session    */
    AUTH_BADVERF      = 3,  /* bad verifier (seal broken)       */
    AUTH_REJECTEDVERF = 4,  /* verifier expired or replayed     */
    AUTH_TOOWEAK      = 5,  /* rejected for security reasons    */
    /*
     * failed locally
     */
    AUTH_INVALIDRESP  = 6,  /* bogus response verifier          */
    AUTH_FAILED       = 7   /* reason unknown                   */
};


typedef struct rpc_opaque {
    size_t len;
    void *data;
} rpc_opaque;


struct rpc_opaque_auth {
    enum rpc_auth_flavor flavor;
    rpc_opaque body;
};


#if 0
/* We don't unpack into a structure anymore.  These are just here for
 * reference.
 */

/* Perhaps we ought to read in just the header separately so that we
 * can better handle the case of corrupted headers, etc.  We need to
 * be able to tell where the error happened in the message, because
 * the error we should return depends on where the error occurred. */
struct rpc_msg {
    unsigned int xid;
    enum rpc_msg_type mtype;
    union {
        struct rpc_call_body {  /* RPC_CALL */
            unsigned int rpcvers;
            unsigned int prog;
            unsigned int vers;
            unsigned int proc;
            struct rpc_opaque_auth  cred;
            struct rpc_opaque_auth  verf;
            /* Procedure specific parameters start here.  How do we
             * get them out?  Should the parameters for different
             * NFS functions be coded in here directly? */
        } cbody;
        struct rpc_reply_body {  /* RPC_REPLY */
            enum rpc_reply_stat stat;
            union {
                struct rpc_accepted_reply {
                    struct rpc_opaque_auth verf;
                    enum rpc_accept_stat stat;
                } areply;
                struct rpc_rejected_reply {
                } rreply;
            } reply;
        } rbody;
    } body;
};
#endif
