From a5b1ca01c3e17b4113d54003b2d6f797d54b17a2 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 18 Jan 2009 15:27:28 +0100 Subject: piano: Safe routeid generation Use modulo instead of >> (shift right) to get seven digits. --- libpiano/src/main.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'libpiano') diff --git a/libpiano/src/main.c b/libpiano/src/main.c index 42c51bf..a71fbba 100644 --- a/libpiano/src/main.c +++ b/libpiano/src/main.c @@ -61,17 +61,16 @@ void PianoFree (void *ptr, size_t size) { } } -/* initialize piano handle, set up curl handle and settings; note: you - * _must_ init curl and libxml2 using curl_global_init (CURL_GLOBAL_SSL) - * and xmlInitParser (), you also _must_ cleanup their garbage on your own! +/* initialize piano handle, set up curl handle and settings; note: _you_ have + * to init curl and libxml2 using curl_global_init (CURL_GLOBAL_SSL) and + * xmlInitParser (), _you_ also have to cleanup their garbage on your own! * @param piano handle * @return nothing */ void PianoInit (PianoHandle_t *ph) { memset (ph, 0, sizeof (*ph)); ph->curlHandle = curl_easy_init (); - /* FIXME: 64-bit may make this hack useless */ - snprintf (ph->routeId, sizeof (ph->routeId), "%07liP", time (NULL)>>8); + snprintf (ph->routeId, sizeof (ph->routeId), "%07liP", time (NULL) % 10000000); curl_easy_setopt (ph->curlHandle, CURLOPT_USERAGENT, PACKAGE_STRING); curl_easy_setopt (ph->curlHandle, CURLOPT_CONNECTTIMEOUT, 60); curl_easy_setopt (ph->curlHandle, CURLOPT_TIMEOUT, 60); -- cgit v1.2.3