view src/control.c @ 54:125d79c9e586 noffle

[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c, src/database.c, src/dynamicstring.c, src/fetch.c, src/fetchlist.c, src/group.c, src/itemlist.c, src/lock.c, src/log.c, src/noffle.c, src/online.c, src/outgoing.c, src/over.c, src/post.c, src/protocol.c, src/pseudo.c, src/request.c, src/server.c, src/util.c: Added portable.h #include. * src/client.h, src/database.h, src/fetch.c, src/group.h, src/lock.c, src/outgoing.c, src/over.c, src/over.h, src/pseudo.c, src/server.c, src/util.c, src/util.h: Added some #ifdefs to correctly include either time.h or sys/time.h or both, depending on which are found. * src/noffle.c: Changed the return-type of the signal-handlers bugReport() and logSignal() to RETSIGTYPE, which is either void or int, depending on the system you compile on (autoconf #defines the RETSIGTYPE).
author uh1763
date Tue, 09 May 2000 23:28:38 +0100
parents 32ba1198c6fa
children fed1334d766b
line wrap: on
line source

/*
  control.c

  $Id: control.c 60 2000-05-09 22:28:38Z uh1763 $
*/

#if HAVE_CONFIG_H
#include <config.h>
#endif

#include "control.h"
#include <stdio.h>
#include "common.h"
#include "content.h"
#include "database.h"
#include "group.h"
#include "itemlist.h"
#include "log.h"
#include "outgoing.h"
#include "portable.h"

int
Ctrl_cancel( const char *msgId )
{
    ItemList *refs;
    const char *ref;
    Str server;
    Bool seen = FALSE;
    int res = CANCEL_OK;

    /* See if in outgoing and zap if so. */
    if ( Out_find( msgId, server ) )
    {
	Out_remove( server, msgId );
	Log_inf( "'%s' cancelled from outgoing queue for '%s'.\n",
		 msgId, server );
	seen = TRUE;
    }

    if ( ! Db_contains( msgId ) )
    {
	Log_inf( "Cancel: '%s' not in database.", msgId );
	return seen ? CANCEL_OK : CANCEL_NO_SUCH_MSG;
    }

    /*
      Retrieve the Xrefs, remove from each group and then
      remove from the database.
     */
    refs = new_Itl( Db_xref( msgId ), " " );
    for( ref = Itl_first( refs ); ref != NULL; ref = Itl_next( refs ) )
    {
	Str grp;
	int no;

	if ( sscanf( ref, "%s:%d", grp, &no ) != 2 )
	    break;
	
	if ( Grp_exists( grp ) )
	{
	    Cont_read( grp );
	    Cont_delete( no );
	    Cont_write();

	    if ( ! Grp_local( grp ) && ! seen )
		res = CANCEL_NEEDS_MSG;

	    Log_dbg( "Removed '%s' from group '%s'.", msgId, grp );
	}
	else
	{
	    Log_inf( "Group '%s' in Xref for '%s' not found.", grp, msgId );
	}
    }
    del_Itl( refs );
    Db_delete( msgId );
    Log_inf( "Message '%s' cancelled.", msgId );
    return res;
}