/
remove_file.c
81 lines (66 loc) · 1.85 KB
/
remove_file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Copyright (C) 2000-1 drscholl@users.sourceforge.net
This is free software distributed under the terms of the
GNU Public License. See the file COPYING for details.
$Id: remove_file.c,v 1.36 2001/09/22 05:52:06 drscholl Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include "opennap.h"
#include "debug.h"
#ifndef ROUTING_ONLY
/* 102 <filename> */
HANDLER (remove_file)
{
USER *user;
DATUM *info;
unsigned int fsize;
(void) tag;
(void) len;
ASSERT (validate_connection (con));
CHECK_USER_CLASS ("remove_file");
user = con->user;
if (!user->shared)
{
send_cmd (con, MSG_SERVER_NOSUCH, "Not sharing any files");
return;
}
ASSERT (pkt != 0);
if (!*pkt)
{
send_cmd (con, MSG_SERVER_NOSUCH, "remove file failed: missing argument");
return;
}
/* find the file in the user's list */
info = hash_lookup (con->uopt->files, pkt);
if (!info)
{
send_cmd (con, MSG_SERVER_NOSUCH, "Not sharing that file");
return;
}
/* adjust the global state information */
fsize = info->size / 1024; /* kB */
if (fsize > user->libsize)
{
log_message ("remove_file: bad lib size for %s, fsize=%u user->libsize=%u",
user->nick, fsize, user->libsize);
user->libsize = fsize; /* prevent negative count */
}
user->libsize -= fsize;
if (fsize > Num_Gigs)
{
log_message ("remove_file: bad lib size for %s, fsize=%u Num_Gigs=%f",
user->nick, fsize, Num_Gigs);
Num_Gigs = fsize; /* prevent negative count */
}
Num_Gigs -= fsize;
ASSERT (Num_Files > 0);
Num_Files--;
ASSERT (Local_Files > 0);
Local_Files--;
user->shared--;
user->unsharing = 1; /* note that we are unsharing */
/* this invokes free_datum() indirectly */
hash_remove (con->uopt->files, info->filename);
}
#endif /* ! ROUTING_ONLY */