MEMCACHED_BAD_KEY_PROVIDED has been added as an error type. When libmemcached
[m6w6/libmemcached] / lib / memcached_parse.c
1 /*
2 I debated about putting this in the client library since it does an
3 action I don't really believe belongs in the library.
4
5 Frankly its too damn useful not to be here though.
6 */
7
8 #include <memcached.h>
9 #include <common.h>
10
11 memcached_server_st *memcached_servers_parse(char *server_strings)
12 {
13 char *string;
14 unsigned int port;
15 char *begin_ptr;
16 char *end_ptr;
17 memcached_server_st *servers= NULL;
18 memcached_return rc;
19
20 WATCHPOINT_ASSERT(server_strings);
21
22 end_ptr= server_strings + strlen(server_strings);
23
24 for (begin_ptr= server_strings, string= index(server_strings, ',');
25 begin_ptr != end_ptr;
26 string= index(begin_ptr, ','))
27 {
28 char buffer[HUGE_STRING_LEN];
29 char *ptr;
30 port= 0;
31
32 if (string)
33 {
34 memcpy(buffer, begin_ptr, string - begin_ptr);
35 buffer[(unsigned int)(string - begin_ptr)]= 0;
36 begin_ptr= string+1;
37 }
38 else
39 {
40 size_t length= strlen(begin_ptr);
41 memcpy(buffer, begin_ptr, length);
42 buffer[length]= 0;
43 begin_ptr= end_ptr;
44 }
45
46 ptr= index(buffer, ':');
47
48 if (ptr)
49 {
50 ptr[0]= 0;
51
52 ptr++;
53
54 port= strtol(ptr, (char **)NULL, 10);
55 }
56
57 servers= memcached_server_list_append(servers, buffer, port, &rc);
58
59 if (isspace(*begin_ptr))
60 begin_ptr++;
61 }
62
63 return servers;
64 }