Don't use __attribute__((unused))
[m6w6/libmemcached] / libmemcached / util / version.c
1 /* LibMemcached
2 * Copyright (C) 2010 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: connect to all hosts, and make sure they meet a minimum version
9 *
10 */
11
12 /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
13 #include "libmemcached/common.h"
14 #include "libmemcached/memcached_util.h"
15
16 struct local_context
17 {
18 uint8_t major_version;
19 uint8_t minor_version;
20 uint8_t micro_version;
21
22 bool truth;
23 };
24
25 static memcached_return_t check_server_version(const memcached_st *ptr,
26 const memcached_server_st *instance,
27 void *context)
28 {
29 /* Do Nothing */
30 struct local_context *check= (struct local_context *)context;
31 (void)ptr;
32
33 if (instance->major_version != UINT8_MAX &&
34 instance->major_version >= check->major_version &&
35 instance->minor_version >= check->minor_version &&
36 instance->micro_version >= check->micro_version )
37 {
38 return MEMCACHED_SUCCESS;
39 }
40
41 check->truth= false;
42
43 return MEMCACHED_FAILURE;
44 }
45
46 bool libmemcached_util_version_check(memcached_st *memc,
47 uint8_t major_version,
48 uint8_t minor_version,
49 uint8_t micro_version)
50 {
51 memcached_server_fn callbacks[1];
52 memcached_return_t rc= memcached_version(memc);
53
54 if (rc != MEMCACHED_SUCCESS)
55 return false;
56
57 struct local_context check= { .major_version= major_version, .minor_version= minor_version, .micro_version= micro_version, .truth= true };
58
59 callbacks[0]= check_server_version;
60 memcached_server_cursor(memc, callbacks, (void *)&check, 1);
61
62 return check.truth;
63 }