| 42 | | // just print it for now |
|---|
| 43 | | // \todo read literal data packet into buffer |
|---|
| 44 | | |
|---|
| 45 | | ops_print_packet(content_); |
|---|
| | 45 | // ops_print_packet(content_); |
|---|
| | 46 | |
|---|
| | 47 | // Read data from packet into static buffer |
|---|
| | 48 | switch(content_->tag) |
|---|
| | 49 | { |
|---|
| | 50 | case OPS_PTAG_CT_LITERAL_DATA_BODY: |
|---|
| | 51 | data=ops_mallocz(content->literal_data_body.length+1); |
|---|
| | 52 | memcpy(data,content->literal_data_body.data,content->literal_data_body.length); |
|---|
| | 53 | break; |
|---|
| | 54 | |
|---|
| | 55 | case OPS_PARSER_PTAG: |
|---|
| | 56 | case OPS_PTAG_CT_LITERAL_DATA_HEADER: |
|---|
| | 57 | // ignore |
|---|
| | 58 | break; |
|---|
| | 59 | |
|---|
| | 60 | default: |
|---|
| | 61 | fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag, |
|---|
| | 62 | content_->tag); |
|---|
| | 63 | assert(0); |
|---|
| | 64 | } |
|---|
| | 65 | |
|---|
| | 78 | static void init_for_memory_write(ops_create_info_t **cinfo, ops_memory_t **mem) |
|---|
| | 79 | { |
|---|
| | 80 | /* |
|---|
| | 81 | * initialise needed structures for writing |
|---|
| | 82 | */ |
|---|
| | 83 | |
|---|
| | 84 | *cinfo=ops_create_info_new(); |
|---|
| | 85 | *mem=ops_memory_new(); |
|---|
| | 86 | |
|---|
| | 87 | ops_memory_init(*mem,MAXBUF); |
|---|
| | 88 | |
|---|
| | 89 | ops_writer_set_memory(*cinfo,*mem); |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | static void init_for_memory_read(ops_parse_info_t **pinfo, ops_memory_t *mem, |
|---|
| | 93 | ops_parse_cb_return_t callback(const ops_parser_content_t *, ops_parse_cb_info_t *)) |
|---|
| | 94 | { |
|---|
| | 95 | /* |
|---|
| | 96 | * initialise needed structures for reading |
|---|
| | 97 | */ |
|---|
| | 98 | |
|---|
| | 99 | *pinfo=ops_parse_info_new(); |
|---|
| | 100 | ops_parse_cb_set(*pinfo,callback,NULL); |
|---|
| | 101 | ops_reader_set_memory(*pinfo,mem->buf,mem->length); |
|---|
| | 102 | } |
|---|
| | 103 | |
|---|
| | 104 | |
|---|
| 67 | | create_testtext("literal data packet", &in[0], MAXBUF); |
|---|
| 68 | | |
|---|
| 69 | | /* |
|---|
| 70 | | * initialise needed structures for writing |
|---|
| 71 | | */ |
|---|
| 72 | | |
|---|
| 73 | | cinfo=ops_create_info_new(); |
|---|
| 74 | | mem=ops_memory_new(); |
|---|
| 75 | | ops_memory_init(mem,MAXBUF); |
|---|
| 76 | | ops_writer_set_memory(cinfo,mem); |
|---|
| | 115 | create_testtext("literal data packet text", &in[0], MAXBUF); |
|---|
| | 116 | |
|---|
| | 117 | /* |
|---|
| | 118 | * initialise needed structures for writing into memory |
|---|
| | 119 | */ |
|---|
| | 120 | |
|---|
| | 121 | init_for_memory_write(&cinfo,&mem); |
|---|
| 84 | | * initialise needed structures for writing |
|---|
| 85 | | */ |
|---|
| 86 | | |
|---|
| 87 | | pinfo=ops_parse_info_new(); |
|---|
| 88 | | ops_parse_cb_set(pinfo,callback,NULL); |
|---|
| 89 | | ops_reader_set_memory(pinfo,mem->buf,mem->length); |
|---|
| | 129 | * initialise needed structures for reading from memory |
|---|
| | 130 | */ |
|---|
| | 131 | |
|---|
| | 132 | init_for_memory_read(&pinfo,mem,callback); |
|---|
| | 150 | static void test_literal_data_packet_data() |
|---|
| | 151 | { |
|---|
| | 152 | ops_create_info_t *cinfo; |
|---|
| | 153 | ops_parse_info_t *pinfo; |
|---|
| | 154 | ops_memory_t *mem; |
|---|
| | 155 | |
|---|
| | 156 | unsigned char *in=ops_mallocz(MAXBUF); |
|---|
| | 157 | int rtn=0; |
|---|
| | 158 | |
|---|
| | 159 | // create test data buffer |
|---|
| | 160 | create_testdata("literal data packet data", &in[0], MAXBUF); |
|---|
| | 161 | |
|---|
| | 162 | /* |
|---|
| | 163 | * initialise needed structures for writing into memory |
|---|
| | 164 | */ |
|---|
| | 165 | |
|---|
| | 166 | init_for_memory_write(&cinfo,&mem); |
|---|
| | 167 | |
|---|
| | 168 | /* |
|---|
| | 169 | * create literal data packet |
|---|
| | 170 | */ |
|---|
| | 171 | ops_write_literal_data(in,MAXBUF,OPS_LDT_BINARY,cinfo); |
|---|
| | 172 | |
|---|
| | 173 | /* |
|---|
| | 174 | * initialise needed structures for reading from memory |
|---|
| | 175 | */ |
|---|
| | 176 | |
|---|
| | 177 | init_for_memory_read(&pinfo,mem,callback); |
|---|
| | 178 | |
|---|
| | 179 | // and parse it |
|---|
| | 180 | |
|---|
| | 181 | ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); |
|---|
| | 182 | rtn=ops_parse(pinfo); |
|---|
| | 183 | |
|---|
| | 184 | /* |
|---|
| | 185 | * test it's the same |
|---|
| | 186 | */ |
|---|
| | 187 | |
|---|
| | 188 | CU_ASSERT(memcmp(data,in,MAXBUF)==0); |
|---|
| | 189 | |
|---|
| | 190 | // cleanup |
|---|
| | 191 | ops_memory_free(mem); |
|---|
| | 192 | free (in); |
|---|
| | 193 | } |
|---|
| | 194 | |
|---|