function_name
stringlengths
1
80
function
stringlengths
14
10.6k
comment
stringlengths
12
8.02k
normalized_comment
stringlengths
6
6.55k
ParsePacketTAGVLAN
bool ParsePacketTAGVLAN(PKT *p, UCHAR *buf, UINT size) { USHORT vlan_ushort; // Validate arguments if (p == NULL || buf == NULL) { return false; } // Check the size if (size < sizeof(TAGVLAN_HEADER)) { return false; } // TAG VLAN header p->L3.TagVlanHeader = (TAGVLAN_HEADER *)buf; p->TypeL3 = L3_TAGVLAN; buf += sizeof(TAGVLAN_HEADER); size -= sizeof(TAGVLAN_HEADER); vlan_ushort = READ_USHORT(p->L3.TagVlanHeader->Data); vlan_ushort = vlan_ushort & 0xFFF; p->VlanId = vlan_ushort; return true; }
/* TAG VLAN parsing*/
TAG VLAN parsing
FreeCloneICMPv6Options
void FreeCloneICMPv6Options(ICMPV6_OPTION_LIST *o) { // Validate arguments if (o == NULL) { return; } Free(o->SourceLinkLayer); Free(o->TargetLinkLayer); Free(o->Prefix); Free(o->Mtu); }
/* Release of the ICMPv6 options*/
Release of the ICMPv6 options
CloneICMPv6Options
void CloneICMPv6Options(ICMPV6_OPTION_LIST *dst, ICMPV6_OPTION_LIST *src) { // Validate arguments if (dst == NULL || src == NULL) { return; } Zero(dst, sizeof(ICMPV6_OPTION_LIST)); dst->SourceLinkLayer = Clone(src->SourceLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER)); dst->TargetLinkLayer = Clone(src->TargetLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER)); dst->Prefix = Clone(src->Prefix, sizeof(ICMPV6_OPTION_PREFIX)); dst->Mtu = Clone(src->Mtu, sizeof(ICMPV6_OPTION_MTU)); }
/* Clone of the ICMPv6 options*/
Clone of the ICMPv6 options
ParsePacketIPv4WithDummyMacHeader
PKT *ParsePacketIPv4WithDummyMacHeader(UCHAR *buf, UINT size) { UCHAR *tmp; UINT tmp_size; PKT *ret; // Validate arguments if (buf == NULL) { return NULL; } tmp_size = size + 14; tmp = Malloc(tmp_size); Zero(tmp, 12); WRITE_USHORT(tmp + 12, MAC_PROTO_IPV4); Copy(tmp + 14, buf, size); ret = ParsePacket(tmp, tmp_size); if (ret == NULL) { Free(tmp); } return ret; }
/* Parse the IPv4 by adding a dummy MAC header*/
Parse the IPv4 by adding a dummy MAC header
GetNextByte
UCHAR GetNextByte(BUF *b) { UCHAR c = 0; // Validate arguments if (b == NULL) { return 0; } if (ReadBuf(b, &c, 1) != 1) { return 0; } return c; }
/* Get the next byte*/
Get the next byte
FreePacket
void FreePacket(PKT *p) { // Validate arguments if (p == NULL) { return; } if (p->MacHeader != NULL) { switch (p->TypeL3) { case L3_IPV4: FreePacketIPv4(p); break; case L3_ARPV4: FreePacketARPv4(p); break; case L3_TAGVLAN: FreePacketTagVlan(p); break; } } if (p->HttpLog != NULL) { Free(p->HttpLog); } Free(p); }
/* Release the memory of the packet*/
Release the memory of the packet
FreePacketWithData
void FreePacketWithData(PKT *p) { void *data; // Validate arguments if (p == NULL) { return; } data = p->PacketData; FreePacket(p); Free(data); }
/* Release the memory of the packet with data*/
Release the memory of the packet with data
FreePacketIPv4
void FreePacketIPv4(PKT *p) { // Validate arguments if (p == NULL) { return; } switch (p->TypeL4) { case L4_ICMPV4: FreePacketICMPv4(p); break; case L4_TCP: FreePacketTCPv4(p); break; case L4_UDP: FreePacketUDPv4(p); break; } p->L3.IPv4Header = NULL; p->TypeL3 = L3_UNKNOWN; }
/* Release the memory for the IPv4 packet*/
Release the memory for the IPv4 packet
FreePacketTagVlan
void FreePacketTagVlan(PKT *p) { // Validate arguments if (p == NULL) { return; } p->L3.TagVlanHeader = NULL; p->TypeL3 = L3_UNKNOWN; }
/* Release the memory for the tagged VLAN packet*/
Release the memory for the tagged VLAN packet
FreePacketARPv4
void FreePacketARPv4(PKT *p) { // Validate arguments if (p == NULL) { return; } p->L3.ARPv4Header = NULL; p->TypeL3 = L3_UNKNOWN; }
/* Release the memory for the ARPv4 packet*/
Release the memory for the ARPv4 packet
FreePacketUDPv4
void FreePacketUDPv4(PKT *p) { // Validate arguments if (p == NULL) { return; } switch (p->TypeL7) { case L7_DHCPV4: FreePacketDHCPv4(p); break; } p->L4.UDPHeader = NULL; p->TypeL4 = L4_UNKNOWN; }
/* Release the memory of the UDPv4 packet*/
Release the memory of the UDPv4 packet
FreePacketTCPv4
void FreePacketTCPv4(PKT *p) { // Validate arguments if (p == NULL) { return; } p->L4.TCPHeader = NULL; p->TypeL4 = L4_UNKNOWN; }
/* Release the memory for the TCPv4 packet*/
Release the memory for the TCPv4 packet
FreePacketICMPv4
void FreePacketICMPv4(PKT *p) { // Validate arguments if (p == NULL) { return; } p->L4.ICMPHeader = NULL; p->TypeL4 = L4_UNKNOWN; }
/* Release the memory for the ICMPv4 packet*/
Release the memory for the ICMPv4 packet
FreePacketDHCPv4
void FreePacketDHCPv4(PKT *p) { // Validate arguments if (p == NULL) { return; } p->L7.DHCPv4Header = NULL; p->TypeL7 = L7_UNKNOWN; }
/* Release the memory for the DHCPv4 packet*/
Release the memory for the DHCPv4 packet
IpCheckChecksum
bool IpCheckChecksum(IPV4_HEADER *ip) { UINT header_size; USHORT checksum_original, checksum_calc; // Validate arguments if (ip == NULL) { return false; } header_size = IPV4_GET_HEADER_LEN(ip) * 4; checksum_original = ip->Checksum; ip->Checksum = 0; checksum_calc = IpChecksum(ip, header_size); ip->Checksum = checksum_original; if (checksum_original == checksum_calc) { return true; } else { return false; } }
/* Confirm the checksum of the IP header*/
Confirm the checksum of the IP header
NewDhcpOption
DHCP_OPTION *NewDhcpOption(UINT id, void *data, UINT size) { DHCP_OPTION *ret; if (size != 0 && data == NULL) { return NULL; } ret = ZeroMalloc(sizeof(DHCP_OPTION)); ret->Data = ZeroMalloc(size); Copy(ret->Data, data, size); ret->Size = (UCHAR)size; ret->Id = (UCHAR)id; return ret; }
/* Create a new DHCP option item*/
Create a new DHCP option item
NormalizeClasslessRouteTableStr
bool NormalizeClasslessRouteTableStr(char *dst, UINT dst_size, char *src) { DHCP_CLASSLESS_ROUTE_TABLE t; // Validate arguments if (dst == NULL || src == NULL) { return false; } Zero(&t, sizeof(t)); if (ParseClasslessRouteTableStr(&t, src)) { BuildClasslessRouteTableStr(dst, dst_size, &t); return true; } return false; }
/* Normalize the classless routing table string*/
Normalize the classless routing table string
BuildClasslessRouteStr
void BuildClasslessRouteStr(char *str, UINT str_size, DHCP_CLASSLESS_ROUTE *r) { ClearStr(str, str_size); // Validate arguments if (str == NULL || r == NULL || r->Exists == false) { return; } Format(str, str_size, "%r/%r/%r", &r->Network, &r->SubnetMask, &r->Gateway); }
/* Build the string from the classless routing table entry*/
Build the string from the classless routing table entry
CheckClasslessRouteTableStr
bool CheckClasslessRouteTableStr(char *str) { DHCP_CLASSLESS_ROUTE_TABLE d; // Validate arguments if (str == NULL) { return false; } return ParseClasslessRouteTableStr(&d, str); }
/* Check the classless routing table string*/
Check the classless routing table string
GetDhcpOption
DHCP_OPTION *GetDhcpOption(LIST *o, UINT id) { UINT i; DHCP_OPTION *ret = NULL; // Validate arguments if (o == NULL) { return NULL; } for (i = 0;i < LIST_NUM(o);i++) { DHCP_OPTION *opt = LIST_DATA(o, i); if (opt->Id == id) { ret = opt; } } return ret; }
/* Finding a DHCP option*/
Finding a DHCP option
FreeDhcpOptions
void FreeDhcpOptions(LIST *o) { UINT i; // Validate arguments if (o == NULL) { return; } for (i = 0;i < LIST_NUM(o);i++) { DHCP_OPTION *opt = LIST_DATA(o, i); Free(opt->Data); Free(opt); } ReleaseList(o); }
/* Release the DHCP option*/
Release the DHCP option
PRandInt
UINT PRandInt(PRAND *p) { UINT r; if (p == NULL) { return 0; } PRand(p, &r, sizeof(UINT)); return r; }
/* Generate UINT PRand*/
Generate UINT PRand
IsInHashListKey
bool IsInHashListKey(HASH_LIST *h, UINT key) { // Validate arguments if (h == NULL || key == 0) { return false; } if (HashListKeyToPointer(h, key) == NULL) { return false; } return true; }
/* Check whether the specified key item is in the hash list*/
Check whether the specified key item is in the hash list
HashListKeyToPointer
void *HashListKeyToPointer(HASH_LIST *h, UINT key) { UINT num, i; void **pp; void *ret = NULL; // Validate arguments if (h == NULL || key == 0) { return NULL; } pp = HashListToArray(h, &num); if (pp == NULL) { return NULL; } for (i = 0;i < num;i++) { void *p = pp[i]; if (POINTER_TO_KEY(p) == key) { ret = p; } } Free(pp); return ret; }
/* Search the item in the hash list with the key*/
Search the item in the hash list with the key
LockHashList
void LockHashList(HASH_LIST *h) { // Validate arguments if (h == NULL) { return; } Lock(h->Lock); }
/* Lock the hash list*/
Lock the hash list
UnlockHashList
void UnlockHashList(HASH_LIST *h) { // Validate arguments if (h == NULL) { return; } Unlock(h->Lock); }
/* Unlock the hash list*/
Unlock the hash list
SearchHash
void *SearchHash(HASH_LIST *h, void *t) { UINT r; void *ret = NULL; // Validate arguments if (h == NULL || t == NULL) { return NULL; } r = CalcHashForHashList(h, t); if (h->Entries[r] != NULL) { LIST *o = h->Entries[r]; void *r = Search(o, t); if (r != NULL) { ret = r; } } return ret; }
/* Search an item in the hash list*/
Search an item in the hash list
AddHash
void AddHash(HASH_LIST *h, void *p) { UINT r; // Validate arguments if (h == NULL || p == NULL) { return; } r = CalcHashForHashList(h, p); if (h->Entries[r] == NULL) { h->Entries[r] = NewListFast(h->CompareProc); } Insert(h->Entries[r], p); if (h->AllList != NULL) { Add(h->AllList, p); } h->NumItems++; }
/* Add an item to the hash list*/
Add an item to the hash list
CalcHashForHashList
UINT CalcHashForHashList(HASH_LIST *h, void *p) { UINT r; // Validate arguments if (h == NULL || p == NULL) { return 0; } r = h->GetHashProc(p); return (r % h->Size); }
/* Calculation of the hash value of the object*/
Calculation of the hash value of the object
ReleaseHashList
void ReleaseHashList(HASH_LIST *h) { // Validate arguments if (h == NULL) { return; } if (Release(h->Ref) == 0) { CleanupHashList(h); } }
/* Release the hash list*/
Release the hash list
AppendBufStr
void AppendBufStr(BUF *b, char *str) { // Validate arguments if (b == NULL || str == NULL) { return; } WriteBuf(b, str, StrLen(str)); }
/* Append a string to the buffer*/
Append a string to the buffer
AppendBufUtf8
void AppendBufUtf8(BUF *b, wchar_t *str) { UINT size; UCHAR *data; // Validate arguments if (b == NULL || str == NULL) { return; } size = CalcUniToUtf8(str) + 1; data = ZeroMalloc(size); UniToUtf8(data, size, str); WriteBuf(b, data, size - 1); Free(data); }
/* Add a UTF-8 string to the buffer*/
Add a UTF-8 string to the buffer
NewSharedBuffer
SHARED_BUFFER *NewSharedBuffer(void *data, UINT size) { SHARED_BUFFER *b = ZeroMalloc(sizeof(SHARED_BUFFER)); b->Ref = NewRef(); b->Data = ZeroMalloc(size); b->Size = size; if (data != NULL) { Copy(b->Data, data, size); } return b; }
/* Creating a shared buffer*/
Creating a shared buffer
ReleaseSharedBuffer
void ReleaseSharedBuffer(SHARED_BUFFER *b) { // Validate arguments if (b == NULL) { return; } if (Release(b->Ref) == 0) { CleanupSharedBuffer(b); } }
/* Release of the shared buffer*/
Release of the shared buffer
Power
UINT Power(UINT a, UINT b) { UINT ret, i; if (a == 0) { return 0; } if (b == 0) { return 1; } ret = 1; for (i = 0;i < b;i++) { ret *= a; } return ret; }
/* Calculation of a ^ b (a to the b-th power)*/
Calculation of a ^ b (a to the b-th power)
SearchBin
UINT SearchBin(void *data, UINT data_start, UINT data_size, void *key, UINT key_size) { UINT i; // Validate arguments if (data == NULL || key == NULL || key_size == 0 || data_size == 0 || (data_start >= data_size) || (data_start + key_size > data_size)) { return INFINITE; } for (i = data_start;i < (data_size - key_size + 1);i++) { UCHAR *p = ((UCHAR *)data) + i; if (Cmp(p, key, key_size) == 0) { return i; } } return INFINITE; }
/* Search in the binary*/
Search in the binary
CandidateToBuf
BUF *CandidateToBuf(LIST *o) { BUF *b; UINT i; // Validate arguments if (o == NULL) { return NULL; } b = NewBuf(); WriteBufInt(b, LIST_NUM(o)); for (i = 0;i < LIST_NUM(o);i++) { CANDIDATE *c = LIST_DATA(o, i); WriteBufInt64(b, c->LastSelectedTime); WriteBufInt(b, UniStrLen(c->Str)); WriteBuf(b, c->Str, UniStrSize(c->Str)); } SeekBuf(b, 0, 0); return b; }
/* Convert the candidate to buffer*/
Convert the candidate to buffer
CompareCandidate
int CompareCandidate(void *p1, void *p2) { CANDIDATE *c1, *c2; if (p1 == NULL || p2 == NULL) { return 0; } c1 = *(CANDIDATE **)p1; c2 = *(CANDIDATE **)p2; if (c1 == NULL || c2 == NULL) { return 0; } if (c1->LastSelectedTime > c2->LastSelectedTime) { return -1; } else if (c1->LastSelectedTime < c2->LastSelectedTime) { return 1; } else { return UniStrCmpi(c1->Str, c2->Str); } }
/* Comparison of candidates*/
Comparison of candidates
FreeCandidateList
void FreeCandidateList(LIST *o) { UINT i; // Validate arguments if (o == NULL) { return; } for (i = 0;i < LIST_NUM(o);i++) { CANDIDATE *c = LIST_DATA(o, i); Free(c->Str); Free(c); } ReleaseList(o); }
/* Release of the candidate list*/
Release of the candidate list
NewCandidateList
LIST *NewCandidateList() { return NewList(CompareCandidate); }
/* Creating a new candidate list*/
Creating a new candidate list
IsZero
bool IsZero(void *data, UINT size) { UINT i; UCHAR *c = (UCHAR *)data; // Validate arguments if (data == NULL || size == 0) { return true; } for (i = 0;i < size;i++) { if (c[i] != 0) { return false; } } return true; }
/* Examine whether the specified address points all-zero area*/
Examine whether the specified address points all-zero area
Uncompress
UINT Uncompress(void *dst, UINT dst_size, void *src, UINT src_size) { unsigned long dst_size_long = dst_size; // Validate arguments if (dst == NULL || dst_size_long == 0 || src == NULL) { return 0; } if (uncompress(dst, &dst_size_long, src, src_size) != Z_OK) { return 0; } return (UINT)dst_size_long; }
/* Expand the data*/
Expand the data
Compress
UINT Compress(void *dst, UINT dst_size, void *src, UINT src_size) { return CompressEx(dst, dst_size, src, src_size, Z_DEFAULT_COMPRESSION); }
/* Compress the data*/
Compress the data
CompressEx
UINT CompressEx(void *dst, UINT dst_size, void *src, UINT src_size, UINT level) { unsigned long dst_size_long = dst_size; // Validate arguments if (dst == NULL || dst_size_long == 0 || src == NULL) { return 0; } if (compress2(dst, &dst_size_long, src, src_size, (int)level) != Z_OK) { return 0; } return dst_size_long; }
/* Compress the data with options*/
Compress the data with options
CalcCompress
UINT CalcCompress(UINT src_size) { return src_size * 2 + 256; }
/* Get the maximum size of compressed data from data of src_size*/
Get the maximum size of compressed data from data of src_size
NewSk
SK *NewSk() { return NewSkEx(false); }
/* Creating a Stack*/
Creating a Stack
ReleaseSk
void ReleaseSk(SK *s) { // Validate arguments if (s == NULL) { return; } if (Release(s->ref) == 0) { CleanupSk(s); } }
/* Release of the stack*/
Release of the stack
CleanupSk
void CleanupSk(SK *s) { // Validate arguments if (s == NULL) { return; } // Memory release Free(s->p); DeleteLock(s->lock); Free(s); // KS KS_INC(KS_FREESK_COUNT); }
/* Clean up the stack*/
Clean up the stack
LockSk
void LockSk(SK *s) { // Validate arguments if (s == NULL) { return; } Lock(s->lock); }
/* Lock of the stack*/
Lock of the stack
UnlockSk
void UnlockSk(SK *s) { // Validate arguments if (s == NULL) { return; } Unlock(s->lock); }
/* Unlock the stack*/
Unlock the stack
Push
void Push(SK *s, void *p) { UINT i; // Validate arguments if (s == NULL || p == NULL) { return; } i = s->num_item; s->num_item++; // Size expansion if (s->num_item > s->num_reserved) { s->num_reserved = s->num_reserved * 2; s->p = ReAlloc(s->p, sizeof(void *) * s->num_reserved); } s->p[i] = p; // KS KS_INC(KS_PUSH_COUNT); }
/* Push to the stack*/
Push to the stack
GetQueueNum
UINT GetQueueNum(QUEUE *q) { // Validate arguments if (q == NULL) { return 0; } return q->num_item; }
/* Get the number of queued items*/
Get the number of queued items
GetNextWithLock
void *GetNextWithLock(QUEUE *q) { void *p; // Validate arguments if (q == NULL) { return NULL; } LockQueue(q); { p = GetNext(q); } UnlockQueue(q); return p; }
/* Get one item from the queue (locking)*/
Get one item from the queue (locking)
InsertQueueInt
void InsertQueueInt(QUEUE *q, UINT value) { UINT *p; // Validate arguments if (q == NULL) { return; } p = Clone(&value, sizeof(UINT)); InsertQueue(q, p); }
/* Insert the int type in the queue*/
Insert the int type in the queue
InsertQueue
void InsertQueue(QUEUE *q, void *p) { // Validate arguments if (q == NULL || p == NULL) { return; } // Write to the FIFO WriteFifo(q->fifo, &p, sizeof(void *)); q->num_item++; /*{ static UINT max_num_item; static UINT64 next_tick = 0; UINT64 now = Tick64(); max_num_item = MAX(q->num_item, max_num_item); if (next_tick == 0 || next_tick <= now) { next_tick = now + (UINT64)1000; printf("max_queue = %u\n", max_num_item); } }*/ // KS KS_INC(KS_INSERT_QUEUE_COUNT); }
/* Insert to the queue*/
Insert to the queue
InsertQueueWithLock
void InsertQueueWithLock(QUEUE *q, void *p) { // Validate arguments if (q == NULL || p == NULL) { return; } LockQueue(q); { InsertQueue(q, p); } UnlockQueue(q); }
/* Insert to the queue (locking)*/
Insert to the queue (locking)
LockQueue
void LockQueue(QUEUE *q) { // Validate arguments if (q == NULL) { return; } Lock(q->lock); }
/* Lock the queue*/
Lock the queue
UnlockQueue
void UnlockQueue(QUEUE *q) { // Validate arguments if (q == NULL) { return; } Unlock(q->lock); }
/* Unlock the queue*/
Unlock the queue
ReleaseQueue
void ReleaseQueue(QUEUE *q) { // Validate arguments if (q == NULL) { return; } if (q->ref == NULL || Release(q->ref) == 0) { CleanupQueue(q); } }
/* Release of the queue*/
Release of the queue
CleanupQueue
void CleanupQueue(QUEUE *q) { // Validate arguments if (q == NULL) { return; } // Memory release ReleaseFifo(q->fifo); DeleteLock(q->lock); Free(q); // KS KS_INC(KS_FREEQUEUE_COUNT); }
/* Clean-up the queue*/
Clean-up the queue
NewQueue
QUEUE *NewQueue() { QUEUE *q; q = ZeroMalloc(sizeof(QUEUE)); q->lock = NewLock(); q->ref = NewRef(); q->num_item = 0; q->fifo = NewFifo(); // KS KS_INC(KS_NEWQUEUE_COUNT); return q; }
/* Creating a Queue*/
Creating a Queue
CloneList
LIST *CloneList(LIST *o) { LIST *n = NewList(o->cmp); // Memory reallocation Free(n->p); n->p = ToArray(o); n->num_item = n->num_reserved = LIST_NUM(o); n->sorted = o->sorted; return n; }
/* Clone the list*/
Clone the list
CopyToArray
void CopyToArray(LIST *o, void *p) { // Validate arguments if (o == NULL || p == NULL) { return; } // KS KS_INC(KS_TOARRAY_COUNT); Copy(p, o->p, sizeof(void *) * o->num_item); }
/* Copy the list to an array*/
Copy the list to an array
ToArray
void *ToArray(LIST *o) { return ToArrayEx(o, false); }
/* Arrange the list to an array*/
Arrange the list to an array
Search
void *Search(LIST *o, void *target) { void **ret; // Validate arguments if (o == NULL || target == NULL) { return NULL; } if (o->cmp == NULL) { return NULL; } // Check the sort if (o->sorted == false) { // Sort because it is not sorted Sort(o); } ret = (void **)bsearch(&target, o->p, o->num_item, sizeof(void *), (int(*)(const void *, const void *))o->cmp); // KS KS_INC(KS_SEARCH_COUNT); if (ret != NULL) { return *ret; } else { return NULL; } }
/* Search in the list*/
Search in the list
Sort
void Sort(LIST *o) { // Validate arguments if (o == NULL || o->cmp == NULL) { return; } qsort(o->p, o->num_item, sizeof(void *), (int(*)(const void *, const void *))o->cmp); o->sorted = true; // KS KS_INC(KS_SORT_COUNT); }
/* Sort the list*/
Sort the list
ReplaceListPointer
bool ReplaceListPointer(LIST *o, void *oldptr, void *newptr) { UINT i; // Validate arguments if (o == NULL || oldptr == NULL || newptr == NULL) { return false; } for (i = 0;i < LIST_NUM(o);i++) { void *p = LIST_DATA(o, i); if (p == oldptr) { o->p[i] = newptr; return true; } } return false; }
/* Replace the pointer in the list*/
Replace the pointer in the list
NewStrList
LIST *NewStrList() { return NewListFast(CompareStr); }
/* New string list*/
New string list
ReleaseStrList
void ReleaseStrList(LIST *o) { UINT i; if (o == NULL) { return; } for (i = 0;i < LIST_NUM(o);i++) { char *s = LIST_DATA(o, i); Free(s); } ReleaseList(o); }
/* Release string list*/
Release string list
AddStrToStrListDistinct
bool AddStrToStrListDistinct(LIST *o, char *str) { if (o == NULL || str == NULL) { return false; } if (IsInListStr(o, str) == false) { Add(o, CopyStr(str)); return true; } return false; }
/* Add a string distinct to the string list*/
Add a string distinct to the string list
IsInListStr
bool IsInListStr(LIST *o, char *str) { UINT i; // Validate arguments if (o == NULL || str == NULL) { return false; } for (i = 0;i < LIST_NUM(o);i++) { char *s = LIST_DATA(o, i); if (StrCmpi(s, str) == 0) { return true; } } return false; }
/* Examine whether a string items are present in the list*/
Examine whether a string items are present in the list
ListKeyToPointer
void *ListKeyToPointer(LIST *o, UINT key) { UINT i; // Validate arguments if (o == NULL || key == 0) { return NULL; } for (i = 0;i < LIST_NUM(o);i++) { void *p = LIST_DATA(o, i); if (POINTER_TO_KEY(p) == key) { return p; } } return NULL; }
/* Get the pointer by scanning by UINT pointer in the list*/
Get the pointer by scanning by UINT pointer in the list
IsInListKey
bool IsInListKey(LIST *o, UINT key) { void *p; // Validate arguments if (o == NULL || key == 0) { return false; } p = ListKeyToPointer(o, key); if (p == NULL) { return false; } return true; }
/* Examine whether the key is present in the list*/
Examine whether the key is present in the list
IsInList
bool IsInList(LIST *o, void *p) { UINT i; // Validate arguments if (o == NULL || p == NULL) { return false; } for (i = 0;i < LIST_NUM(o);i++) { void *q = LIST_DATA(o, i); if (p == q) { return true; } } return false; }
/* Examine whether the item exists in the list*/
Examine whether the item exists in the list
AddDistinct
void AddDistinct(LIST *o, void *p) { // Validate arguments if (o == NULL || p == NULL) { return; } if (IsInList(o, p)) { return; } Add(o, p); }
/* Add an element to the list (Don't add if it already exists)*/
Add an element to the list (Don't add if it already exists)
Add
void Add(LIST *o, void *p) { UINT i; // Validate arguments if (o == NULL || p == NULL) { return; } i = o->num_item; o->num_item++; if (o->num_item > o->num_reserved) { o->num_reserved = o->num_reserved * 2; o->p = ReAlloc(o->p, sizeof(void *) * o->num_reserved); } o->p[i] = p; o->sorted = false; // KS KS_INC(KS_INSERT_COUNT); }
/* Add an element to the list*/
Add an element to the list
DeleteAll
void DeleteAll(LIST *o) { // Validate arguments if (o == NULL) { return; } o->num_item = 0; o->num_reserved = INIT_NUM_RESERVED; o->p = ReAlloc(o->p, sizeof(void *) * INIT_NUM_RESERVED); }
/* Delete all elements from the list*/
Delete all elements from the list
LockList
void LockList(LIST *o) { // Validate arguments if (o == NULL) { return; } Lock(o->lock); }
/* Lock the list*/
Lock the list
UnlockList
void UnlockList(LIST *o) { // Validate arguments if (o == NULL) { return; } Unlock(o->lock); }
/* Unlock the list*/
Unlock the list
ReleaseList
void ReleaseList(LIST *o) { // Validate arguments if (o == NULL) { return; } if (o->ref == NULL || Release(o->ref) == 0) { CleanupList(o); } }
/* Release the list*/
Release the list
CleanupList
void CleanupList(LIST *o) { // Validate arguments if (o == NULL) { return; } Free(o->p); if (o->lock != NULL) { DeleteLock(o->lock); } Free(o); // KS KS_INC(KS_FREELIST_COUNT); }
/* Clean up the list*/
Clean up the list
IsIntInList
bool IsIntInList(LIST *o, UINT i) { UINT j; // Validate arguments if (o == NULL) { return false; } for (j = 0;j < LIST_NUM(o);j++) { UINT *p = LIST_DATA(o, j); if (*p == i) { return true; } } return false; }
/* Check whether the specified number is already in the list*/
Check whether the specified number is already in the list
ReleaseIntList
void ReleaseIntList(LIST *o) { UINT i; // Validate arguments if (o == NULL) { return; } for (i = 0;i < LIST_NUM(o);i++) { UINT *p = LIST_DATA(o, i); Free(p); } ReleaseList(o); }
/* Release the integer list*/
Release the integer list
NewIntList
LIST *NewIntList(bool sorted) { LIST *o = NewList(sorted ? CompareInt : NULL); return o; }
/* Create a new list of integers*/
Create a new list of integers
CompareInt
int CompareInt(void *p1, void *p2) { UINT *v1, *v2; if (p1 == NULL || p2 == NULL) { return 0; } v1 = *((UINT **)p1); v2 = *((UINT **)p2); if (v1 == NULL || v2 == NULL) { return 0; } return COMPARE_RET(*v1, *v2); }
/* Comparison of items in the list of integers*/
Comparison of items in the list of integers
AddInt
void AddInt(LIST *o, UINT i) { // Validate arguments if (o == NULL) { return; } Add(o, Clone(&i, sizeof(UINT))); }
/* Add an integer to the list*/
Add an integer to the list
AddIntDistinct
void AddIntDistinct(LIST *o, UINT i) { // Validate arguments if (o == NULL) { return; } if (IsIntInList(o, i) == false) { AddInt(o, i); } }
/* Add an integer to the list (no duplicates)*/
Add an integer to the list (no duplicates)
CompareUniStr
int CompareUniStr(void *p1, void *p2) { wchar_t *s1, *s2; if (p1 == NULL || p2 == NULL) { return 0; } s1 = *(wchar_t **)p1; s2 = *(wchar_t **)p2; return UniStrCmp(s1, s2); }
/* String comparison function (Unicode)*/
String comparison function (Unicode)
InsertStr
bool InsertStr(LIST *o, char *str) { // Validate arguments if (o == NULL || str == NULL) { return false; } if (Search(o, str) == NULL) { Insert(o, str); return true; } return false; }
/* Insert the string to the list*/
Insert the string to the list
CompareStr
int CompareStr(void *p1, void *p2) { char *s1, *s2; if (p1 == NULL || p2 == NULL) { return 0; } s1 = *(char **)p1; s2 = *(char **)p2; return StrCmpi(s1, s2); }
/* String comparison function*/
String comparison function
NewListSingle
LIST *NewListSingle(void *p) { LIST *o = NewListFast(NULL); Add(o, p); return o; }
/* Create a list with an item*/
Create a list with an item
NewListFast
LIST *NewListFast(COMPARE *cmp) { return NewListEx(cmp, true); }
/* Creating a high-speed list (without lock)*/
Creating a high-speed list (without lock)
NewList
LIST *NewList(COMPARE *cmp) { return NewListEx(cmp, false); }
/* Creating a list*/
Creating a list
EntryListHasKey
bool EntryListHasKey(LIST *o, char *key) { // Validate arguments if (o == NULL || key == NULL) { return false; } if (GetIniEntry(o, key) != NULL) { return true; } return false; }
/* Checks whether the list contains the specified entry*/
Checks whether the list contains the specified entry
EntryListStrValue
char *EntryListStrValue(LIST *o, char *key) { return IniStrValue(o, key); }
/* Gets the value of the specified key from the entry list*/
Gets the value of the specified key from the entry list
FreeEntryList
void FreeEntryList(LIST *o) { // Validate arguments if (o == NULL) { return; } FreeIni(o); }
/* Release the entry list*/
Release the entry list
ReadFifoAll
BUF *ReadFifoAll(FIFO *f) { BUF *buf; UCHAR *tmp; UINT size; if (f == NULL) { return NewBuf(); } size = FifoSize(f); tmp = Malloc(size); ReadFifo(f, tmp, size); buf = MemToBuf(tmp, size); Free(tmp); return buf; }
/* Read all data from FIFO*/
Read all data from FIFO
GetFifoPointer
UCHAR *GetFifoPointer(FIFO *f) { // Validate arguments if (f == NULL) { return NULL; } return ((UCHAR *)f->p) + f->pos; }
/* Get the current pointer of the FIFO*/
Get the current pointer of the FIFO
FifoSize
UINT FifoSize(FIFO *f) { // Validate arguments if (f == NULL) { return 0; } return f->size; }
/* Get the size of the FIFO*/
Get the size of the FIFO
ReleaseFifo
void ReleaseFifo(FIFO *f) { // Validate arguments if (f == NULL) { return; } if (f->ref == NULL || Release(f->ref) == 0) { CleanupFifo(f); } }
/* Release the FIFO*/
Release the FIFO