Skip to content
Browse files

Merge pull request #61 from ploxiln/const_args

change (char *) to (const char *) where possible
  • Loading branch information...
2 parents f917114 + e6e7532 commit 489aa9c784ab8578bff1ba71cd868c5a0775ed69 @mreiferson committed
View
2 host_pool/host_pool.c
@@ -52,7 +52,7 @@ void free_host_pool(struct HostPool *host_pool)
}
struct HostPoolEndpoint *new_host_pool_endpoint(struct HostPool *host_pool,
- char *address, int port, char *path)
+ const char *address, int port, char *path)
{
struct HostPoolEndpoint *host_pool_endpoint;
View
2 host_pool/host_pool.h
@@ -37,7 +37,7 @@ struct HostPool *new_host_pool(int retry_failed_hosts, int retry_interval,
int max_retry_interval, int reset_on_all_failed);
void free_host_pool(struct HostPool *host_pool);
struct HostPoolEndpoint *new_host_pool_endpoint(struct HostPool *host_pool,
- char *address, int port, char *path);
+ const char *address, int port, char *path);
void free_host_pool_endpoint(struct HostPoolEndpoint *host_pool_endpoint);
void host_pool_from_json(struct HostPool *host_pool, json_object *host_pool_endpoint_list);
struct HostPoolEndpoint *host_pool_get_endpoint(struct HostPool *host_pool,
View
4 pubsub_filtered/pubsub_filtered.c
@@ -65,7 +65,7 @@ int filter_message(char *subject, pcre *filter, struct json_object *json_in);
int parse_encrypted_fields(char *str);
int parse_blacklisted_fields(char *str);
-int parse_fields(char *str, char **field_array);
+int parse_fields(const char *str, char **field_array);
int can_kick(struct cli *client);
int is_slow(struct cli *client);
@@ -158,7 +158,7 @@ int parse_encrypted_fields(char *str)
* in an char array. Array better have enough slots
* because I didn't have time to work out the memory allocation.
*/
-int parse_fields(char *str, char **field_array)
+int parse_fields(const char *str, char **field_array)
{
int i;
const char delim[] = ",";
View
2 shared_tests/test_shunt.py
@@ -152,4 +152,4 @@ def tearDownClass(self):
logging.debug('cleaning up %s' % dirname)
pipe = subprocess.Popen(['rm', '-rf', dirname])
pipe.wait()
- check_valgrind_output('test_output/vg.out')
+ check_valgrind_output(os.path.join(self.test_output_dir, 'vg.out'))
View
13 simplehttp/async_simplehttp.c
@@ -49,7 +49,7 @@ static void async_simplehttp_log(struct evhttp_request *req, struct AsyncCallbac
}
}
-struct evhttp_connection *get_connection(char *address, int port, struct Connection **store_conn)
+struct evhttp_connection *get_connection(const char *address, int port, struct Connection **store_conn)
{
struct Connection *conn;
int i;
@@ -103,15 +103,14 @@ void free_async_callback_group(struct AsyncCallbackGroup *callback_group)
}
}
-struct AsyncCallback *new_async_request(char *address, int port, char *path,
+struct AsyncCallback *new_async_request(const char *address, int port, const char *path,
void (*cb)(struct evhttp_request *, void *), void *cb_arg)
{
return new_async_request_with_body(EVHTTP_REQ_GET, address, port, path, NULL, NULL, cb, cb_arg);
}
-struct AsyncCallback *new_async_request_with_body(int request_method, char *address, int port, char *path,
- struct RequestHeader *header_list, char *body,
- void (*cb)(struct evhttp_request *, void *), void *cb_arg)
+struct AsyncCallback *new_async_request_with_body(int request_method, const char *address, int port, const char *path,
+ struct RequestHeader *header_list, const char *body, void (*cb)(struct evhttp_request *, void *), void *cb_arg)
{
static uint64_t counter = 0;
// create new connection to endpoint
@@ -167,8 +166,8 @@ struct AsyncCallback *new_async_request_with_body(int request_method, char *addr
return callback;
}
-int new_async_callback(struct AsyncCallbackGroup *callback_group, char *address, int port, char *path,
- void (*cb)(struct evhttp_request *, void *), void *cb_arg)
+int new_async_callback(struct AsyncCallbackGroup *callback_group, const char *address, int port,
+ const char *path, void (*cb)(struct evhttp_request *, void *), void *cb_arg)
{
struct AsyncCallback *callback = NULL;
View
2 simplehttp/async_simplehttp.h
@@ -49,7 +49,7 @@ struct Connection {
};
void finish_async_request(struct evhttp_request *req, void *cb_arg);
-struct evhttp_connection *get_connection(char *address, int port, struct Connection **store_conn);
+struct evhttp_connection *get_connection(const char *address, int port, struct Connection **store_conn);
void free_async_callback(struct AsyncCallback *callback);
#endif
View
2 simplehttp/options.c
@@ -320,7 +320,7 @@ int option_define_int(const char *option_name, int required, int default_val, in
return 1;
}
-int option_define_str(const char *option_name, int required, char *default_val, char **dest, int(*cb)(char *value), const char *help)
+int option_define_str(const char *option_name, int required, const char *default_val, char **dest, int(*cb)(char *value), const char *help)
{
struct Option *option = new_option(option_name, required, help);
if (!option) {
View
2 simplehttp/options.h
@@ -8,7 +8,7 @@ enum required_option {
int option_parse_command_line(int argc, char **argv);
int option_define_int(const char *option_name, int required, int default_val, int *dest, int(*cb)(int value), const char *help);
-int option_define_str(const char *option_name, int required, char *default_val, char **dest, int(*cb)(char *value), const char *help);
+int option_define_str(const char *option_name, int required, const char *default_val, char **dest, int(*cb)(char *value), const char *help);
int option_define_bool(const char *option_name, int required, int default_val, int *dest, int(*cb)(int value), const char *help);
int option_define_char(const char *option_name, int required, char default_val, char *dest, int(*cb)(char value), const char *help);
View
14 simplehttp/request.c
@@ -114,33 +114,33 @@ void simplehttp_async_finish(struct evhttp_request *req)
int get_argument_format(struct evkeyvalq *args)
{
int format_code = json_format;
- char *format = (char *)evhttp_find_header(args, "format");
+ const char *format = evhttp_find_header(args, "format");
if (format && !strncmp(format, "txt", 3)) {
format_code = txt_format;
}
return format_code;
}
-int get_int_argument(struct evkeyvalq *args, char *key, int default_value)
+int get_int_argument(struct evkeyvalq *args, const char *key, int default_value)
{
- char *tmp;
+ const char *tmp;
if (!key) {
return default_value;
}
- tmp = (char *)evhttp_find_header(args, (const char *)key);
+ tmp = evhttp_find_header(args, key);
if (tmp) {
return atoi(tmp);
}
return default_value;
}
-double get_double_argument(struct evkeyvalq *args, char *key, double default_value)
+double get_double_argument(struct evkeyvalq *args, const char *key, double default_value)
{
- char *tmp;
+ const char *tmp;
if (!key) {
return default_value;
}
- tmp = (char *)evhttp_find_header(args, (const char *)key);
+ tmp = evhttp_find_header(args, key);
if (tmp) {
return atof(tmp);
}
View
2 simplehttp/simplehttp.c
@@ -169,7 +169,7 @@ void simplehttp_free()
simplehttp_stats_destruct();
}
-void simplehttp_set_cb(char *path, void (*cb)(struct evhttp_request *, struct evbuffer *, void *), void *ctx)
+void simplehttp_set_cb(const char *path, void (*cb)(struct evhttp_request *, struct evbuffer *, void *), void *ctx)
{
struct cb_entry *cbPtr;
View
21 simplehttp/simplehttp.h
@@ -38,7 +38,7 @@ int simplehttp_main();
int simplehttp_listen();
void simplehttp_run();
void simplehttp_free();
-void simplehttp_set_cb(char *path, void (*cb)(struct evhttp_request *, struct evbuffer *, void *), void *ctx);
+void simplehttp_set_cb(const char *path, void (*cb)(struct evhttp_request *, struct evbuffer *, void *), void *ctx);
uint64_t simplehttp_request_id(struct evhttp_request *req);
void simplehttp_async_enable(struct evhttp_request *req);
@@ -64,27 +64,28 @@ struct RequestHeader {
/* start a new callback_group. memory will be freed after a call to
release_callback_group or when all the callbacks have been run */
-struct AsyncCallbackGroup *new_async_callback_group(struct evhttp_request *req, void (*finished_cb)(struct evhttp_request *, void *), void *finished_cb_arg);
+struct AsyncCallbackGroup *new_async_callback_group(struct evhttp_request *req,
+ void (*finished_cb)(struct evhttp_request *, void *), void *finished_cb_arg);
/* create a new AsyncCallback. delegation of memory for this callback
will be passed to callback_group */
-int new_async_callback(struct AsyncCallbackGroup *callback_group, char *address, int port, char *path, void (*cb)(struct evhttp_request *, void *), void *cb_arg);
-struct AsyncCallback *new_async_request(char *address, int port, char *path,
+int new_async_callback(struct AsyncCallbackGroup *callback_group, const char *address, int port,
+ const char *path, void (*cb)(struct evhttp_request *, void *), void *cb_arg);
+struct AsyncCallback *new_async_request(const char *address, int port, const char *path,
void (*cb)(struct evhttp_request *, void *), void *cb_arg);
-struct AsyncCallback *new_async_request_with_body(int request_method, char *address, int port, char *path,
- struct RequestHeader *header_list, char *body,
- void (*cb)(struct evhttp_request *, void *), void *cb_arg);
+struct AsyncCallback *new_async_request_with_body(int request_method, const char *address, int port, const char *path,
+ struct RequestHeader *header_list, const char *body, void (*cb)(struct evhttp_request *, void *), void *cb_arg);
void free_async_callback_group(struct AsyncCallbackGroup *callback_group);
void init_async_connection_pool(int enable_request_logging);
void free_async_connection_pool();
enum response_formats {json_format, txt_format};
int get_argument_format(struct evkeyvalq *args);
-int get_int_argument(struct evkeyvalq *args, char *key, int default_value);
-double get_double_argument(struct evkeyvalq *args, char *key, double default_value);
+int get_int_argument(struct evkeyvalq *args, const char *key, int default_value);
+double get_double_argument(struct evkeyvalq *args, const char *key, double default_value);
void define_simplehttp_options();
-int simplehttp_parse_url(char *endpoint, size_t endpoint_len, char **address, int *port, char **path);
+int simplehttp_parse_url(const char *endpoint, size_t endpoint_len, char **address, int *port, char **path);
char *simplehttp_encode_uri(const char *uri);
#endif
View
32 simplehttp/util.c
@@ -56,11 +56,10 @@ uint64_t ninety_five_percent(int64_t *int_array, int length)
return value;
}
-int simplehttp_parse_url(char *endpoint, size_t endpoint_len, char **address, int *port, char **path)
+int simplehttp_parse_url(const char *endpoint, size_t endpoint_len, char **address, int *port, char **path)
{
// parse out address, port, path
- char *tmp_port = NULL;
- char *tmp_pointer;
+ const char *address_p, *path_p, *tmp_pointer, *tmp_port;
size_t address_len;
size_t path_len;
@@ -70,36 +69,35 @@ int simplehttp_parse_url(char *endpoint, size_t endpoint_len, char **address, in
}
// find the first /
- *address = (char *)strchr(endpoint, '/'); // http:/
- if (!*address) {
+ address_p = strchr(endpoint, '/'); // http:/
+ if (!address_p) {
return 0;
}
// move past the two slashes
- *address = *address + 2;
+ address_p += 2;
// check for the colon specifying a port
- tmp_pointer = (char *)strchr(*address, ':');
- *path = (char *)strchr(*address, '/');
+ tmp_pointer = strchr(address_p, ':');
+ path_p = strchr(address_p, '/');
- if (!*path) {
+ if (!path_p) {
return 0;
}
if (tmp_pointer) {
- address_len = tmp_pointer - *address;
- tmp_port = *address + address_len + 1;
- **path = '\0';
+ address_len = tmp_pointer - address_p;
+ tmp_port = address_p + address_len + 1;
+ // atoi() will stop at the first non-digit which will be '/'
*port = atoi(tmp_port);
- **path = '/';
} else {
- address_len = *path - *address;
+ address_len = path_p - address_p;
*port = 80;
}
- path_len = (endpoint + endpoint_len) - *path;
- *address = strndup(*address, address_len);
- *path = strndup(*path, path_len);
+ path_len = (endpoint + endpoint_len) - path_p;
+ *address = strndup(address_p, address_len);
+ *path = strndup(path_p, path_len);
return 1;
}
View
2 simpleleveldb/str_list_set.h
@@ -31,7 +31,7 @@ static inline void serialize_list_item(struct evbuffer *output, const char *item
evbuffer_add_printf(output, "%s", item);
}
-static inline void add_new_set_item(struct SetItem **set, char *value_ptr)
+static inline void add_new_set_item(struct SetItem **set, const char *value_ptr)
{
struct SetItem *set_item;
set_item = calloc(1, sizeof(struct SetItem));

0 comments on commit 489aa9c

Please sign in to comment.
Something went wrong with that request. Please try again.