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