/* oper_result.c - deal with result of an operation */

#ifndef	lint
static char *rcsid = "$Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/quipu/oper_result.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $";
#endif

/* 
 * $Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/quipu/oper_result.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $
 *
 *
 * $Log: oper_result.c,v $
 * Revision 1.1.1.1  2018/04/24 16:12:56  root
 * BSD 4.3reno
 *
 * Revision 7.2  90/07/09  14:46:25  mrose
 * sync
 * 
 * Revision 7.1  90/04/18  08:49:57  mrose
 * 6.2
 * 
 * Revision 7.0  89/11/23  22:17:54  mrose
 * Release 6.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


/* LINTLIBRARY */

#include "quipu/dsap.h"
#include "quipu/util.h"
#include "quipu/connection.h"

extern	LLog	* log_dsap;
extern	int	  dn_print();

oper_result(cn, di)
struct connection	* cn;
struct DSAPindication	* di;
{
    struct DSAPresult	* dr = &(di->di_result);
    struct oper_act *   on;

    DLOG(log_dsap, LLOG_TRACE, ("oper_result()"));

    for(on=cn->cn_operlist; on != NULLOPER; on=on->on_next_conn)
    {
	if(on->on_id == dr->dr_id)
	    break;
    }

    if(on == NULLOPER)
    {
	LLOG(log_dsap, LLOG_FATAL, ("Cannot find operation to match result"));
	send_ro_ureject(cn->cn_ad, &(dr->dr_id), ROS_RRP_UNRECOG);
	return;
    }

    if (dr->dr_res.dcr_dsres.result_type != on->on_arg->dca_dsarg.arg_type)
    {
	LLOG(log_dsap, LLOG_NOTICE, ("oper_result - operation had been abandoned"));
	send_ro_ureject(on->on_conn->cn_ad, &(dr->dr_id), ROS_RRP_MISTYPED);
	oper_extract(on);
	return;
    }

    if(on->on_state == ON_ABANDONED)
    {
	LLOG(log_dsap, LLOG_NOTICE, ("oper_result - operation had been abandoned"));
	oper_extract(on);
	return;
    }

    on->on_resp = (*di);	/* struct copy */

    switch(on->on_type)
    {
    case ON_TYPE_X500:
	task_result_wakeup (on);
	break;
    case ON_TYPE_SUBTASK:
	subtask_result_wakeup (on);
	break;
    case ON_TYPE_BIND_COMPARE:
	bind_compare_result_wakeup(on);
	break;
    case ON_TYPE_GET_DSA_INFO:
	dsa_info_result_wakeup(on);
	break;
    case ON_TYPE_GET_EDB:
	on->on_state = ON_COMPLETE;
	break;
    default:
	LLOG(log_dsap, LLOG_EXCEPTIONS, ("oper_result: operation of unknown type"));
	oper_extract(on);
	break;
    }
}

