1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-12-22 04:02:04 +03:00

Auto-format after merge

This commit is contained in:
bel
2016-08-15 21:43:38 +02:00
parent a71d31cf2f
commit a3d83a152e
2 changed files with 69 additions and 71 deletions

View File

@@ -4846,54 +4846,53 @@ mg_get_var2(const char *data,
/* HCP24: some changes to compare hole var_name */ /* HCP24: some changes to compare hole var_name */
int int
mg_get_cookie(const char *cookie_header, mg_get_cookie(const char *cookie_header,
const char *var_name, const char *var_name,
char *dst, char *dst,
size_t dst_size) size_t dst_size)
{ {
const char *s, *p, *end; const char *s, *p, *end;
int name_len, len = -1; int name_len, len = -1;
if (dst == NULL || dst_size == 0) { if (dst == NULL || dst_size == 0) {
return -2; return -2;
} }
dst[0] = '\0'; dst[0] = '\0';
if (var_name == NULL || (s = cookie_header) == NULL) { if (var_name == NULL || (s = cookie_header) == NULL) {
return -1; return -1;
} }
name_len = (int)strlen(var_name); name_len = (int)strlen(var_name);
end = s + strlen(s); end = s + strlen(s);
for (; (s = mg_strcasestr( s, var_name)) != NULL; s += name_len) { for (; (s = mg_strcasestr(s, var_name)) != NULL; s += name_len) {
if (s[name_len] == '=') { if (s[name_len] == '=') {
/* HCP24: now check is it a substring or a full cookie name */ /* HCP24: now check is it a substring or a full cookie name */
if ((s == cookie_header) || (s[-1] == ' ')) { if ((s == cookie_header) || (s[-1] == ' ')) {
s += name_len + 1; s += name_len + 1;
if ((p = strchr(s, ' ')) == NULL) { if ((p = strchr(s, ' ')) == NULL) {
p = end; p = end;
} }
if (p[-1] == ';') { if (p[-1] == ';') {
p--; p--;
} }
if (*s == '"' && p[-1] == '"' && p > s + 1) { if (*s == '"' && p[-1] == '"' && p > s + 1) {
s++; s++;
p--; p--;
} }
if ((size_t)(p - s) < dst_size) { if ((size_t)(p - s) < dst_size) {
len = (int)(p - s); len = (int)(p - s);
mg_strlcpy(dst, s, (size_t)len + 1); mg_strlcpy(dst, s, (size_t)len + 1);
} } else {
else { len = -3;
len = -3; }
} break;
break; }
} }
} }
} return len;
return len; }
}
#if defined(USE_WEBSOCKET) || defined(USE_LUA) #if defined(USE_WEBSOCKET) || defined(USE_LUA)

View File

@@ -30,33 +30,32 @@ timer_add(struct mg_context *ctx,
unsigned u, v; unsigned u, v;
int error = 0; int error = 0;
struct timespec now; struct timespec now;
double dt; /* double time */ double dt; /* double time */
if (ctx->stop_flag) { if (ctx->stop_flag) {
return 0; return 0;
} }
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
dt = (double)now.tv_sec; dt = (double)now.tv_sec;
dt += now.tv_nsec * 1.0E-9; dt += now.tv_nsec * 1.0E-9;
/* HCP24: if is_relative = 0 and next_time < now /* HCP24: if is_relative = 0 and next_time < now
* action will be called so fast as possible * action will be called so fast as possible
* if additional period > 0 * if additional period > 0
* action will be called so fast as possible * action will be called so fast as possible
* n times until (next_time + (n * period)) > now * n times until (next_time + (n * period)) > now
* then the period is working * then the period is working
* Solution: * Solution:
* if next_time < now then we set next_time = now. * if next_time < now then we set next_time = now.
* The first callback will be so fast as possible (now) * The first callback will be so fast as possible (now)
* but the next callback on period * but the next callback on period
*/ */
if (is_relative) { if (is_relative) {
next_time += dt; next_time += dt;
} } else if (next_time < dt) {
else if (next_time < dt) { next_time = dt;
next_time = dt; }
}
pthread_mutex_lock(&ctx->timers->mutex); pthread_mutex_lock(&ctx->timers->mutex);
if (ctx->timers->timer_count == MAX_TIMERS) { if (ctx->timers->timer_count == MAX_TIMERS) {
@@ -64,8 +63,8 @@ timer_add(struct mg_context *ctx,
} else { } else {
for (u = 0; u < ctx->timers->timer_count; u++) { for (u = 0; u < ctx->timers->timer_count; u++) {
if (ctx->timers->timers[u].time > next_time) { if (ctx->timers->timers[u].time > next_time) {
/* HCP24: moving all timers > next_time */ /* HCP24: moving all timers > next_time */
for (v = ctx->timers->timer_count; v > u; v--) { for (v = ctx->timers->timer_count; v > u; v--) {
ctx->timers->timers[v] = ctx->timers->timers[v - 1]; ctx->timers->timers[v] = ctx->timers->timers[v - 1];
} }
break; break;