/**********************************************************************
 * ti library's routine for deauthentication
 *
 * $Author: brlewis $
 * $Source: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/deauth.c,v $
 * $Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/deauth.c,v 0.2 92/04/01 16:17:41 brlewis Exp $
 *
 * Copyright 1991 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 **********************************************************************/

#include <mit-copyright.h>

#ifndef lint
static char rcsid_ti_deauth_c[] = "$Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/deauth.c,v 0.2 92/04/01 16:17:41 brlewis Exp $";
#endif /* lint */

#include <stdio.h>
#include <string.h>
#include <ti/ti.h>

/**********************************************************************
 * ti_deauth(TI_H hti)
 *
 * - ends provider session
 * - returns error code
 **********************************************************************/

/* jms 7/9/92 -- windows-izing begun */

long
ti_deauth(hti)
     TI_H hti;
{
  long code;
  static char torecv[BUFSIZ];

  TI_LP lpti;

  lpti = (TI_LP)TI_DEREFERENCE(hti);

  /* send command and receive reply */
  if (code = _ti_talk(hti, "c:\n", 3, torecv, BUFSIZ-1))
    CLEANUP_AND_RETURN(code)

  /* success? */
  if (torecv[0] == '0' && torecv[1] == ':')
    {
      /* free memory */ /* !!! */
      if (ti_user(lpti))
	{
	  free((char *) ti_user(lpti));
	  ti_user(lpti) = NULL;
	}
      if (ti_password(lpti))
	{
	  free((char *) ti_password(lpti));
	  ti_password(lpti) = NULL;
	}
      if (ti_source1(lpti))
	{
	  free((char *) ti_source1(lpti));
	  ti_source1(lpti) = NULL;
	}
      CLEANUP_AND_RETURN(0L)
    }

  /* failure */
  strcpy(ti_context, "deauthenticating");
  CLEANUP_AND_RETURN(_ti_srverr(torecv))

CLEANUP:
  TI_REMOVE_DEREFERENCE(hti);
  return(code);
}
