Working on getting version patch working
[awesomized/libmemcached] / lib / memcached_version.c
1 #include "common.h"
2
3 const char * memcached_lib_version(void) {
4 return LIBMEMCACHED_VERSION_STRING;
5 }
6
7 memcached_return memcached_version(memcached_st *ptr)
8 {
9 unsigned int x;
10 size_t send_length;
11 memcached_return rc;
12 char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
13 char *response_ptr;
14 char *command= "version\r\n";
15
16 send_length= strlen(command);
17
18 rc= MEMCACHED_SUCCESS;
19 for (x= 0; x < ptr->number_of_hosts; x++)
20 {
21 memcached_return rrc;
22
23 rrc= memcached_do(ptr, x, command, send_length, 1);
24 if (rrc != MEMCACHED_SUCCESS)
25 {
26 rc= MEMCACHED_SOME_ERRORS;
27 continue;
28 }
29
30 rrc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL, x);
31 if (rrc != MEMCACHED_SUCCESS)
32 rc= MEMCACHED_SOME_ERRORS;
33
34 /* Find the space, and then move one past it to copy version */
35 response_ptr= index(buffer, ' ');
36 response_ptr++;
37
38 ptr->hosts[x].major_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
39 response_ptr= index(response_ptr, '.');
40 response_ptr++;
41 ptr->hosts[x].minor_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
42 response_ptr= index(response_ptr, '.');
43 response_ptr++;
44 ptr->hosts[x].micro_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
45 }
46
47 return rc;
48 }