source: src/router/proftpd/src/feat.c @ 17876

Last change on this file since 17876 was 17876, checked in by BrainSlayer, 20 months ago

update proftp

File size: 2.3 KB
Line 
1/*
2 * ProFTPD - FTP server daemon
3 * Copyright (c) 2001-2008 The ProFTPD Project team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, The ProFTPD Project team and other respective
20 * copyright holders give permission to link this program with OpenSSL, and
21 * distribute the resulting executable, without including the source code for
22 * OpenSSL in the source distribution.
23 */
24
25/* Feature management code
26 * $Id: feat.c,v 1.9 2011/05/23 21:22:24 castaglia Exp $
27 */
28
29#include "conf.h"
30
31static pool *feat_pool = NULL;
32static pr_table_t *feat_tab = NULL;
33
34int pr_feat_add(const char *feat) {
35  if (!feat) {
36    errno = EINVAL;
37    return -1;
38  }
39
40  /* If no feature-tracking list has been allocated, create one. */
41  if (!feat_pool) {
42    feat_pool = make_sub_pool(permanent_pool);
43    pr_pool_tag(feat_pool, "Feat API");
44    feat_tab = pr_table_alloc(feat_pool, 0);
45  }
46
47  /* Make sure that the feature being added isn't already in the list. */
48  if (pr_table_exists(feat_tab, feat) > 0) {
49    errno = EEXIST;
50    return -1;
51  }
52
53  return pr_table_add(feat_tab, pstrdup(feat_pool, feat), "", 0);
54}
55
56int pr_feat_remove(const char *feat) {
57  void *res;
58
59  if (!feat_tab) {
60    errno = EPERM;
61    return -1;
62  }
63
64  if (!feat) {
65    errno = EINVAL;
66    return -1;
67  }
68
69  res = pr_table_remove(feat_tab, feat, NULL);
70
71  if (res)
72    return 0;
73
74  errno = ENOENT;
75  return -1;
76}
77
78const char *pr_feat_get(void) {
79  if (!feat_tab) {
80    errno = EPERM;
81    return NULL;
82  }
83
84  (void) pr_table_rewind(feat_tab);
85  return pr_table_next(feat_tab);
86}
87
88const char *pr_feat_get_next(void) {
89  if (!feat_tab) {
90    errno = EPERM;
91    return NULL;
92  }
93
94  return pr_table_next(feat_tab);
95}
Note: See TracBrowser for help on using the repository browser.