Frankly its too damn useful not to be here though.
*/
-#include <memcached.h>
#include "common.h"
-memcached_server_st *memcached_servers_parse(char *server_strings)
+memcached_server_st *memcached_servers_parse(const char *server_strings)
{
char *string;
- unsigned int port;
- char *begin_ptr;
- char *end_ptr;
+ uint32_t port;
+ uint32_t weight;
+ const char *begin_ptr;
+ const char *end_ptr;
memcached_server_st *servers= NULL;
memcached_return rc;
string= index(begin_ptr, ','))
{
char buffer[HUGE_STRING_LEN];
- char *ptr;
+ char *ptr, *ptr2;
port= 0;
+ weight= 0;
if (string)
{
- memcpy(buffer, begin_ptr, string - begin_ptr);
+ memcpy(buffer, begin_ptr, (size_t) (string - begin_ptr));
buffer[(unsigned int)(string - begin_ptr)]= 0;
begin_ptr= string+1;
}
ptr++;
- port= strtol(ptr, (char **)NULL, 10);
+ port= (uint32_t) strtoul(ptr, (char **)NULL, 10);
+
+ ptr2= index(ptr, ' ');
+ if (! ptr2)
+ ptr2= index(ptr, ':');
+ if (ptr2)
+ {
+ ptr2++;
+ weight = (uint32_t) strtoul(ptr2, (char **)NULL, 10);
+ }
}
- servers= memcached_server_list_append(servers, buffer, port, &rc);
+ servers= memcached_server_list_append_with_weight(servers, buffer, port, weight, &rc);
if (isspace(*begin_ptr))
begin_ptr++;