Browse Source

[core] add const to reduce .data segment size

personal/stbuehler/mod-csrf
Glenn Strauss 5 years ago
parent
commit
f3437fb2f2
  1. 12
      src/keyvalue.c
  2. 6
      src/keyvalue.h
  3. 4
      src/server.c

12
src/keyvalue.c

@ -7,13 +7,13 @@
#include <stdlib.h>
#include <string.h>
static keyvalue http_versions[] = {
static const keyvalue http_versions[] = {
{ HTTP_VERSION_1_1, "HTTP/1.1" },
{ HTTP_VERSION_1_0, "HTTP/1.0" },
{ HTTP_VERSION_UNSET, NULL }
};
static keyvalue http_methods[] = {
static const keyvalue http_methods[] = {
{ HTTP_METHOD_GET, "GET" },
{ HTTP_METHOD_HEAD, "HEAD" },
{ HTTP_METHOD_POST, "POST" },
@ -56,7 +56,7 @@ static keyvalue http_methods[] = {
{ HTTP_METHOD_UNSET, NULL }
};
static keyvalue http_status[] = {
static const keyvalue http_status[] = {
{ 100, "Continue" },
{ 101, "Switching Protocols" },
{ 102, "Processing" }, /* WebDAV */
@ -110,7 +110,7 @@ static keyvalue http_status[] = {
{ -1, NULL }
};
static keyvalue http_status_body[] = {
static const keyvalue http_status_body[] = {
{ 400, "400.html" },
{ 401, "401.html" },
{ 403, "403.html" },
@ -126,7 +126,7 @@ static keyvalue http_status_body[] = {
};
const char *keyvalue_get_value(keyvalue *kv, int k) {
const char *keyvalue_get_value(const keyvalue *kv, int k) {
int i;
for (i = 0; kv[i].value; i++) {
if (kv[i].key == k) return kv[i].value;
@ -134,7 +134,7 @@ const char *keyvalue_get_value(keyvalue *kv, int k) {
return NULL;
}
int keyvalue_get_key(keyvalue *kv, const char *s) {
int keyvalue_get_key(const keyvalue *kv, const char *s) {
int i;
for (i = 0; kv[i].value; i++) {
if (0 == strcmp(kv[i].value, s)) return kv[i].key;

6
src/keyvalue.h

@ -65,7 +65,7 @@ typedef enum { HTTP_VERSION_UNSET = -1, HTTP_VERSION_1_0, HTTP_VERSION_1_1 } htt
typedef struct {
int key;
char *value;
const char *value;
} keyvalue;
typedef struct {
@ -90,8 +90,8 @@ const char *get_http_status_body_name(int i);
int get_http_version_key(const char *s);
http_method_t get_http_method_key(const char *s);
const char *keyvalue_get_value(keyvalue *kv, int k);
int keyvalue_get_key(keyvalue *kv, const char *s);
const char *keyvalue_get_value(const keyvalue *kv, int k);
int keyvalue_get_key(const keyvalue *kv, const char *s);
pcre_keyvalue_buffer *pcre_keyvalue_buffer_init(void);
int pcre_keyvalue_buffer_append(struct server *srv, pcre_keyvalue_buffer *kvb, const char *key, const char *value);

4
src/server.c

@ -99,10 +99,10 @@ static volatile siginfo_t last_sigterm_info;
static volatile siginfo_t last_sighup_info;
static void sigaction_handler(int sig, siginfo_t *si, void *context) {
static siginfo_t empty_siginfo;
static const siginfo_t empty_siginfo;
UNUSED(context);
if (!si) si = &empty_siginfo;
if (!si) *(const siginfo_t **)&si = &empty_siginfo;
switch (sig) {
case SIGTERM:

Loading…
Cancel
Save