Mercurial > hg > anonet-resdb
comparison contrib/marc/marc.c @ 1185:97ed67f3a20d draft
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
author | epoch <epoch@hacking.allowed.ano> |
---|---|
date | Tue, 09 Feb 2016 03:03:12 +0000 |
parents | c6c05029393a |
children | 98707534e274 |
comparison
equal
deleted
inserted
replaced
1184:80f04024e959 | 1185:97ed67f3a20d |
---|---|
7 #define M_TYPE_NULL 0 | 7 #define M_TYPE_NULL 0 |
8 #define M_TYPE_STRING 1 | 8 #define M_TYPE_STRING 1 |
9 #define M_TYPE_LIST 2 | 9 #define M_TYPE_LIST 2 |
10 #define M_TYPE_DICT 3 | 10 #define M_TYPE_DICT 3 |
11 | 11 |
12 //extension? | |
13 #define M_TYPE_TRANSFERCHAIN 5 | |
14 | |
12 char *type[]={"NULL","string","list","dict"}; | 15 char *type[]={"NULL","string","list","dict"}; |
13 | 16 |
14 int indent; | 17 int indent; |
15 | 18 |
16 void pi() { | 19 void pi() { |
18 for(i=0;i<indent;i++) { | 21 for(i=0;i<indent;i++) { |
19 printf("%s"," "); | 22 printf("%s"," "); |
20 } | 23 } |
21 } | 24 } |
22 | 25 |
26 void printpercent(unsigned char *data,int length) { | |
27 for(;length;data++,length--) { | |
28 if(isprint(*data)) printf("%c",*data); | |
29 else { | |
30 // printf("%%%c%c","0123456789abcdef"[(*data-'0')>>4&15],"0123456789abcdef"[(*data-'0')&15]); | |
31 printf("%%%02x",*data); | |
32 //"0123456789abcdef"[(*data-'0')>>4&15],"0123456789abcdef"[(*data-'0')&15]); | |
33 } | |
34 } | |
35 } | |
36 | |
23 int marc_decode(unsigned char *data,int from_index,int length) { | 37 int marc_decode(unsigned char *data,int from_index,int length) { |
24 char *s; | 38 unsigned char *s; |
25 unsigned int cur_len=0; | 39 unsigned int cur_len=0; |
26 unsigned char m_type=data[from_index]; | 40 unsigned char m_type=data[from_index]; |
27 from_index++; | 41 from_index++; |
28 char *key; | 42 char *key; |
29 if(!length) return printf("dafuq? no length???"),-1; | 43 if(!length) return printf("what the fuck? no length???"),-1; |
30 pi(); | 44 pi(); |
31 printf("length: %d\n",length); | 45 printf("length: %d\n",length); |
32 pi(); | 46 pi(); |
33 switch(m_type) { | 47 switch(m_type) { |
34 case M_TYPE_NULL: | 48 case M_TYPE_NULL: |
36 break; | 50 break; |
37 case M_TYPE_STRING: | 51 case M_TYPE_STRING: |
38 s=malloc(length); | 52 s=malloc(length); |
39 memcpy(s,data+from_index,length-1); | 53 memcpy(s,data+from_index,length-1); |
40 s[length-1]=0; | 54 s[length-1]=0; |
41 printf("string: %s\n",s); | 55 printf("string: "); |
56 printpercent(s,length); | |
57 printf("\n"); | |
42 break; | 58 break; |
43 case M_TYPE_LIST: | 59 case M_TYPE_LIST: |
44 printf("list:\n"); | 60 printf("list:\n"); |
45 indent++; | 61 indent++; |
46 while(from_index < length) { | 62 while(from_index < length) { |
73 indent--; | 89 indent--; |
74 from_index+=cur_len; | 90 from_index+=cur_len; |
75 } | 91 } |
76 indent--; | 92 indent--; |
77 break; | 93 break; |
94 /*case M_TYPE_TRANSFERCHAIN: | |
95 s=malloc(length); | |
96 memcpy(s,data+from_index,length-1); | |
97 s[length-1]=0; | |
98 printf("transfer: %s\n",s); | |
99 break;*/ | |
78 default: | 100 default: |
79 printf("oh fuck. dahell is this!?!? %d\n",m_type); | 101 printf("oh fuck. dahell is this!?!? mtype of %d!?!?\n",m_type); |
80 break; | 102 break; |
81 } | 103 } |
82 return 0; | 104 return 0; |
83 } | 105 } |
84 | 106 |
87 printf("%02x",*data); | 109 printf("%02x",*data); |
88 } | 110 } |
89 } | 111 } |
90 | 112 |
91 void update_message_decode(unsigned char *data,int from_index,int length) { | 113 void update_message_decode(unsigned char *data,int from_index,int length) { |
92 printf("update_message version: %d len: %d\n",data[from_index],length); | 114 printf("\nupdate_message version: %d len: %d\n",data[from_index],length); |
93 if(data[from_index] != 2) return printf("this program only handles version 2 update messages.\n"); | 115 if(data[from_index] != 2) return printf("this program only handles version 2 update messages.\n"); |
94 from_index++; | 116 from_index++; |
95 char pkey[32]; | 117 char pkey[32]; |
96 int i; | 118 int i; |
97 char *label; | 119 char *label; |
133 from_index++; | 155 from_index++; |
134 ext_data_len=(data[from_index]<<8) + (data[from_index+1]); | 156 ext_data_len=(data[from_index]<<8) + (data[from_index+1]); |
135 from_index+=2; | 157 from_index+=2; |
136 from_index+=ext_data_len;//skip this for now... fuck it. | 158 from_index+=ext_data_len;//skip this for now... fuck it. |
137 printf(" ext %d type: %d len: %d\n",i,ext_type,ext_data_len); | 159 printf(" ext %d type: %d len: %d\n",i,ext_type,ext_data_len); |
138 if(ext_type != 1 && ext_type != 4) return printf("fuckfuckfuckfuck...\n"),0; | 160 if(ext_type != 1 && ext_type != 4 && ext_type != 5) {//let's pretend 5 is transfer chain? |
161 printf("fuck. unknown ext_type: %d @ %d\n",ext_type,from_index); | |
162 return; | |
163 } | |
139 } | 164 } |
140 marc_decode(data+from_index,0,length); | 165 marc_decode(data+from_index,0,length); |
141 //} | 166 //} |
142 return; | 167 return; |
143 } | 168 } |