diff options
author | Dan Albert <danalbert@google.com> | 2015-02-20 17:24:58 -0800 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2015-02-25 10:57:26 -0800 |
commit | 055f1aa4ff58ba71133d506b202ad46612758ded (patch) | |
tree | 8999da4097ad2888a50ea3d3e65e08ff042f8ca7 /adb/transport.c | |
parent | d75d6c91d24c071534ed36db85a1e72b33dc5a10 (diff) | |
download | system_core-055f1aa4ff58ba71133d506b202ad46612758ded.zip system_core-055f1aa4ff58ba71133d506b202ad46612758ded.tar.gz system_core-055f1aa4ff58ba71133d506b202ad46612758ded.tar.bz2 |
Add some basic tests to adb.
Change-Id: I946b5b1e5650540db3b4f75892214c4218b3baf3
Diffstat (limited to 'adb/transport.c')
-rw-r--r-- | adb/transport.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/adb/transport.c b/adb/transport.c index 4904cd0..1951595 100644 --- a/adb/transport.c +++ b/adb/transport.c @@ -18,6 +18,7 @@ #include "transport.h" +#include <ctype.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -69,8 +70,7 @@ static void dump_hex( const unsigned char* ptr, size_t len ) } #endif -void -kick_transport(atransport* t) +void kick_transport(atransport* t) { if (t && !t->kicked) { @@ -87,8 +87,25 @@ kick_transport(atransport* t) } } -void -run_transport_disconnects(atransport* t) +// Each atransport contains a list of adisconnects (t->disconnects). +// An adisconnect contains a link to the next/prev adisconnect, a function +// pointer to a disconnect callback which takes a void* piece of user data and +// the atransport, and some user data for the callback (helpfully named +// "opaque"). +// +// The list is circular. New items are added to the entry member of the list +// (t->disconnects) by add_transport_disconnect. +// +// run_transport_disconnects invokes each function in the list. +// +// Gotchas: +// * run_transport_disconnects assumes that t->disconnects is non-null, so +// this can't be run on a zeroed atransport. +// * The callbacks in this list are not removed when called, and this function +// is not guarded against running more than once. As such, ensure that this +// function is not called multiple times on the same atransport. +// TODO(danalbert): Just fix this so that it is guarded once you have tests. +void run_transport_disconnects(atransport* t) { adisconnect* dis = t->disconnects.next; @@ -753,17 +770,6 @@ void remove_transport_disconnect(atransport* t, adisconnect* dis) dis->next = dis->prev = dis; } -static int qual_char_is_invalid(char ch) -{ - if ('A' <= ch && ch <= 'Z') - return 0; - if ('a' <= ch && ch <= 'z') - return 0; - if ('0' <= ch && ch <= '9') - return 0; - return 1; -} - static int qual_match(const char *to_test, const char *prefix, const char *qual, int sanitize_qual) { @@ -783,7 +789,7 @@ static int qual_match(const char *to_test, while (*qual) { char ch = *qual++; - if (sanitize_qual && qual_char_is_invalid(ch)) + if (sanitize_qual && isalnum(ch)) ch = '_'; if (ch != *to_test++) return 0; @@ -923,7 +929,7 @@ static void add_qual(char **buf, size_t *buf_size, if (sanitize_qual) { char *cp; for (cp = *buf + prefix_len; cp < *buf + len; cp++) { - if (qual_char_is_invalid(*cp)) + if (isalnum(*cp)) *cp = '_'; } } |