Browse Source

Merge pull request #291 from kainjow/const-warnings

Fix various const warnings
bel2125 9 years ago
parent
commit
a36e852805
4 changed files with 17 additions and 17 deletions
  1. 1 1
      include/civetweb.h
  2. 11 11
      src/civetweb.c
  3. 4 4
      src/main.c
  4. 1 1
      src/md5.inl

+ 1 - 1
include/civetweb.h

@@ -389,7 +389,7 @@ CIVETWEB_API void *mg_get_user_data(const struct mg_context *ctx);
 
 
 /* Set user data for the current connection. */
-CIVETWEB_API void mg_set_user_connection_data(const struct mg_connection *conn,
+CIVETWEB_API void mg_set_user_connection_data(struct mg_connection *conn,
                                               void *data);
 
 

+ 11 - 11
src/civetweb.c

@@ -1739,10 +1739,10 @@ mg_get_user_data(const struct mg_context *ctx)
 
 
 void
-mg_set_user_connection_data(const struct mg_connection *conn, void *data)
+mg_set_user_connection_data(struct mg_connection *conn, void *data)
 {
 	if (conn != NULL) {
-		((struct mg_connection *)conn)->request_info.conn_data = data;
+		conn->request_info.conn_data = data;
 	}
 }
 
@@ -4142,7 +4142,7 @@ mg_write(struct mg_connection *conn, const void *buf, size_t len)
 		                      conn->ssl,
 		                      (const char *)buf,
 		                      (int64_t)allowed)) == allowed) {
-			buf = (char *)buf + total;
+			buf = (const char *)buf + total;
 			conn->last_throttle_bytes += total;
 			while (total < (int64_t)len && conn->ctx->stop_flag == 0) {
 				allowed = conn->throttle > (int64_t)len - total
@@ -4159,7 +4159,7 @@ mg_write(struct mg_connection *conn, const void *buf, size_t len)
 				sleep(1);
 				conn->last_throttle_bytes = allowed;
 				conn->last_throttle_time = time(NULL);
-				buf = (char *)buf + n;
+				buf = (const char *)buf + n;
 				total += n;
 			}
 		}
@@ -5296,19 +5296,19 @@ parse_auth_header(struct mg_connection *conn,
 }
 
 
-static char *
+static const char *
 mg_fgets(char *buf, size_t size, struct file *filep, char **p)
 {
-	char *eof;
+	const char *eof;
 	size_t len;
-	char *memend;
+	const char *memend;
 
 	if (!filep) {
 		return NULL;
 	}
 
 	if (filep->membuf != NULL && *p != NULL) {
-		memend = (char *)&filep->membuf[filep->size];
+		memend = (const char *)&filep->membuf[filep->size];
 		/* Search for \n from p till the end of stream */
 		eof = (char *)memchr(*p, '\n', (size_t)(memend - *p));
 		if (eof != NULL) {
@@ -7516,7 +7516,7 @@ handle_cgi_request(struct mg_connection *conn, const char *prog)
 	if ((status = get_header(&ri, "Status")) != NULL) {
 		conn->status_code = atoi(status);
 		status_text = status;
-		while (isdigit(*(unsigned char *)status_text) || *status_text == ' ') {
+		while (isdigit(*(const unsigned char *)status_text) || *status_text == ' ') {
 			status_text++;
 		}
 	} else if (get_header(&ri, "Location") != NULL) {
@@ -7985,7 +7985,7 @@ mg_fgetc(struct file *filep, int offset)
 	}
 	if (filep->membuf != NULL && offset >= 0
 	    && ((unsigned int)(offset)) < filep->size) {
-		return ((unsigned char *)filep->membuf)[offset];
+		return ((const unsigned char *)filep->membuf)[offset];
 	} else if (filep->fp != NULL) {
 		return fgetc(filep->fp);
 	} else {
@@ -9099,7 +9099,7 @@ get_remote_ip(const struct mg_connection *conn)
 	if (!conn) {
 		return 0;
 	}
-	return ntohl(*(uint32_t *)&conn->client.rsa.sin.sin_addr);
+	return ntohl(*(const uint32_t *)&conn->client.rsa.sin.sin_addr);
 }
 
 

+ 4 - 4
src/main.c

@@ -129,8 +129,8 @@ struct tuser_data {
 
 static int g_exit_flag = 0;         /* Main loop should exit */
 static char g_server_base_name[40]; /* Set by init_server_name() */
-static char *g_server_name;         /* Set by init_server_name() */
-static char *g_icon_name;           /* Set by init_server_name() */
+static const char *g_server_name;         /* Set by init_server_name() */
+static const char *g_icon_name;           /* Set by init_server_name() */
 static char g_config_file_name[PATH_MAX] =
     "";                          /* Set by process_command_line_arguments() */
 static struct mg_context *g_ctx; /* Set by start_civetweb() */
@@ -612,7 +612,7 @@ init_server_name(int argc, const char *argv[])
 		if ((argv[i][0] == '-')
 		    && (0 == strcmp(argv[i] + 1,
 		                    main_config_options[OPTION_TITLE].name))) {
-			g_server_name = (char *)(argv[i + 1]);
+			g_server_name = (const char *)(argv[i + 1]);
 		}
 	}
 	g_icon_name = NULL;
@@ -620,7 +620,7 @@ init_server_name(int argc, const char *argv[])
 		if ((argv[i][0] == '-')
 		    && (0 == strcmp(argv[i] + 1,
 		                    main_config_options[OPTION_ICON].name))) {
-			g_icon_name = (char *)(argv[i + 1]);
+			g_icon_name = (const char *)(argv[i + 1]);
 		}
 	}
 }

+ 1 - 1
src/md5.inl

@@ -245,7 +245,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
 				   see
 				   https://github.com/bel2125/civetweb/issues/94#issuecomment-98112861
 				   */
-				X = (const md5_word_t *)(void *)data;
+				X = (const md5_word_t *)(const void *)data;
 			} else {
 				/* not aligned */
 				memcpy(xbuf, data, 64);