Created a bigger buffer for write/read.
[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
10 memcached_server_st *memcached_servers_parse(char *server_strings)
11 {
12 char *string;
13 unsigned int port;
14 char *begin_ptr;
15 char *end_ptr;
16 memcached_server_st *servers= NULL;
17 memcached_return rc;
18
19 assert(server_strings);
20
21 end_ptr= server_strings + strlen(server_strings);
22
23 for (begin_ptr= server_strings, string= index(server_strings, ',');
24 begin_ptr != end_ptr;
25 string= index(begin_ptr, ','))
26 {
27 char buffer[HUGE_STRING_LEN];
28 char *ptr;
29 port= 0;
30
31 memset(buffer, 0, HUGE_STRING_LEN);
32 if (string)
33 {
34 memcpy(buffer, begin_ptr, string - begin_ptr);
35 begin_ptr= string+1;
36 }
37 else
38 {
39 size_t length= strlen(begin_ptr);
40 memcpy(buffer, begin_ptr, length);
41 begin_ptr= end_ptr;
42 }
43
44 ptr= index(buffer, ':');
45
46 if (ptr)
47 {
48 ptr[0]= 0;
49
50 ptr++;
51
52 port= strtol(ptr, (char **)NULL, 10);
53 }
54
55 servers= memcached_server_list_append(servers, buffer, port, &rc);
56
57 if (isspace(*begin_ptr))
58 begin_ptr++;
59 }
60
61 return servers;
62 }