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