|
1 #include "CS.h" |
|
2 |
|
3 void Data(DataP thisP, DebugP callerDeP) { |
|
4 DebugP deP = &(thisP->debug); |
|
5 DEBID("%s DATA", callerDeP->id); |
|
6 thisP->dataLen = sizeof(HeaderT) + sizeof(PayloadT) + strlen(csP->text); |
|
7 thisP->contP = (ContainerP)malloc(thisP->dataLen); |
|
8 thisP->contP->hdr.ttl = 0; |
|
9 thisP->contP->hdr.ts = 0; |
|
10 strcpy(&(thisP->contP->payl.text), "EMPTY"); |
|
11 LOG(5, "Data instance established"); |
|
12 } |
|
13 int dttlData(DataP thisP) { |
|
14 thisP->contP->hdr.ttl--; |
|
15 return thisP->contP->hdr.ttl; |
|
16 } |
|
17 int ttlData(DataP thisP) { |
|
18 return thisP->contP->hdr.ttl; |
|
19 } |
|
20 int remPortData(DataP thisP) { |
|
21 return thisP->contP->hdr.listPort; |
|
22 } |
|
23 DataP loadData(DataP thisP, int ttl, char *loadP) { |
|
24 DebugP deP = &(thisP->debug); |
|
25 thisP->contP->hdr.ttl = ttl; |
|
26 thisP->contP->payl.ts = time(NULL); |
|
27 strcpy(&(thisP->contP->payl.text), csP->text); |
|
28 LOG(5, "payload loaded to container"); |
|
29 return thisP; |
|
30 } |
|
31 char *unldData(DataP thisP) { |
|
32 return &(thisP->contP->payl.text); |
|
33 } |
|
34 char *digest24Data(DataP thisP, char *digest) { |
|
35 char *text = &(thisP->contP->payl.text); |
|
36 if(strlen(text) < 24) strcpy(digest, text); |
|
37 else { strncpy(digest, text, 8); strcpy(digest+8, "-------"); strcpy(digest+15, text+strlen(text)-8); } |
|
38 return digest; |
|
39 } |
|
40 void sabotageData(DataP thisP) { |
|
41 thisP->contP->payl.text = '?'; } |
|
42 int chkData(DataP thisP) { |
|
43 return (int)(strcmp(csP->text, &(thisP->contP->payl.text)) == 0); |
|
44 } |
|
45 int tsData(DataP thisP) { |
|
46 return thisP->contP->hdr.ts; |
|
47 } |