Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify. Use WS_Dup() instead of WS_Reserve() and a bunch of tracking

  • Loading branch information...
commit 70bd230e2200f1358e4f3bed6e93caa1b57edade 1 parent 14fba66
Lee Doolan - US Operations Engineer authored
Showing with 11 additions and 13 deletions.
  1. +11 −13 src/vmod_geoip.c
View
24 src/vmod_geoip.c
@@ -1,13 +1,17 @@
+/**/
#include <stdlib.h>
+#include <pthread.h>
+#include <GeoIP.h>
#include "vrt.h"
#include "bin/varnishd/cache.h"
-#include <GeoIP.h>
+#include "include/vct.h"
#include "vcc_if.h"
static GeoIP *gi = NULL;
static pthread_mutex_t gi_mutex;
static const char *unknownCountry= "Unknown";
+static char wspace[8192];
int
init_function(struct vmod_priv *priv, const struct VCL_conf *conf)
@@ -23,27 +27,21 @@ init_function(struct vmod_priv *priv, const struct VCL_conf *conf)
const char *
vmod_country(struct sess *sp, const char *ip)
{
- int ret, w, v;
+ int ret;
const char *country = NULL;
char *cp;
- if (!gi) return unknownCountry;
+ if (!gi) return(unknownCountry);
ret = pthread_mutex_lock(&gi_mutex);
assert(ret == 0);
country = GeoIP_country_code_by_addr(gi, ip);
+ if (country == NULL) {
+ return(unknownCountry);
+ }
- w = WS_Reserve(sp->wrk->ws, 0); /* Reserve some work space (w= # bytes reserved) */
- cp = sp->wrk->ws->f; /* Front of workspace area */
- *cp= 0;
- v= snprintf(cp, w, "%s", country ? country : unknownCountry);
-
+ cp= WS_Dup(sp->wrk->ws, country);
pthread_mutex_unlock(&gi_mutex);
- if (v > w) {
- /* Insufficient reserved space, reset and leave */
- WS_Release(sp->wrk->ws, 0);
- return (unknownCountry);
- }
return(cp);
}
Please sign in to comment.
Something went wrong with that request. Please try again.