comparison dcclib/get_id.c @ 0:c7f6b056b673

First import of vendor version
author Peter Gervai <grin@grin.hu>
date Tue, 10 Mar 2009 13:49:58 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c7f6b056b673
1 /* Distributed Checksum Clearinghouse
2 *
3 * convert an ID to binary
4 *
5 * Copyright (c) 2008 by Rhyolite Software, LLC
6 *
7 * This agreement is not applicable to any entity which sells anti-spam
8 * solutions to others or provides an anti-spam solution as part of a
9 * security solution sold to other entities, or to a private network
10 * which employs the DCC or uses data provided by operation of the DCC
11 * but does not provide corresponding data to other users.
12 *
13 * Permission to use, copy, modify, and distribute this software without
14 * changes for any purpose with or without fee is hereby granted, provided
15 * that the above copyright notice and this permission notice appear in all
16 * copies and any distributed versions or copies are either unchanged
17 * or not called anything similar to "DCC" or "Distributed Checksum
18 * Clearinghouse".
19 *
20 * Parties not eligible to receive a license under this agreement can
21 * obtain a commercial license to use DCC by contacting Rhyolite Software
22 * at sales@rhyolite.com.
23 *
24 * A commercial license would be for Distributed Checksum and Reputation
25 * Clearinghouse software. That software includes additional features. This
26 * free license for Distributed ChecksumClearinghouse Software does not in any
27 * way grant permision to use Distributed Checksum and Reputation Clearinghouse
28 * software
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
31 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
33 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
34 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
35 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
36 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
37 * SOFTWARE.
38 *
39 * Rhyolite Software DCC 1.3.103-1.18 $Revision$
40 */
41
42 #include "dcc_defs.h"
43 #include "dcc_xhdr.h"
44
45
46 /* get client or server-ID */
47 DCC_CLNT_ID /* ID or DCC_ID_INVALID */
48 dcc_get_id(DCC_EMSG emsg, const char *id_str,
49 const char *fnm, int lno)
50 {
51 char *p;
52 unsigned long id;
53 DCC_FNM_LNO_BUF fnm_buf;
54
55 id_str += strspn(id_str, DCC_WHITESPACE);
56 id = strtoul(id_str, &p, 10);
57 if (*p != '\0'
58 || (id != DCC_ID_ANON
59 && (id < DCC_SRVR_ID_MIN || id > DCC_CLNT_ID_MAX))) {
60 if (!strcasecmp(id_str, DCC_XHDR_ID_ANON))
61 return DCC_ID_ANON;
62
63 dcc_pemsg(EX_DATAERR, emsg, "invalid ID \"%s\"%s",
64 id_str, fnm_lno(&fnm_buf, fnm, lno));
65 return DCC_ID_INVALID;
66 }
67
68 return id;
69 }
70
71
72
73 /* get server-ID */
74 const char * /* rest of string */
75 dcc_get_srvr_id(DCC_EMSG emsg,
76 DCC_SRVR_ID *result, /* ID or DCC_ID_INVALID */
77 const char *id_str, const char *dlims,
78 const char *fnm, int lno)
79 {
80 char *p;
81 unsigned long id;
82 DCC_FNM_LNO_BUF fnm_buf;
83
84 if (!dlims)
85 dlims = "";
86 id = strtoul(id_str, &p, 10);
87 if (p == id_str
88 || (*p && !strchr(dlims, *p))
89 || (id < DCC_SRVR_ID_MIN || id > DCC_SRVR_ID_MAX)) {
90 dcc_pemsg(EX_DATAERR, emsg, "invalid server-ID \"%s\"%s",
91 id_str, fnm_lno(&fnm_buf, fnm, lno));
92 *result = DCC_ID_INVALID;
93 return 0;
94 }
95
96 *result = id;
97 return p;
98 }