http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/load_http_hdr.cc ---------------------------------------------------------------------- diff --git a/lib/ts/load_http_hdr.cc b/lib/ts/load_http_hdr.cc index 2ea31a3..66de373 100644 --- a/lib/ts/load_http_hdr.cc +++ b/lib/ts/load_http_hdr.cc @@ -43,18 +43,17 @@ #include <fcntl.h> #include <unistd.h> -enum hdr_type -{ +enum hdr_type { UNKNOWN_HDR, REQUEST_HDR, RESPONSE_HDR, HTTP_INFO_HDR, - RAW_MBUFFER + RAW_MBUFFER, }; void walk_mime_field(MIMEField f); -void walk_mstring(MBuffer * bufp, int32_t offset); -void walk_mbuffer(MBuffer * bufp); +void walk_mstring(MBuffer *bufp, int32_t offset); +void walk_mbuffer(MBuffer *bufp); void print_http_info_impl(HTTPInfo hi); void print_http_hdr_impl(HTTPHdr h); @@ -110,7 +109,6 @@ dump_hdr(char *mbuf, hdr_type h_type) void load_buffer(int fd, hdr_type h_type) { - struct stat s_info; if (fstat(fd, &s_info) < 0) { @@ -166,7 +164,6 @@ load_buffer(int fd, hdr_type h_type) int cur_line = 0; while (cur_line < num_lines && bytes_read < mbuf_size) { - int *cur_ptr; num_el = el_tok.Initialize(line_tok[cur_line]); @@ -176,7 +173,7 @@ load_buffer(int fd, hdr_type h_type) fprintf(stderr, "Corrupted data file\n"); exit(1); } - cur_ptr = (int *) (mbuf + bytes_read); + cur_ptr = (int *)(mbuf + bytes_read); *cur_ptr = el; bytes_read += 4; } @@ -185,7 +182,7 @@ load_buffer(int fd, hdr_type h_type) if (bytes_read != mbuf_length) { fprintf(stderr, "Size mismatch: read %d mbuf_length %d mbuf_size %d\n", bytes_read, mbuf_length, mbuf_size); -// exit(1); + // exit(1); } /* @@ -213,7 +210,6 @@ load_buffer(int fd, hdr_type h_type) int main(int argc, const char *argv[]) { - hdr_type h_type = UNKNOWN_HDR; http_init(); @@ -251,63 +247,46 @@ main(int argc, const char *argv[]) Code for manual groking the mbuf objects *******************************************************************/ -//extern const char *marshal_strs[]; - -char *marshal_type_strs[] = { - "EMPTY ", - "OBJ ", - "STR ", - "URL ", - "URL_F ", - "URL_H ", - "M_VALS", - "M_FLD ", - "M_HDR ", - "H_HDR ", - "H_REQ ", - "H_RESP", - "H_INFO" -}; +// extern const char *marshal_strs[]; + +char *marshal_type_strs[] = {"EMPTY ", "OBJ ", "STR ", "URL ", "URL_F ", "URL_H ", "M_VALS", + "M_FLD ", "M_HDR ", "H_HDR ", "H_REQ ", "H_RESP", "H_INFO"}; void -walk_mbuffer(MBuffer * bufp) +walk_mbuffer(MBuffer *bufp) { int offset = 3; int max_offset = (*bufp->m_length) / 4; do { - MObjectImpl *mo = (MObjectImpl *) mbuffer_get_obj(bufp, offset); - printf("offset %.3d m_length %.2d m_type %s ", offset, (int) mo->m_length, marshal_type_strs[mo->type]); - - switch ((int) mo->type) { - case MARSHAL_MIME_FIELD: - { - MIMEField f(bufp, offset); - walk_mime_field(f); - break; - } - case MARSHAL_STRING: - { - walk_mstring(bufp, offset); - printf("\n"); - break; - } - case MARSHAL_HTTP_INFO: - { - HTTPInfo i(bufp, offset); - print_http_info_impl(i); - printf("\n"); - break; - } + MObjectImpl *mo = (MObjectImpl *)mbuffer_get_obj(bufp, offset); + printf("offset %.3d m_length %.2d m_type %s ", offset, (int)mo->m_length, marshal_type_strs[mo->type]); + + switch ((int)mo->type) { + case MARSHAL_MIME_FIELD: { + MIMEField f(bufp, offset); + walk_mime_field(f); + break; + } + case MARSHAL_STRING: { + walk_mstring(bufp, offset); + printf("\n"); + break; + } + case MARSHAL_HTTP_INFO: { + HTTPInfo i(bufp, offset); + print_http_info_impl(i); + printf("\n"); + break; + } case MARSHAL_HTTP_HEADER: case MARSHAL_HTTP_HEADER_REQ: - case MARSHAL_HTTP_HEADER_RESP: - { - HTTPHdr h(bufp, offset); - print_http_hdr_impl(h); - printf("\n"); - break; - } + case MARSHAL_HTTP_HEADER_RESP: { + HTTPHdr h(bufp, offset); + print_http_hdr_impl(h); + printf("\n"); + break; + } default: @@ -319,16 +298,16 @@ walk_mbuffer(MBuffer * bufp) } void -walk_mstring(MBuffer * bufp, int32_t offset) +walk_mstring(MBuffer *bufp, int32_t offset) { int bufindex = 0; int dumpoffset = 0; char fbuf[4096]; -// int32_t soffset = field_offset; -// soffset <<= MARSHAL_ALIGNMENT; -// printf("offset: %d. shifted field_offset: %d\n", -// field_offset, soffset); + // int32_t soffset = field_offset; + // soffset <<= MARSHAL_ALIGNMENT; + // printf("offset: %d. shifted field_offset: %d\n", + // field_offset, soffset); memset(fbuf, 0, 4096); mstring_print(bufp, offset, fbuf, 4095, &bufindex, &dumpoffset); @@ -339,22 +318,21 @@ walk_mstring(MBuffer * bufp, int32_t offset) void walk_mime_field(MIMEField f) { - int bufindex = 0; int dumpoffset = 0; char fbuf[4096]; -// int32_t soffset = field_offset; -// soffset <<= MARSHAL_ALIGNMENT; -// printf("offset: %d. shifted field_offset: %d\n", -// field_offset, soffset); + // int32_t soffset = field_offset; + // soffset <<= MARSHAL_ALIGNMENT; + // printf("offset: %d. shifted field_offset: %d\n", + // field_offset, soffset); MIMEFieldImpl *fi = MIMEFieldPtr(f.m_buffer, f.m_offset); memset(fbuf, 0, 4096); mime_field_print(f.m_buffer, f.m_offset, fbuf, 4095, &bufindex, &dumpoffset); - printf("(%d,%d) [%d,%d,%d] %s", (int) fi->m_nvalues, (int) fi->m_flags, - (int) fi->m_name_offset, (int) fi->m_values_offset, (int) fi->m_next_offset, fbuf); + printf("(%d,%d) [%d,%d,%d] %s", (int)fi->m_nvalues, (int)fi->m_flags, (int)fi->m_name_offset, (int)fi->m_values_offset, + (int)fi->m_next_offset, fbuf); } void @@ -409,8 +387,7 @@ print_http_info_impl(HTTPInfo hi) return; } - printf("id: %d rid: %d req: %d resp: %d", - info->m_id, info->m_rid, info->m_request_offset, info->m_response_offset); + printf("id: %d rid: %d req: %d resp: %d", info->m_id, info->m_rid, info->m_request_offset, info->m_response_offset); } void @@ -419,18 +396,16 @@ print_http_hdr_impl(HTTPHdr h) HTTPHdrImpl *hdr = HTTPHdrPtr(h.m_buffer, h.m_offset); if (hdr->type == MARSHAL_HTTP_HEADER) { - printf("fields: %d", (int) hdr->m_fields_offset); + printf("fields: %d", (int)hdr->m_fields_offset); return; } else if (hdr->type == MARSHAL_HTTP_HEADER_REQ) { - printf("method: %d url: %d fields: %d", - (int) hdr->u.req.m_method_offset, (int) hdr->u.req.m_url_offset, (int) hdr->m_fields_offset); + printf("method: %d url: %d fields: %d", (int)hdr->u.req.m_method_offset, (int)hdr->u.req.m_url_offset, + (int)hdr->m_fields_offset); } else if (hdr->type == MARSHAL_HTTP_HEADER_RESP) { - printf("status: %d reason: %d fields: %d", - (int) hdr->u.resp.m_status, (int) hdr->u.resp.m_reason_offset, (int) hdr->m_fields_offset); + printf("status: %d reason: %d fields: %d", (int)hdr->u.resp.m_status, (int)hdr->u.resp.m_reason_offset, + (int)hdr->m_fields_offset); } else { printf("Type match failed\n"); return; } - - }
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/lockfile.cc ---------------------------------------------------------------------- diff --git a/lib/ts/lockfile.cc b/lib/ts/lockfile.cc index f6e9587..d8646ad 100644 --- a/lib/ts/lockfile.cc +++ b/lib/ts/lockfile.cc @@ -24,22 +24,22 @@ #include "ink_platform.h" #include "ink_lockfile.h" -#define LOCKFILE_BUF_LEN 16 // 16 bytes should be enought for a pid +#define LOCKFILE_BUF_LEN 16 // 16 bytes should be enought for a pid int -Lockfile::Open(pid_t * holding_pid) +Lockfile::Open(pid_t *holding_pid) { char buf[LOCKFILE_BUF_LEN]; pid_t val; int err; *holding_pid = 0; -#define FAIL(x) \ -{ \ - if (fd > 0) \ - close (fd); \ - return (x); \ -} +#define FAIL(x) \ + { \ + if (fd > 0) \ + close(fd); \ + return (x); \ + } struct flock lock; char *t; @@ -89,7 +89,7 @@ Lockfile::Open(pid_t * holding_pid) *t = '\0'; // coverity[secure_coding] - if (sscanf(buf, "%d\n", (int*)&val) != 1) { + if (sscanf(buf, "%d\n", (int *)&val) != 1) { *holding_pid = 0; } else { *holding_pid = val; @@ -118,13 +118,13 @@ Lockfile::Open(pid_t * holding_pid) // Return the file descriptor of the opened lockfile. When this file // descriptor is closed the lock will be released. - return (1); // success + return (1); // success #undef FAIL } int -Lockfile::Get(pid_t * holding_pid) +Lockfile::Get(pid_t *holding_pid) { char buf[LOCKFILE_BUF_LEN]; int err; @@ -152,18 +152,18 @@ Lockfile::Get(pid_t * holding_pid) return (-errno); } // Write our process id to the Lockfile. - snprintf(buf, sizeof(buf), "%d\n", (int) getpid()); + snprintf(buf, sizeof(buf), "%d\n", (int)getpid()); do { err = write(fd, buf, strlen(buf)); } while ((err < 0) && (errno == EINTR)); - if (err != (int) strlen(buf)) { + if (err != (int)strlen(buf)) { close(fd); return (-errno); } - return (1); // success + return (1); // success } void @@ -205,14 +205,14 @@ lockfile_kill_internal(pid_t init_pid, int init_sig, pid_t pid, const char * /* // Wait for children to exit do { err = waitpid(-1, &status, WNOHANG); - if (err == -1) break; - } while(!WIFEXITED(status) && !WIFSIGNALED(status)); + if (err == -1) + break; + } while (!WIFEXITED(status) && !WIFSIGNALED(status)); } do { err = kill(pid, sig); } while ((err == 0) || ((err < 0) && (errno == EINTR))); - } void @@ -223,10 +223,10 @@ Lockfile::Kill(int sig, int initial_sig, const char *pname) pid_t holding_pid; err = Open(&holding_pid); - if (err == 1) // success getting the lock file + if (err == 1) // success getting the lock file { Close(); - } else if (err == 0) // someone else has the lock + } else if (err == 0) // someone else has the lock { pid = holding_pid; if (pid != 0) { @@ -243,10 +243,10 @@ Lockfile::KillGroup(int sig, int initial_sig, const char *pname) pid_t holding_pid; err = Open(&holding_pid); - if (err == 1) // success getting the lock file + if (err == 1) // success getting the lock file { Close(); - } else if (err == 0) // someone else has the lock + } else if (err == 0) // someone else has the lock { do { pid = getpgid(holding_pid); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/mkdfa.c ---------------------------------------------------------------------- diff --git a/lib/ts/mkdfa.c b/lib/ts/mkdfa.c index d02ae25..7b94b93 100644 --- a/lib/ts/mkdfa.c +++ b/lib/ts/mkdfa.c @@ -27,29 +27,26 @@ #include <stdlib.h> #include <string.h> -#define SIZEOF(t) (sizeof (t) / (sizeof ((t)[0]))) +#define SIZEOF(t) (sizeof(t) / (sizeof((t)[0]))) typedef struct _info_t info_t; typedef struct _state_t state_t; typedef struct _transition_t transition_t; -struct _info_t -{ +struct _info_t { const char *name; const char *value; int namelen; }; -struct _state_t -{ +struct _state_t { int num; const char *value; transition_t *transitions; }; -struct _transition_t -{ +struct _transition_t { int value; state_t *state; transition_t *next; @@ -269,7 +266,7 @@ mkstate() { state_t *state; - state = (state_t *) malloc(sizeof(state_t)); + state = (state_t *)malloc(sizeof(state_t)); state->num = state_count++; state->value = NULL; state->transitions = NULL; @@ -282,7 +279,7 @@ mktransition() { transition_t *transition; - transition = (transition_t *) malloc(sizeof(transition_t)); + transition = (transition_t *)malloc(sizeof(transition_t)); transition->value = 0; transition->state = NULL; transition->next = NULL; @@ -291,7 +288,7 @@ mktransition() } void -prstate(state_t * state) +prstate(state_t *state) { transition_t *transitions; @@ -315,7 +312,7 @@ prstate(state_t * state) } void -add_states(state_t * state, info_t * info, int pos) +add_states(state_t *state, info_t *info, int pos) { transition_t *transitions; @@ -378,7 +375,7 @@ prtable(const char *type, const char *name, int *table, int size) } int -mkmap(state_t * state) +mkmap(state_t *state) { static int count = 1; @@ -401,7 +398,7 @@ mkmap(state_t * state) } void -mkaccept(state_t * state, const char *defvalue) +mkaccept(state_t *state, const char *defvalue) { transition_t *transitions; @@ -418,11 +415,11 @@ mkaccept(state_t * state, const char *defvalue) } void -mkprefix(state_t * state, char *prefix, int length) +mkprefix(state_t *state, char *prefix, int length) { transition_t *transitions; - prefixtbl[state->num] = (char *) malloc(sizeof(char) * (length + 1)); + prefixtbl[state->num] = (char *)malloc(sizeof(char) * (length + 1)); strncpy(prefixtbl[state->num], prefix, length); prefixtbl[state->num][length] = '\0'; @@ -435,7 +432,7 @@ mkprefix(state_t * state, char *prefix, int length) } int -checkbase(state_t * state, int base) +checkbase(state_t *state, int base) { transition_t *transitions; @@ -450,7 +447,7 @@ checkbase(state_t * state, int base) } void -mktranstables(state_t * state) +mktranstables(state_t *state) { transition_t *transitions; int base; @@ -483,14 +480,14 @@ mktranstables(state_t * state) } void -mktables(state_t * state, const char *defvalue, int useprefix) +mktables(state_t *state, const char *defvalue, int useprefix) { char prefix[1024]; int char_count; int i; /* make the character map */ - map = (int *) malloc(sizeof(int) * 256); + map = (int *)malloc(sizeof(int) * 256); for (i = 0; i < 256; i++) map[i] = 0; @@ -500,7 +497,7 @@ mktables(state_t * state, const char *defvalue, int useprefix) printf("\n"); /* make the accept state table */ - accepttbl = (const char **) malloc(sizeof(const char *) * state_count); + accepttbl = (const char **)malloc(sizeof(const char *) * state_count); for (i = 0; i < state_count; i++) accepttbl[i] = NULL; @@ -517,7 +514,7 @@ mktables(state_t * state, const char *defvalue, int useprefix) /* make the prefix table */ if (useprefix) { - prefixtbl = (char **) malloc(sizeof(char *) * state_count); + prefixtbl = (char **)malloc(sizeof(char *) * state_count); for (i = 0; i < state_count; i++) prefixtbl[i] = NULL; @@ -535,9 +532,9 @@ mktables(state_t * state, const char *defvalue, int useprefix) /* make the state transition tables */ - basetbl = (int *) malloc(sizeof(int) * state_count); - nexttbl = (int *) malloc(sizeof(int) * (state_count + char_count)); - checktbl = (int *) malloc(sizeof(int) * (state_count + char_count)); + basetbl = (int *)malloc(sizeof(int) * state_count); + nexttbl = (int *)malloc(sizeof(int) * (state_count + char_count)); + checktbl = (int *)malloc(sizeof(int) * (state_count + char_count)); for (i = 0; i < state_count; i++) { basetbl[i] = -1; @@ -568,7 +565,7 @@ rundfa(const char *buf, int length) end = buf + length; while (buf != end) { - ch = map[(int) *buf++]; + ch = map[(int)*buf++]; tmp = basetbl[state] + ch; if (checktbl[tmp] != state) @@ -580,7 +577,7 @@ rundfa(const char *buf, int length) } void -mkdfa(info_t * infos, int ninfos, int useprefix, int debug) +mkdfa(info_t *infos, int ninfos, int useprefix, int debug) { /* static const char *names[] = http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/signals.cc ---------------------------------------------------------------------- diff --git a/lib/ts/signals.cc b/lib/ts/signals.cc index 58676b3..ec11af3 100644 --- a/lib/ts/signals.cc +++ b/lib/ts/signals.cc @@ -34,7 +34,7 @@ bool signal_check_handler(int signal, signal_handler_t handler) { struct sigaction oact; - void * sigact; + void *sigact; ink_release_assert(sigaction(signal, NULL, &oact) == 0); if (handler == (signal_handler_t)SIG_DFL || handler == (signal_handler_t)SIG_IGN) { @@ -60,7 +60,7 @@ signal_check_handler(int signal, signal_handler_t handler) void check_signals(signal_handler_t handler) { - signal_check_handler(SIGPIPE, (signal_handler_t) SIG_IGN); + signal_check_handler(SIGPIPE, (signal_handler_t)SIG_IGN); signal_check_handler(SIGQUIT, handler); signal_check_handler(SIGHUP, handler); signal_check_handler(SIGTERM, handler); @@ -99,7 +99,7 @@ signal_reset_default(int signo) // certain the DEC pthreads SIGPIPE bug isn't back.. // static void * -check_signal_thread(void * ptr) +check_signal_thread(void *ptr) { signal_handler_t handler = (signal_handler_t)ptr; for (;;) { @@ -153,7 +153,7 @@ signal_is_crash(int signo) } void -signal_format_siginfo(int signo, siginfo_t * info, const char * msg) +signal_format_siginfo(int signo, siginfo_t *info, const char *msg) { (void)info; (void)signo; @@ -213,8 +213,7 @@ signal_register_default_handler(signal_handler_t handler) set_signal(SIGQUIT, handler); set_signal(SIGTERM, handler); - set_signal(SIGINT, handler); + set_signal(SIGINT, handler); set_signal(SIGUSR1, handler); set_signal(SIGUSR2, handler); - } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/signals.h ---------------------------------------------------------------------- diff --git a/lib/ts/signals.h b/lib/ts/signals.h index b94f30f..558a884 100644 --- a/lib/ts/signals.h +++ b/lib/ts/signals.h @@ -29,7 +29,7 @@ #ifndef __SIGNALS_H__ #define __SIGNALS_H__ -typedef void (*signal_handler_t)(int signo, siginfo_t * info, void * ctx); +typedef void (*signal_handler_t)(int signo, siginfo_t *info, void *ctx); // Default crash signal handler that dumps a stack trace and exits. void signal_crash_handler(int, siginfo_t *, void *); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_List.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_List.cc b/lib/ts/test_List.cc index fc736ac..86618b0 100644 --- a/lib/ts/test_List.cc +++ b/lib/ts/test_List.cc @@ -24,36 +24,43 @@ #include "List.h" -class Foo { public: +class Foo +{ +public: int x; - void foo() {} + void + foo() + { + } SLINK(Foo, slink); LINK(Foo, dlink); - Foo(int i = 0): x(i) {} + Foo(int i = 0) : x(i) {} }; -int main() { - SList(Foo,slink) s; - DList(Foo,dlink) d; - Que(Foo,dlink) q; - Foo *f = new Foo; - f->x = 7; - s.push(f); - d.push(s.pop()); - q.enqueue(d.pop()); - for (int i = 0; i < 100; i++) - q.enqueue(new Foo(i)); - int tot = 0; - for (int i = 0; i < 101; i++) - tot += q.dequeue()->x; - if (tot != 4957) { - printf("test_List FAILED\n"); - exit(1); - } else { - printf("test_List PASSED\n"); - exit(0); - } +int +main() +{ + SList(Foo, slink) s; + DList(Foo, dlink) d; + Que(Foo, dlink) q; + Foo *f = new Foo; + f->x = 7; + s.push(f); + d.push(s.pop()); + q.enqueue(d.pop()); + for (int i = 0; i < 100; i++) + q.enqueue(new Foo(i)); + int tot = 0; + for (int i = 0; i < 101; i++) + tot += q.dequeue()->x; + if (tot != 4957) { + printf("test_List FAILED\n"); + exit(1); + } else { + printf("test_List PASSED\n"); + exit(0); + } } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_Map.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_Map.cc b/lib/ts/test_Map.cc index 3824607..bb0c12c 100644 --- a/lib/ts/test_Map.cc +++ b/lib/ts/test_Map.cc @@ -33,8 +33,12 @@ struct Item { typedef Item Value; typedef DList(Item, m_link) ListHead; - static ID hash(Key key) { return key; } - static Key key(Value*); + static ID + hash(Key key) + { + return key; + } + static Key key(Value *); static bool equal(Key lhs, Key rhs); }; @@ -45,61 +49,75 @@ struct Item { Item(uint32_t key, uint32_t value) : _key(key), _value(value) {} }; -uint32_t Item::Hash::key(Value* v) { return v->_key; } -bool Item::Hash::equal(Key lhs, Key rhs) { return lhs == rhs; } +uint32_t +Item::Hash::key(Value *v) +{ + return v->_key; +} +bool +Item::Hash::equal(Key lhs, Key rhs) +{ + return lhs == rhs; +} typedef TSHashTable<Item::Hash> Table; -void test_TSHashTable() { +void +test_TSHashTable() +{ static uint32_t const N = 270; Table t; - Item* item; + Item *item; Table::Location loc; item = new Item(1); t.insert(item); - for ( uint32_t i = 2 ; i <= N ; ++i ) { + for (uint32_t i = 2; i <= N; ++i) { t.insert(new Item(i)); } - for ( uint32_t i = 1 ; i <= N ; ++i) { + for (uint32_t i = 1; i <= N; ++i) { Table::Location l = t.find(i); ink_assert(l.isValid()); ink_assert(i == l->_value); } - ink_assert(!(t.find(N*2).isValid())); + ink_assert(!(t.find(N * 2).isValid())); - loc = t.find(N/2 | 1); + loc = t.find(N / 2 | 1); if (loc) t.remove(loc); else - ink_assert(! "Did not find expected value"); + ink_assert(!"Did not find expected value"); - if (! loc) + if (!loc) ; // compiler check. - ink_assert(!(t.find(N/2 | 1).isValid())); + ink_assert(!(t.find(N / 2 | 1).isValid())); - for ( uint32_t i = 1 ; i <= N ; i += 2) { + for (uint32_t i = 1; i <= N; i += 2) { t.remove(i); } - for ( uint32_t i = 1 ; i <= N ; ++i) { + for (uint32_t i = 1; i <= N; ++i) { Table::Location l = t.find(i); - if (1 & i) ink_assert(! l.isValid()); - else ink_assert(l.isValid()); + if (1 & i) + ink_assert(!l.isValid()); + else + ink_assert(l.isValid()); } int n = 0; - for ( Table::iterator spot = t.begin(), limit = t.end() ; spot != limit ; ++spot ) { + for (Table::iterator spot = t.begin(), limit = t.end(); spot != limit; ++spot) { ++n; ink_assert((spot->_value & 1) == 0); } - ink_assert(n == N/2); + ink_assert(n == N / 2); } -int main(int /* argc ATS_UNUSED */, char **/*argv ATS_UNUSED */) { +int +main(int /* argc ATS_UNUSED */, char ** /*argv ATS_UNUSED */) +{ typedef Map<cchar *, cchar *> SSMap; typedef MapElem<cchar *, cchar *> SSMapElem; #define form_SSMap(_p, _v) form_Map(SSMapElem, _p, _v) @@ -108,17 +126,17 @@ int main(int /* argc ATS_UNUSED */, char **/*argv ATS_UNUSED */) { ssm.put("b", "B"); ssm.put("c", "C"); ssm.put("d", "D"); - form_SSMap(x, ssm) { /* nop */ } - -/* - if ((ssm).n) - for (SSMapElem *qq__x = (SSMapElem*)0, *x = &(ssm).v[0]; - ((intptr_t)(qq__x) < (ssm).n) && ((x = &(ssm).v[(intptr_t)qq__x]) || 1); - qq__x = (SSMapElem*)(((intptr_t)qq__x) + 1)) - if ((x)->key) { - // nop - } - */ + form_SSMap(x, ssm) { /* nop */} + + /* + if ((ssm).n) + for (SSMapElem *qq__x = (SSMapElem*)0, *x = &(ssm).v[0]; + ((intptr_t)(qq__x) < (ssm).n) && ((x = &(ssm).v[(intptr_t)qq__x]) || 1); + qq__x = (SSMapElem*)(((intptr_t)qq__x) + 1)) + if ((x)->key) { + // nop + } + */ StringChainHash<> h; cchar *hi = "hi", *ho = "ho", *hum = "hum", *hhi = "hhi"; @@ -197,4 +215,3 @@ int main(int /* argc ATS_UNUSED */, char **/*argv ATS_UNUSED */) { printf("test_Map PASSED\n"); } - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_Regex.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_Regex.cc b/lib/ts/test_Regex.cc index 8ed4323..792cdeb 100644 --- a/lib/ts/test_Regex.cc +++ b/lib/ts/test_Regex.cc @@ -34,17 +34,12 @@ typedef struct { } test_t; static const test_t test_data[] = { - {"^foo", {{"foo", true}, - {"bar", false}, - {"foobar", true}, - {"foobarbaz", true}}}, - {"foo$", {{"foo", true}, - {"bar", false}, - {"foobar", false}, - {"foobarbaz", false}}}, + {"^foo", {{"foo", true}, {"bar", false}, {"foobar", true}, {"foobarbaz", true}}}, + {"foo$", {{"foo", true}, {"bar", false}, {"foobar", false}, {"foobarbaz", false}}}, }; -static void test_basic() +static void +test_basic() { for (unsigned int i = 0; i < countof(test_data); i++) { Regex r; @@ -58,7 +53,8 @@ static void test_basic() } } -int main(int /* argc ATS_UNUSED */, char **/* argv ATS_UNUSED */) +int +main(int /* argc ATS_UNUSED */, char ** /* argv ATS_UNUSED */) { test_basic(); printf("test_Regex PASSED\n"); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_Vec.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_Vec.cc b/lib/ts/test_Vec.cc index f8693c1..2eb7cc6 100644 --- a/lib/ts/test_Vec.cc +++ b/lib/ts/test_Vec.cc @@ -27,7 +27,8 @@ #include <ink_assert.h> #include "Vec.h" -static void test_append() +static void +test_append() { static const char value[] = "this is a string"; unsigned int len = (int)sizeof(value) - 1; @@ -52,24 +53,25 @@ static void test_append() ink_assert(str.length() == 1000 * len); } -static void test_basic() +static void +test_basic() { Vec<void *> v, vv, vvv; int tt = 99 * 50, t = 0; for (size_t i = 0; i < 100; i++) - v.add((void*)(intptr_t)i); + v.add((void *)(intptr_t)i); for (size_t i = 0; i < 100; i++) t += (int)(intptr_t)v.v[i]; ink_assert(t == tt); t = 0; for (size_t i = 1; i < 100; i++) - vv.set_add((void*)(intptr_t)i); + vv.set_add((void *)(intptr_t)i); for (size_t i = 1; i < 100; i++) - vvv.set_add((void*)(intptr_t)i); + vvv.set_add((void *)(intptr_t)i); for (size_t i = 1; i < 100; i++) - vvv.set_add((void*)(intptr_t)(i * 1000)); + vvv.set_add((void *)(intptr_t)(i * 1000)); vv.set_union(vvv); for (size_t i = 0; i < vv.n; i++) if (vv.v[i]) @@ -80,7 +82,7 @@ static void test_basic() v.reserve(1000); t = 0; for (size_t i = 0; i < 1000; i++) - v.add((void*)(intptr_t)i); + v.add((void *)(intptr_t)i); for (size_t i = 0; i < 1000; i++) t += (int)(intptr_t)v.v[i]; ink_assert(t == 999 * 500); @@ -108,20 +110,21 @@ static void test_basic() UnionFind uf; uf.size(4); - uf.unify(0,1); - uf.unify(2,3); + uf.unify(0, 1); + uf.unify(2, 3); ink_assert(uf.find(2) == uf.find(3)); ink_assert(uf.find(0) == uf.find(1)); ink_assert(uf.find(0) != uf.find(3)); ink_assert(uf.find(1) != uf.find(3)); ink_assert(uf.find(1) != uf.find(2)); ink_assert(uf.find(0) != uf.find(2)); - uf.unify(1,2); + uf.unify(1, 2); ink_assert(uf.find(0) == uf.find(3)); ink_assert(uf.find(1) == uf.find(3)); } -int main(int /* argc ATS_UNUSED */, char **/* argv ATS_UNUSED */) +int +main(int /* argc ATS_UNUSED */, char ** /* argv ATS_UNUSED */) { test_append(); test_basic(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_arena.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_arena.cc b/lib/ts/test_arena.cc index e0d83b2..515a8bf 100644 --- a/lib/ts/test_arena.cc +++ b/lib/ts/test_arena.cc @@ -84,7 +84,7 @@ test_block_boundries() // Allocate and fill the array for (j = 0; j < regions_to_test; j++) { - test_regions[j] = (char *) a->alloc(test_size); + test_regions[j] = (char *)a->alloc(test_size); fill_test_data(test_regions[j], test_size, j); } @@ -106,7 +106,7 @@ test_block_boundries() a->reset(); } - delete[]test_regions; + delete[] test_regions; delete a; return failures; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_atomic.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_atomic.cc b/lib/ts/test_atomic.cc index ba95daf..932328a 100644 --- a/lib/ts/test_atomic.cc +++ b/lib/ts/test_atomic.cc @@ -43,7 +43,7 @@ volatile int al_done = 0; void * testalist(void *ame) { - int me = (int) (uintptr_t) ame; + int me = (int)(uintptr_t)ame; int j, k; for (k = 0; k < MAX_ALIST_ARRAY; k++) ink_atomiclist_push(&al[k % MAX_ALIST_TEST], &al_test[me][k]); @@ -51,21 +51,20 @@ testalist(void *ame) for (j = 0; j < 1000000; j++) if ((x = ink_atomiclist_pop(&al[me]))) ink_atomiclist_push(&al[rand() % MAX_ALIST_TEST], x); - ink_atomic_increment((int *) &al_done, 1); + ink_atomic_increment((int *)&al_done, 1); return NULL; } #endif // !LONG_ATOMICLIST_TEST #ifdef LONG_ATOMICLIST_TEST /************************************************************************/ -#define MAX_ATOMIC_LISTS (4 * 1024) -#define MAX_ITEMS_PER_LIST (1 * 1024) -#define MAX_TEST_THREADS 64 +#define MAX_ATOMIC_LISTS (4 * 1024) +#define MAX_ITEMS_PER_LIST (1 * 1024) +#define MAX_TEST_THREADS 64 static InkAtomicList alists[MAX_ATOMIC_LISTS]; struct listItem *items[MAX_ATOMIC_LISTS * MAX_ITEMS_PER_LIST]; -struct listItem -{ +struct listItem { int data1; int data2; void *link; @@ -83,11 +82,11 @@ init_data() struct listItem *plistItem; for (ali = 0; ali < MAX_ATOMIC_LISTS; ali++) - ink_atomiclist_init(&alists[ali], "alist", ((char *) &l.link - (char *) &l)); + ink_atomiclist_init(&alists[ali], "alist", ((char *)&l.link - (char *)&l)); for (ali = 0; ali < MAX_ATOMIC_LISTS; ali++) { for (j = 0; j < MAX_ITEMS_PER_LIST; j++) { - plistItem = (struct listItem *) malloc(sizeof(struct listItem)); + plistItem = (struct listItem *)malloc(sizeof(struct listItem)); items[ali + j] = plistItem; plistItem->data1 = ali + j; plistItem->data2 = ali + rand(); @@ -109,26 +108,26 @@ cycle_data(void *d) int iterations; int me; - me = (int) d; + me = (int)d; iterations = 0; while (1) { l = &alists[(me + rand()) % MAX_ATOMIC_LISTS]; - pli = (struct listItem *) ink_atomiclist_popall(l); + pli = (struct listItem *)ink_atomiclist_popall(l); if (!pli) continue; // Place listItems into random queues while (pli) { ink_assert((pli->data1 ^ pli->data2 ^ pli->data3 ^ pli->data4) == pli->check); - pli_next = (struct listItem *) pli->link; + pli_next = (struct listItem *)pli->link; pli->link = 0; - ink_atomiclist_push(&alists[(me + rand()) % MAX_ATOMIC_LISTS], (void *) pli); + ink_atomiclist_push(&alists[(me + rand()) % MAX_ATOMIC_LISTS], (void *)pli); pli = pli_next; } iterations++; - poll(0, 0, 10); // 10 msec delay + poll(0, 0, 10); // 10 msec delay if ((iterations % 100) == 0) printf("%d ", me); } @@ -138,13 +137,13 @@ cycle_data(void *d) #endif // LONG_ATOMICLIST_TEST int -main(int /* argc ATS_UNUSED */, const char */* argv ATS_UNUSED */[]) +main(int /* argc ATS_UNUSED */, const char * /* argv ATS_UNUSED */ []) { #ifndef LONG_ATOMICLIST_TEST int32_t m = 1, n = 100; - //int64 lm = 1LL, ln = 100LL; - const char* m2 = "hello"; - char* n2; + // int64 lm = 1LL, ln = 100LL; + const char *m2 = "hello"; + char *n2; printf("sizeof(int32_t)==%d sizeof(void *)==%d\n", (int)sizeof(int32_t), (int)sizeof(void *)); @@ -158,16 +157,16 @@ main(int /* argc ATS_UNUSED */, const char */* argv ATS_UNUSED */[]) printf("changed to: %d, result=%s\n", m, n ? "true" : "false"); printf("CAS pointer: '%s' == 'hello' then 'new'\n", m2); - n = ink_atomic_cas( &m2, "hello", "new"); - printf("changed to: %s, result=%s\n", m2, n ? (char *) "true" : (char *) "false"); + n = ink_atomic_cas(&m2, "hello", "new"); + printf("changed to: %s, result=%s\n", m2, n ? (char *)"true" : (char *)"false"); printf("CAS pointer: '%s' == 'hello' then 'new2'\n", m2); - n = ink_atomic_cas(&m2, m2, "new2"); + n = ink_atomic_cas(&m2, m2, "new2"); printf("changed to: %s, result=%s\n", m2, n ? "true" : "false"); n = 100; printf("Atomic Inc of %d\n", n); - m = ink_atomic_increment((int *) &n, 1); + m = ink_atomic_increment((int *)&n, 1); printf("changed to: %d, result=%d\n", n, m); @@ -205,11 +204,11 @@ main(int /* argc ATS_UNUSED */, const char */* argv ATS_UNUSED */[]) init_data(); for (id = 0; id < MAX_TEST_THREADS; id++) { - ink_assert(thr_create(NULL, 0, cycle_data, (void *) id, THR_NEW_LWP, NULL) == 0); + ink_assert(thr_create(NULL, 0, cycle_data, (void *)id, THR_NEW_LWP, NULL) == 0); } } while (1) { - poll(0, 0, 10); // 10 msec delay + poll(0, 0, 10); // 10 msec delay } #endif // LONG_ATOMICLIST_TEST http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_freelist.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_freelist.cc b/lib/ts/test_freelist.cc index 677da63..9d8e5b4 100644 --- a/lib/ts/test_freelist.cc +++ b/lib/ts/test_freelist.cc @@ -37,7 +37,7 @@ test(void *d) int id; void *m1, *m2, *m3; - id = (intptr_t) d; + id = (intptr_t)d; time_t start = time(NULL); int count = 0; @@ -47,8 +47,8 @@ test(void *d) m3 = ink_freelist_new(flist); if ((m1 == m2) || (m1 == m3) || (m2 == m3)) { - printf("0x%08" PRIx64 " 0x%08" PRIx64 " 0x%08" PRIx64 "\n", - (uint64_t)(uintptr_t)m1, (uint64_t)(uintptr_t)m2, (uint64_t)(uintptr_t)m3); + printf("0x%08" PRIx64 " 0x%08" PRIx64 " 0x%08" PRIx64 "\n", (uint64_t)(uintptr_t)m1, (uint64_t)(uintptr_t)m2, + (uint64_t)(uintptr_t)m3); exit(1); } @@ -65,12 +65,11 @@ test(void *d) return NULL; } } - } int -main(int /* argc ATS_UNUSED */, char */*argv ATS_UNUSED */[]) +main(int /* argc ATS_UNUSED */, char * /*argv ATS_UNUSED */ []) { int i; @@ -81,7 +80,7 @@ main(int /* argc ATS_UNUSED */, char */*argv ATS_UNUSED */[]) ink_thread_create(test, (void *)((intptr_t)i)); } - test((void *) NTHREADS); + test((void *)NTHREADS); return 0; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_geometry.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_geometry.cc b/lib/ts/test_geometry.cc index ffa01d7..ff14e4c 100644 --- a/lib/ts/test_geometry.cc +++ b/lib/ts/test_geometry.cc @@ -28,7 +28,8 @@ // geometry of an arbitrary device file. That's useful when figuring out how ATS will // perceive different devices on differen operating systems. -int main(int argc, const char ** argv) +int +main(int argc, const char **argv) { for (int i = 1; i < argc; ++i) { int fd; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_memchr.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_memchr.cc b/lib/ts/test_memchr.cc index 6f990fd..294207c 100644 --- a/lib/ts/test_memchr.cc +++ b/lib/ts/test_memchr.cc @@ -29,17 +29,17 @@ void * ink_memchr(const void *as, int ac, size_t an) { - unsigned char c = (unsigned char) ac; - unsigned char *s = (unsigned char *) as; + unsigned char c = (unsigned char)ac; + unsigned char *s = (unsigned char *)as; // initial segment - int i_len = (int)(((uintptr_t) 8 - (uintptr_t) as) & 7); + int i_len = (int)(((uintptr_t)8 - (uintptr_t)as) & 7); // too short to concern us - if ((int) an < i_len) { - for (int i = 0; i < (int) an; i++) + if ((int)an < i_len) { + for (int i = 0; i < (int)an; i++) if (s[i] == c) return &s[i]; return 0; @@ -67,7 +67,7 @@ ink_memchr(const void *as, int ac, size_t an) ib |= (ib << 16); unsigned int im = 0x7efefeff; if (i_len & 4) { - unsigned int ibp = *(unsigned int *) s; + unsigned int ibp = *(unsigned int *)s; unsigned int ibb = ibp ^ ib; ibb = ((ibb + im) ^ ~ibb) & ~im; if (ibb) { @@ -84,17 +84,17 @@ ink_memchr(const void *as, int ac, size_t an) } // next 8x bytes uint64_t m = 0x7efefefefefefeffLL; - uint64_t b = ((uint64_t) ib); + uint64_t b = ((uint64_t)ib); b |= (b << 32); - uint64_t *p = (uint64_t *) s; - unsigned int n = (((unsigned int) an) - (s - (unsigned char *) as)) >> 3; + uint64_t *p = (uint64_t *)s; + unsigned int n = (((unsigned int)an) - (s - (unsigned char *)as)) >> 3; uint64_t *end = p + n; while (p < end) { uint64_t bp = *p; uint64_t bb = bp ^ b; bb = ((bb + m) ^ ~bb) & ~m; if (bb) { - s = (unsigned char *) p; + s = (unsigned char *)p; if (s[0] == c) return &s[0]; if (s[1] == c) @@ -117,13 +117,13 @@ ink_memchr(const void *as, int ac, size_t an) // terminal segement - i_len = an - (((unsigned char *) p) - ((unsigned char *) as)); - s = (unsigned char *) p; + i_len = an - (((unsigned char *)p) - ((unsigned char *)as)); + s = (unsigned char *)p; // n-(4..8)..n bytes if (i_len & 4) { - unsigned int ibp = *(unsigned int *) s; + unsigned int ibp = *(unsigned int *)s; unsigned int ibb = ibp ^ ib; ibb = ((ibb + im) ^ ~ibb) & ~im; if (ibb) { @@ -157,7 +157,7 @@ ink_memchr(const void *as, int ac, size_t an) } -#define MEMCHR(_s,_c) ink_memchr(_s,_c,strlen(_s))?:"" +#define MEMCHR(_s, _c) ink_memchr(_s, _c, strlen(_s)) ?: "" main() { int i = 0; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/test_strings.cc ---------------------------------------------------------------------- diff --git a/lib/ts/test_strings.cc b/lib/ts/test_strings.cc index d78742e..ac32b5b 100644 --- a/lib/ts/test_strings.cc +++ b/lib/ts/test_strings.cc @@ -53,76 +53,70 @@ clock_t start, stop; void *ink_memchr(const void *as, int ac, size_t an); -#define STRLEN_TEST(_func_,_size_) \ -{ \ - start = clock(); \ - for (i = 0; i < cycles; i++) { \ - iresult = _func_ (_size_); \ - } \ - stop = clock(); \ - printf ("%20s\t%10s\t%1.03g usec/op\n", \ - #_func_, #_size_, ((double)stop-start)/((double)cycles)); \ -} +#define STRLEN_TEST(_func_, _size_) \ + { \ + start = clock(); \ + for (i = 0; i < cycles; i++) { \ + iresult = _func_(_size_); \ + } \ + stop = clock(); \ + printf("%20s\t%10s\t%1.03g usec/op\n", #_func_, #_size_, ((double)stop - start) / ((double)cycles)); \ + } -#define STRCHR_TEST(_func_,_size_,_chr_) \ -{ \ - start = clock(); \ - for (i = 0; i < cycles; i++) { \ - sresult = _func_ (_size_,_chr_); \ - } \ - stop = clock(); \ - printf ("%20s\t%10s\t%1.03g usec/op\t%s\n", \ - #_func_, #_size_, ((double)stop-start)/((double)cycles), \ - (sresult)? "found" : "not found"); \ -} +#define STRCHR_TEST(_func_, _size_, _chr_) \ + { \ + start = clock(); \ + for (i = 0; i < cycles; i++) { \ + sresult = _func_(_size_, _chr_); \ + } \ + stop = clock(); \ + printf("%20s\t%10s\t%1.03g usec/op\t%s\n", #_func_, #_size_, ((double)stop - start) / ((double)cycles), \ + (sresult) ? "found" : "not found"); \ + } -#define JP_MEMCHR_TEST(_func_,_size_,_chr_,_len_) \ -{ \ - start = clock(); \ - for (i = 0; i < cycles; i++) { \ - sresult = (char*) ink_memchr (_size_,_chr_,_len_); \ - } \ - stop = clock(); \ - printf ("%20s\t%10s\t%1.03g usec/op\t%s\n", \ - "jp_memchr", #_size_, ((double)stop-start)/((double)cycles), \ - (sresult)? "found" : "not found"); \ -} +#define JP_MEMCHR_TEST(_func_, _size_, _chr_, _len_) \ + { \ + start = clock(); \ + for (i = 0; i < cycles; i++) { \ + sresult = (char *)ink_memchr(_size_, _chr_, _len_); \ + } \ + stop = clock(); \ + printf("%20s\t%10s\t%1.03g usec/op\t%s\n", "jp_memchr", #_size_, ((double)stop - start) / ((double)cycles), \ + (sresult) ? "found" : "not found"); \ + } -#define STRCMP_TEST(_func_,_size_,_str_) \ -{ \ - start = clock(); \ - for (i = 0; i < cycles; i++) { \ - iresult = _func_ (_size_,_str_); \ - } \ - stop = clock(); \ - printf ("%20s\t%10s\t%1.03g usec/op\t%s\n", \ - #_func_, #_size_, ((double)stop-start)/((double)cycles), \ - (sresult)? "not matching" : "matching"); \ -} +#define STRCMP_TEST(_func_, _size_, _str_) \ + { \ + start = clock(); \ + for (i = 0; i < cycles; i++) { \ + iresult = _func_(_size_, _str_); \ + } \ + stop = clock(); \ + printf("%20s\t%10s\t%1.03g usec/op\t%s\n", #_func_, #_size_, ((double)stop - start) / ((double)cycles), \ + (sresult) ? "not matching" : "matching"); \ + } -#define STRCPY_TEST(_func_,_size_) \ -{ \ - char buf[1024]; \ - start = clock(); \ - for (i = 0; i < cycles; i++) { \ - sresult = _func_ (buf,_size_); \ - } \ - stop = clock(); \ - printf ("%20s\t%10s\t%1.03g usec/op\n", \ - #_func_, #_size_, ((double)stop-start)/((double)cycles)); \ -} +#define STRCPY_TEST(_func_, _size_) \ + { \ + char buf[1024]; \ + start = clock(); \ + for (i = 0; i < cycles; i++) { \ + sresult = _func_(buf, _size_); \ + } \ + stop = clock(); \ + printf("%20s\t%10s\t%1.03g usec/op\n", #_func_, #_size_, ((double)stop - start) / ((double)cycles)); \ + } -#define MEMCPY_TEST(_func_,_size_,_len_) \ -{ \ - char buf[1024]; \ - start = clock(); \ - for (i = 0; i < cycles; i++) { \ - sresult = (char*) _func_ (buf,_size_,_len_); \ - } \ - stop = clock(); \ - printf ("%20s\t%10s\t%10s\t%1.03g usec/op\n", \ - #_func_, #_size_, #_len_, ((double)stop-start)/((double)cycles)); \ -} +#define MEMCPY_TEST(_func_, _size_, _len_) \ + { \ + char buf[1024]; \ + start = clock(); \ + for (i = 0; i < cycles; i++) { \ + sresult = (char *)_func_(buf, _size_, _len_); \ + } \ + stop = clock(); \ + printf("%20s\t%10s\t%10s\t%1.03g usec/op\n", #_func_, #_size_, #_len_, ((double)stop - start) / ((double)cycles)); \ + } /* version from ink_string.h */ inline char * @@ -149,7 +143,7 @@ ink_memcpy(char *d, char *s, int len) inline char * jp_strchr(char *s, char c) { - return (char *) ink_memchr(s, c, strlen(s)); + return (char *)ink_memchr(s, c, strlen(s)); } void @@ -251,17 +245,17 @@ main(int argc, char *argv[]) void * ink_memchr(const void *as, int ac, size_t an) { - unsigned char c = (unsigned char) ac; - unsigned char *s = (unsigned char *) as; + unsigned char c = (unsigned char)ac; + unsigned char *s = (unsigned char *)as; // initial segment - int i_len = (int)(((uintptr_t) 8 - (uintptr_t) as) & 7); + int i_len = (int)(((uintptr_t)8 - (uintptr_t)as) & 7); // too short to concern us - if ((int) an < i_len) { - for (int i = 0; i < (int) an; i++) + if ((int)an < i_len) { + for (int i = 0; i < (int)an; i++) if (s[i] == c) return &s[i]; return 0; @@ -289,7 +283,7 @@ ink_memchr(const void *as, int ac, size_t an) ib |= (ib << 16); unsigned int im = 0x7efefeff; if (i_len & 4) { - unsigned int ibp = *(unsigned int *) s; + unsigned int ibp = *(unsigned int *)s; unsigned int ibb = ibp ^ ib; ibb = ((ibb + im) ^ ~ibb) & ~im; if (ibb) { @@ -306,17 +300,17 @@ ink_memchr(const void *as, int ac, size_t an) } // next 8x bytes uint64_t m = 0x7efefefefefefeffLL; - uint64_t b = ((uint64_t) ib); + uint64_t b = ((uint64_t)ib); b |= (b << 32); - uint64_t *p = (uint64_t *) s; - unsigned int n = (((unsigned int) an) - (s - (unsigned char *) as)) >> 3; + uint64_t *p = (uint64_t *)s; + unsigned int n = (((unsigned int)an) - (s - (unsigned char *)as)) >> 3; uint64_t *end = p + n; while (p < end) { uint64_t bp = *p; uint64_t bb = bp ^ b; bb = ((bb + m) ^ ~bb) & ~m; if (bb) { - s = (unsigned char *) p; + s = (unsigned char *)p; if (s[0] == c) return &s[0]; if (s[1] == c) @@ -339,13 +333,13 @@ ink_memchr(const void *as, int ac, size_t an) // terminal segement - i_len = an - (((unsigned char *) p) - ((unsigned char *) as)); - s = (unsigned char *) p; + i_len = an - (((unsigned char *)p) - ((unsigned char *)as)); + s = (unsigned char *)p; // n-(4..8)..n bytes if (i_len & 4) { - unsigned int ibp = *(unsigned int *) s; + unsigned int ibp = *(unsigned int *)s; unsigned int ibb = ibp ^ ib; ibb = ((ibb + im) ^ ~ibb) & ~im; if (ibb) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/wccp/Wccp.h ---------------------------------------------------------------------- diff --git a/lib/wccp/Wccp.h b/lib/wccp/Wccp.h index cfe99c7..8dd92d7 100644 --- a/lib/wccp/Wccp.h +++ b/lib/wccp/Wccp.h @@ -1,5 +1,5 @@ -# if ! defined(ATS_WCCP_API_HEADER) -# define ATS_WCCP_API_HEADER +#if !defined(ATS_WCCP_API_HEADER) +#define ATS_WCCP_API_HEADER /** @file WCCP (v2) support API. @@ -23,33 +23,36 @@ limitations under the License. */ -# include <ts/TsBuffer.h> -# include <tsconfig/Errata.h> -# include <memory.h> -# include <ink_defs.h> -# include <ink_memory.h> +#include <ts/TsBuffer.h> +#include <tsconfig/Errata.h> +#include <memory.h> +#include <ink_defs.h> +#include <ink_memory.h> // Nasty, defining this with no prefix. The value is still available // in TS_VERSION_STRING. -# undef VERSION +#undef VERSION // INADDR_ANY -# include <netinet/in.h> +#include <netinet/in.h> /// WCCP Support. -namespace wccp { - +namespace wccp +{ /// Forward declare implementation classes. class Impl; class CacheImpl; class RouterImpl; /// Namespace for implementation details. -namespace detail { +namespace detail +{ /// Cache implementation details. - namespace cache { + namespace cache + { struct GroupData; } - namespace router { + namespace router + { struct GroupData; } } @@ -58,7 +61,7 @@ namespace detail { /// @note Sec 4.14: HERE_I_AM_T. static time_t const TIME_UNIT = 10; static time_t const ASSIGN_WAIT = (3 * TIME_UNIT) / 2; -static time_t const RAPID_TIME = TIME_UNIT/10; +static time_t const RAPID_TIME = TIME_UNIT / 10; /// Service group related constants. /// @internal In a struct so enum values can be imported to more than @@ -68,18 +71,18 @@ struct ServiceConstants { /// @internal Enumerations values match protocol values. enum PacketStyle { NO_PACKET_STYLE = 0, ///< Undefined or invalid. - GRE = 1, ///< GRE tunnel only. [default] - L2 = 2, ///< L2 rewrite only. - GRE_OR_L2 = 3 ///< L2 rewrite or GRE tunnel. + GRE = 1, ///< GRE tunnel only. [default] + L2 = 2, ///< L2 rewrite only. + GRE_OR_L2 = 3 ///< L2 rewrite or GRE tunnel. }; /// Cache assignment supported methods. /// @internal Enumerations values match protocol values. enum CacheAssignmentStyle { NO_CACHE_ASSIGN_STYLE = 0, ///< Undefined or invalid. - HASH_ONLY = 1, ///< Use only hash assignment. [default] - MASK_ONLY = 2, ///< Use only mask assignment. - HASH_OR_MASK = 3 ///< Use hash or mask assignment. + HASH_ONLY = 1, ///< Use only hash assignment. [default] + MASK_ONLY = 2, ///< Use only mask assignment. + HASH_OR_MASK = 3 ///< Use hash or mask assignment. }; }; @@ -89,20 +92,21 @@ struct ServiceConstants { in serialized form because it is copied to and from message data far more often then it is accessed directly. */ -class ServiceGroup : public ServiceConstants { +class ServiceGroup : public ServiceConstants +{ public: typedef ServiceGroup self; ///< Self reference type. /// Type of service. enum Type { STANDARD = 0, ///< Well known service. - DYNAMIC = 1 ///< Dynamic (locally defined) service. + DYNAMIC = 1 ///< Dynamic (locally defined) service. }; /// Result codes for service definition. enum Result { DEFINED = 0, ///< Service group was created by the call. - EXISTS = 1, ///< Service group already existed. + EXISTS = 1, ///< Service group already existed. CONFLICT = 2 ///< Service group existed but didn't match new definition. }; @@ -120,96 +124,93 @@ public: /// @name Flag mask values. //@{ /// Source IP address hash - static uint32_t const SRC_IP_HASH = 1<<0; + static uint32_t const SRC_IP_HASH = 1 << 0; /// Destination IP address hash - static uint32_t const DST_IP_HASH = 1<<1; + static uint32_t const DST_IP_HASH = 1 << 1; /// Source port hash. - static uint32_t const SRC_PORT_HASH = 1<<2; + static uint32_t const SRC_PORT_HASH = 1 << 2; /// Destination port hash - static uint32_t const DST_PORT_HASH = 1<<3; + static uint32_t const DST_PORT_HASH = 1 << 3; /// @a m_ports has port information. - static uint32_t const PORTS_DEFINED = 1<<4; + static uint32_t const PORTS_DEFINED = 1 << 4; /// @a m_ports has source ports (otherwise destination ports). - static uint32_t const PORTS_SOURCE = 1<<5; + static uint32_t const PORTS_SOURCE = 1 << 5; /// Alternate source IP address hash - static uint32_t const SRC_IP_ALT_HASH = 1<<8; + static uint32_t const SRC_IP_ALT_HASH = 1 << 8; /// Alternate destination IP address hash - static uint32_t const DST_IP_ALT_HASH = 1<<9; + static uint32_t const DST_IP_ALT_HASH = 1 << 9; /// Alternate source port hash - static uint32_t const SRC_PORT_ALT_HASH = 1<<10; + static uint32_t const SRC_PORT_ALT_HASH = 1 << 10; /// Alternate destination port hash - static uint32_t const DST_PORT_ALT_HASH = 1<<11; + static uint32_t const DST_PORT_ALT_HASH = 1 << 11; /// All hash related flags. - static uint32_t const HASH_FLAGS = - SRC_IP_HASH | DST_IP_HASH | SRC_PORT_HASH | DST_PORT_HASH - | SRC_IP_ALT_HASH | DST_IP_ALT_HASH | SRC_PORT_ALT_HASH | DST_PORT_ALT_HASH - ; + static uint32_t const HASH_FLAGS = SRC_IP_HASH | DST_IP_HASH | SRC_PORT_HASH | DST_PORT_HASH | SRC_IP_ALT_HASH | DST_IP_ALT_HASH | + SRC_PORT_ALT_HASH | DST_PORT_ALT_HASH; //@} /// Default constructor - no member initialization. ServiceGroup(); /// Test for equivalent. - bool operator == (self const& that) const; + bool operator==(self const &that) const; /// Test for not equivalent. - bool operator != (self const& that) const; + bool operator!=(self const &that) const; /// @name Accessors //@{ ServiceGroup::Type getSvcType() const; ///< Get service type field. - /** Set the service type. - If @a svc is @c SERVICE_STANDARD then all fields except the - component header and service id are set to zero as required - by the protocol. - */ - self& setSvcType(ServiceGroup::Type svc); + /** Set the service type. + If @a svc is @c SERVICE_STANDARD then all fields except the + component header and service id are set to zero as required + by the protocol. + */ + self &setSvcType(ServiceGroup::Type svc); - uint8_t getSvcId() const; ///< Get service ID field. - self& setSvcId(uint8_t id); ///< Set service ID field to @a id. + uint8_t getSvcId() const; ///< Get service ID field. + self &setSvcId(uint8_t id); ///< Set service ID field to @a id. - uint8_t getPriority() const; ///< Get priority field. - self& setPriority(uint8_t pri); ///< Set priority field to @a p. + uint8_t getPriority() const; ///< Get priority field. + self &setPriority(uint8_t pri); ///< Set priority field to @a p. - uint8_t getProtocol() const; ///< Get protocol field. - self& setProtocol(uint8_t p); ///< Set protocol field to @a p. + uint8_t getProtocol() const; ///< Get protocol field. + self &setProtocol(uint8_t p); ///< Set protocol field to @a p. - uint32_t getFlags() const; ///< Get flags field. - self& setFlags(uint32_t f); ///< Set the flags flags in field to @a f. + uint32_t getFlags() const; ///< Get flags field. + self &setFlags(uint32_t f); ///< Set the flags flags in field to @a f. /// Set the flags in the flag field that are set in @a f. /// Other flags are unchanged. - self& enableFlags(uint32_t f); + self &enableFlags(uint32_t f); /// Clear the flags in the flag field that are set in @a f. /// Other flags are unchanged. - self& disableFlags(uint32_t f); + self &disableFlags(uint32_t f); /// Get a port value. - uint16_t getPort( - int idx ///< Index of target port. - ) const; + uint16_t getPort(int idx ///< Index of target port. + ) const; /// Set a port value. - self& setPort( - int idx, ///< Index of port. - uint16_t port ///< Value for port. - ); + self &setPort(int idx, ///< Index of port. + uint16_t port ///< Value for port. + ); /// Zero (clear) all ports. - self& clearPorts(); + self &clearPorts(); //@} protected: - uint8_t m_svc_type; ///< @ref Type. - uint8_t m_svc_id; ///< ID for service type. - uint8_t m_priority; ///< Redirection priority ordering. - uint8_t m_protocol; ///< IP protocol for service. - uint32_t m_flags; ///< Flags. + uint8_t m_svc_type; ///< @ref Type. + uint8_t m_svc_id; ///< ID for service type. + uint8_t m_priority; ///< Redirection priority ordering. + uint8_t m_protocol; ///< IP protocol for service. + uint32_t m_flags; ///< Flags. uint16_t m_ports[N_PORTS]; ///< Service ports. }; /// Security component option (sub-type) enum SecurityOption { SECURITY_NONE = 0, ///< No security @c WCCP2_NO_SECURITY - SECURITY_MD5 = 1 ///< MD5 security @c WCCP2_MD5_SECURITY + SECURITY_MD5 = 1 ///< MD5 security @c WCCP2_MD5_SECURITY }; -class EndPoint { +class EndPoint +{ public: typedef EndPoint self; ///< Self reference type. typedef Impl ImplType; ///< Implementation type. @@ -217,9 +218,8 @@ public: /** Set the identifying IP address. This is also used as the address for the socket. */ - self& setAddr( - uint32_t addr ///< IP address. - ); + self &setAddr(uint32_t addr ///< IP address. + ); /** Check if this endpoint is ready to use. @return @c true if the address has been set and services @@ -238,9 +238,8 @@ public: @return 0 on success, -ERRNO on failure. @see setAddr */ - int open( - uint32_t addr = INADDR_ANY ///< Local IP address for socket. - ); + int open(uint32_t addr = INADDR_ANY ///< Local IP address for socket. + ); /// Get the internal socket. /// Useful primarily for socket options and using @@ -248,13 +247,11 @@ public: int getSocket() const; /// Use MD5 based security with @a key. - void useMD5Security( - char const* key ///< Shared hash key. - ); + void useMD5Security(char const *key ///< Shared hash key. + ); /// Use MD5 based security with @a key. - void useMD5Security( - ts::ConstBuffer const& key ///< Shared hash key. - ); + void useMD5Security(ts::ConstBuffer const &key ///< Shared hash key. + ); /// Perform house keeping, including sending outbound messages. int housekeeping(); @@ -267,7 +264,7 @@ protected: /// Default constructor. EndPoint(); /// Copy constructor. - EndPoint(self const& that); + EndPoint(self const &that); /// Force virtual destructor virtual ~EndPoint(); @@ -279,15 +276,16 @@ protected: implementation instantiation to be virtual so the correct type is created. */ - ImplType* instance(); + ImplType *instance(); - virtual ImplType* make() = 0; ///< Create a new implementation instance. + virtual ImplType *make() = 0; ///< Create a new implementation instance. }; -class Cache : public EndPoint { +class Cache : public EndPoint +{ public: - typedef Cache self; ///< Self reference type. - typedef EndPoint super; ///< Parent type. + typedef Cache self; ///< Self reference type. + typedef EndPoint super; ///< Parent type. typedef CacheImpl ImplType; ///< Implementation type. class Service; @@ -298,9 +296,8 @@ public: ~Cache(); /// Define services from a configuration file. - ts::Errata loadServicesFromFile( - char const* path ///< Path to file. - ); + ts::Errata loadServicesFromFile(char const *path ///< Path to file. + ); /** Define a service group. @@ -311,10 +308,8 @@ public: - @c ServiceGroup::EXISTS if the service matches the existing service. - @c ServiceGroup::CONFLICT if the service doesn't match the existing service. */ - Service defineServiceGroup( - ServiceGroup const& svc, ///< Service group description. - ServiceGroup::Result* result = 0 - ); + Service defineServiceGroup(ServiceGroup const &svc, ///< Service group description. + ServiceGroup::Result *result = 0); /** Add a seed router to the service group. @@ -326,29 +321,30 @@ public: Seed routers are removed when a reply is received from that router. */ - self& addSeedRouter( - uint8_t id, ///< Service group ID. - uint32_t addr ///< IP address of router. - ); + self &addSeedRouter(uint8_t id, ///< Service group ID. + uint32_t addr ///< IP address of router. + ); /// Number of seconds until next housekeeping activity is due. time_t waitTime() const; + protected: /// Get implementation instance, creating if needed. - ImplType* instance(); + ImplType *instance(); /// Get the current implementation instance cast to correct type. - ImplType* impl(); + ImplType *impl(); /// Get the current implementation instance cast to correct type. - ImplType const* impl() const; + ImplType const *impl() const; /// Create a new implementation instance. - super::ImplType* make(); + super::ImplType *make(); }; /** Hold a reference to a service group in this end point. This is useful when multiple operations are to be done on the same group, rather than doing a lookup by id every time. */ -class Cache::Service : public ServiceConstants { +class Cache::Service : public ServiceConstants +{ public: typedef Service self; ///< Self reference type. @@ -356,44 +352,39 @@ public: Service(); /// Add an address for a seed router. - self& addSeedRouter( - uint32_t addr ///< Router IP address. - ); + self &addSeedRouter(uint32_t addr ///< Router IP address. + ); /// Set the security key. - self& setKey( - char const* key /// Shared key. - ); + self &setKey(char const *key /// Shared key. + ); /// Set the service local security option. - self& setSecurity( - SecurityOption opt ///< Security style to use. - ); + self &setSecurity(SecurityOption opt ///< Security style to use. + ); /// Set intercepted packet forwarding style. - self& setForwarding( - PacketStyle style ///< Type of forwarding supported. - ); + self &setForwarding(PacketStyle style ///< Type of forwarding supported. + ); /// Enable or disable packet return by layer 2 rewrite. - self& setReturn( - PacketStyle style ///< Type of return supported. - ); + self &setReturn(PacketStyle style ///< Type of return supported. + ); /// Set cache assignment style. - self& setCacheAssignment( - CacheAssignmentStyle style ///< Style to use. - ); + self &setCacheAssignment(CacheAssignmentStyle style ///< Style to use. + ); private: - Service(Cache const& cache, detail::cache::GroupData& group); - Cache m_cache; ///< Parent cache. - detail::cache::GroupData* m_group; ///< Service Group data. + Service(Cache const &cache, detail::cache::GroupData &group); + Cache m_cache; ///< Parent cache. + detail::cache::GroupData *m_group; ///< Service Group data. friend class Cache; }; -class Router : public EndPoint { +class Router : public EndPoint +{ public: - typedef Router self; ///< Self reference type. - typedef EndPoint super; ///< Parent type. + typedef Router self; ///< Self reference type. + typedef EndPoint super; ///< Parent type. typedef RouterImpl ImplType; ///< Implementation type. /// Default constructor @@ -403,110 +394,127 @@ public: /// Transmit pending messages. int sendPendingMessages(); + protected: /// Get implementation instance, creating if needed. - ImplType* instance(); + ImplType *instance(); /// Get the current implementation instance cast to correct type. - ImplType* impl(); + ImplType *impl(); /// Create a new implementation instance. - super::ImplType* make(); + super::ImplType *make(); }; // ------------------------------------------------------ -inline bool -ServiceGroup::operator != (self const& that) const { +inline bool ServiceGroup::operator!=(self const &that) const +{ return !(*this == that); } inline ServiceGroup::Type -ServiceGroup::getSvcType() const { +ServiceGroup::getSvcType() const +{ return static_cast<ServiceGroup::Type>(m_svc_type); } inline uint8_t -ServiceGroup::getSvcId() const { +ServiceGroup::getSvcId() const +{ return m_svc_id; } -inline ServiceGroup& -ServiceGroup::setSvcId(uint8_t id) { +inline ServiceGroup & +ServiceGroup::setSvcId(uint8_t id) +{ m_svc_id = id; return *this; } inline uint8_t -ServiceGroup::getPriority() const { +ServiceGroup::getPriority() const +{ return m_priority; } -inline ServiceGroup& -ServiceGroup::setPriority(uint8_t pri) { +inline ServiceGroup & +ServiceGroup::setPriority(uint8_t pri) +{ m_priority = pri; return *this; } inline uint8_t -ServiceGroup::getProtocol() const { +ServiceGroup::getProtocol() const +{ return m_protocol; } -inline ServiceGroup& -ServiceGroup::setProtocol(uint8_t proto) { +inline ServiceGroup & +ServiceGroup::setProtocol(uint8_t proto) +{ m_protocol = proto; return *this; } inline uint32_t -ServiceGroup::getFlags() const { +ServiceGroup::getFlags() const +{ return ntohl(m_flags); } -inline ServiceGroup& -ServiceGroup::setFlags(uint32_t flags) { +inline ServiceGroup & +ServiceGroup::setFlags(uint32_t flags) +{ m_flags = htonl(flags); return *this; } -inline ServiceGroup& -ServiceGroup::enableFlags(uint32_t flags) { +inline ServiceGroup & +ServiceGroup::enableFlags(uint32_t flags) +{ m_flags |= htonl(flags); return *this; } -inline ServiceGroup& -ServiceGroup::disableFlags(uint32_t flags) { +inline ServiceGroup & +ServiceGroup::disableFlags(uint32_t flags) +{ m_flags &= ~htonl(flags); return *this; } inline uint16_t -ServiceGroup::getPort (int idx) const { +ServiceGroup::getPort(int idx) const +{ return ntohs(m_ports[idx]); } -inline ServiceGroup& -ServiceGroup::setPort(int idx, uint16_t port) { +inline ServiceGroup & +ServiceGroup::setPort(int idx, uint16_t port) +{ m_ports[idx] = htons(port); return *this; } -inline ServiceGroup& -ServiceGroup::clearPorts() { +inline ServiceGroup & +ServiceGroup::clearPorts() +{ memset(m_ports, 0, sizeof(m_ports)); return *this; } -inline Cache::Service::Service() : m_group(0) { } +inline Cache::Service::Service() : m_group(0) +{ +} -inline Cache::Service::Service( - Cache const& cache, - detail::cache::GroupData& group -) : m_cache(cache), m_group(&group) { +inline Cache::Service::Service(Cache const &cache, detail::cache::GroupData &group) : m_cache(cache), m_group(&group) +{ } -inline void EndPoint::useMD5Security(char const* key) { +inline void +EndPoint::useMD5Security(char const *key) +{ this->useMD5Security(ts::ConstBuffer(key, strlen(key))); } // ------------------------------------------------------ } // namespace Wccp -# endif // include guard. +#endif // include guard.
