Index: trunk/extensions/PoolCounter/daemon/locks.c |
— | — | @@ -26,6 +26,22 @@ |
27 | 27 | #define DOUBLE_LLIST_DEL(this) do { (this)->prev->next = (this)->next; (this)->next->prev = (this)->prev; } while (0) |
28 | 28 | #define DOUBLE_LLIST_ADD(parent,child) do { (child)->prev = (parent)->prev; (child)->next = (child)->prev->next /* parent */; (parent)->prev->next = (child); (parent)->prev = (child); } while(0); |
29 | 29 | |
| 30 | +/* Converts a numeric text into an unsigned integer. |
| 31 | + * Returns 0 if it's a NULL pointer or not a natural. |
| 32 | + */ |
| 33 | +unsigned atou(char const* astext) { |
| 34 | + int num = 0; |
| 35 | + if (!astext) return 0; |
| 36 | + |
| 37 | + while ( *astext ) { |
| 38 | + if ( *astext < '0' ) return 0; |
| 39 | + if ( *astext > '9' ) return 0; |
| 40 | + num = num * 10 + *astext - '0'; |
| 41 | + astext++; |
| 42 | + } |
| 43 | + return num; |
| 44 | +} |
| 45 | + |
30 | 46 | char* process_line(struct client_data* cli_data, char* line, int line_len) { |
31 | 47 | struct locks* l = &cli_data->client_locks; |
32 | 48 | |
— | — | @@ -37,10 +53,14 @@ |
38 | 54 | int for_anyone = line[6] != ' '; |
39 | 55 | |
40 | 56 | char* key = strtok( line + 7 + for_anyone, " " ); |
41 | | - int workers = atoi( strtok(NULL, " ") ); |
42 | | - int maxqueue = atoi( strtok(NULL, " ") ); |
43 | | - int timeout = atoi( strtok(NULL, " ") ); |
| 57 | + unsigned workers = atou( strtok(NULL, " ") ); |
| 58 | + unsigned maxqueue = atou( strtok(NULL, " ") ); |
| 59 | + unsigned timeout = atou( strtok(NULL, " ") ); |
44 | 60 | |
| 61 | + if ( !key || !workers || !maxqueue || !timeout ) { |
| 62 | + return "ERROR BAD_SYNTAX\n"; |
| 63 | + } |
| 64 | + |
45 | 65 | uint32_t hash_value = hash( key, strlen( key ), 0 ); |
46 | 66 | struct PoolCounter* pCounter; |
47 | 67 | pCounter = hashtable_find( primary_hashtable, hash_value, key ); |