a4d5b2d431b2c50fd629112af4b48394cda550f7
[awesomized/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 __attribute__((unused)),
26 const memcached_server_st *instance,
27 void *context)
28 {
29 /* Do Nothing */
30 struct local_context *check= (struct local_context *)context;
31
32 if (instance->major_version != UINT8_MAX &&
33 instance->major_version >= check->major_version &&
34 instance->minor_version >= check->minor_version &&
35 instance->micro_version >= check->micro_version )
36 {
37 return MEMCACHED_SUCCESS;
38 }
39
40 check->truth= false;
41
42 return MEMCACHED_FAILURE;
43 }
44
45 bool libmemcached_util_version_check(memcached_st *memc,
46 uint8_t major_version,
47 uint8_t minor_version,
48 uint8_t micro_version)
49 {
50 memcached_server_fn callbacks[1];
51 memcached_return_t rc= memcached_version(memc);
52
53 if (rc != MEMCACHED_SUCCESS)
54 return false;
55
56 struct local_context check= { .major_version= major_version, .minor_version= minor_version, .micro_version= micro_version, .truth= true };
57
58 callbacks[0]= check_server_version;
59 memcached_server_cursor(memc, callbacks, (void *)&check, 1);
60
61 return check.truth;
62 }