~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to proxy/ControlBase.cc

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-12-17 22:28:16 UTC
  • mfrom: (5.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121217222816-7xwjsx5k76zkb63d
Tags: 3.2.0-1ubuntu1
* Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Apply patch from Konstantinos Margaritis to define barriers on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include "HdrUtils.h"
46
46
#include "Vec.h"
47
47
 
48
 
#include "tsconfig/TsBuffer.h"
 
48
#include <ts/TsBuffer.h>
49
49
 
50
50
/** Used for printing IP address.
51
51
    @code
250
250
// ----------
251
251
struct SrcIPMod : public ControlBase::Modifier {
252
252
  // Stored in host order because that's how they are compared.
253
 
  ip_addr_t start_addr; ///< Start address in HOST order.
254
 
  ip_addr_t end_addr; ///< End address in HOST order.
 
253
  IpEndpoint start_addr; ///< Start address in HOST order.
 
254
  IpEndpoint end_addr; ///< End address in HOST order.
255
255
 
256
256
  static char const * const NAME;
257
257
 
267
267
char const * SrcIPMod::name() const { return NAME; }
268
268
 
269
269
void SrcIPMod::print(FILE* f) const {
270
 
  ip_addr_t a1 = htonl(start_addr);
271
 
  ip_addr_t a2 = htonl(end_addr);
272
 
  fprintf(f, "%s=%d.%d.%d.%d-%d.%d.%d.%d  ",
273
 
    this->name(), TS_IP_OCTETS(a1), TS_IP_OCTETS(a2)
 
270
  ip_text_buffer b1, b2;
 
271
  fprintf(f, "%s=%s-%s  "
 
272
    ,this->name()
 
273
    , ats_ip_ntop(&start_addr.sa, b1, sizeof(b1))
 
274
    , ats_ip_ntop(&end_addr.sa, b2, sizeof(b2))
274
275
  );
275
276
}
276
277
bool SrcIPMod::check(HttpRequestData* req) const {
277
278
  // Compare in host order
278
 
  uint32_t addr = ntohl(req->src_ip);
279
 
  return start_addr <= addr && addr <= end_addr;
 
279
  return ats_ip_addr_cmp(&start_addr, &req->src_ip) <= 0
 
280
    && ats_ip_addr_cmp(&req->src_ip, &end_addr) <= 0
 
281
    ;
280
282
}
281
283
SrcIPMod*
282
284
SrcIPMod::make(char * value, char const ** error ) {
283
285
  SrcIPMod tmp;
284
286
  SrcIPMod* zret = 0;
285
 
  *error = ExtractIpRange(value, &tmp.start_addr, &tmp.end_addr);
 
287
  *error = ExtractIpRange(value, &tmp.start_addr.sa, &tmp.end_addr.sa);
286
288
 
287
289
  if (!*error) zret = new SrcIPMod(tmp);
288
290
  return zret;
349
351
  fprintf(f, "%s=%*s  ", this->name(), static_cast<int>(text.size()), text.data());
350
352
}
351
353
 
352
 
TextMod::TextMod() : text(0,0) {}
 
354
TextMod::TextMod() : text(0) {}
353
355
TextMod::~TextMod() {
354
 
  if (text.data()) free(text.data());
 
356
  free(text.data());
355
357
}
356
358
 
357
359
// ----------
377
379
MethodMod*
378
380
MethodMod::make(char * value, char const **) {
379
381
  MethodMod* mod = new MethodMod;
380
 
  mod->text.set(xstrdup(value), strlen(value));
 
382
  mod->text.set(ats_strdup(value), strlen(value));
381
383
  return mod;
382
384
}
383
385
 
414
416
  // strip leading slashes because get_path which is used later
415
417
  // doesn't include them from the URL.
416
418
  while ('/' == *value) ++value;
417
 
  mod->text.set(xstrdup(value), strlen(value));
 
419
  mod->text.set(ats_strdup(value), strlen(value));
418
420
  return mod;
419
421
}
420
422
// ----------
439
441
SuffixMod*
440
442
SuffixMod::make(char * value, char const ** error ) {
441
443
  SuffixMod* mod = new SuffixMod;
442
 
  mod->text.set(xstrdup(value), strlen(value));
 
444
  mod->text.set(ats_strdup(value), strlen(value));
443
445
  return mod;
444
446
}
445
447
 
461
463
TagMod*
462
464
TagMod::make(char * value, char const ** error ) {
463
465
  TagMod* mod = new TagMod;
464
 
  mod->text.set(xstrdup(value), strlen(value));
 
466
  mod->text.set(ats_strdup(value), strlen(value));
465
467
  return mod;
466
468
}
467
469
// ----------