/*
 * delete.c
 *
$Author: dm3e $
$Date: 1992/12/01 23:44:07 $
$Revision: 1.1 $
$State: Exp $
$Locker:  $

/***********************************************************
        Copyright 1991 by Carnegie Mellon University

                      All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/

#include <stdio.h>
#include <strings.h>
#include <sys/time.h>
#include <afs/cmd.h>
#include "rxemt.h"
#include "globals.h"
#include "alloc.h"
#include "tools.h"
#include "hash.h"
#include "util.h"
#include "shell.h"
#include "emt_err.h"

#define INITIAL_VERSION 11

#define PARM_TREE (as->parms[EMT_STD_PARM].items->data)
#define PARM_COLLECTION (as->parms[EMT_STD_PARM+1].items->data)
#define PARM_VERSION (as->parms[EMT_STD_PARM+2].items->data)
#define PARM_SYSTEMS (as->parms[EMT_STD_PARM+3].items)
#define PARM_SOURCE (as->parms[EMT_STD_PARM+4].items)
#define PARM_DESTS (as->parms[EMT_STD_PARM+5].items)
#define PARM_OBJECTS (as->parms[EMT_STD_PARM+6].items)
#define PARM_ALL (as->parms[EMT_STD_PARM+7].items)
#define PARM_VERBOSE (as->parms[EMT_STD_PARM+8].items)
#define PARM_FORCE (as->parms[EMT_STD_PARM+9].items)

extern struct rx_connection *conn;

/***************************************************************************
 * [exported] emt_DeleteCommand
 *
 * Description:
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Thu Oct 15 10:25:18 1992 - created by David Allen Markley
 *
 ***************************************************************************/
long emt_DeleteCommand(as)
struct cmd_syndesc *as;
{
    register long code;
    register struct cmd_item *ti;
    char *errstr;
    struct rx_call *call;
    req_in_t request = (req_in_t)new_req_in();
    llist_t c_list;

    request->type = EMTD_DELETE;
    request->tree = copy_string(PARM_TREE);
    request->collection = copy_string(PARM_COLLECTION);
    request->environment = copy_string("");
    request->current_version = copy_string(PARM_VERSION);
    request->old_version = copy_string("");
    request->path = copy_string("");
    c_list = NULL;
    for(ti=PARM_SYSTEMS; ti; ti=ti->next) {
	new_llist(&c_list, ti->data, NULL, NULL);
	if (NULL == request->systems) request->systems = c_list;
    }
    if (PARM_ALL || PARM_SOURCE) request->flags |= DELETE_SOURCE;
    if (PARM_ALL || PARM_DESTS) request->flags |= DELETE_DESTS;
    if (PARM_ALL || PARM_OBJECTS) request->flags |= DELETE_OBJECTS;
    if (PARM_FORCE) request->flags |= FORCE_REQUEST;

    errstr = NULL;
    call = rx_NewCall(conn);
    code = StartEMT_QueueCommand(call, request);
    ReadWaiting(call, PARM_VERBOSE);
    code = EndEMT_QueueCommand(call, &errstr);
    code = rx_EndCall(call, code);
    if (code) return code;
    return 0;
}

#undef PARM_TREE
#undef PARM_COLLECTION
#undef PARM_VERSION
#undef PARM_SYSTEMS
#undef PARM_SOURCE
#undef PARM_DESTS
#undef PARM_OBJECTS
#undef PARM_VERBOSE
