comparison stream/pnm.c @ 25696:f159db1e77db

Use sizeof instead of size variables/defines
author reimar
date Sun, 13 Jan 2008 12:53:24 +0000
parents 33972bac0c16
children 43d2ca88edc1
comparison
equal deleted inserted replaced
25695:33972bac0c16 25696:f159db1e77db
120 #define PREAMBLE_SIZE 8 120 #define PREAMBLE_SIZE 8
121 #define CHECKSUM_SIZE 3 121 #define CHECKSUM_SIZE 3
122 122
123 123
124 /* header of rm files */ 124 /* header of rm files */
125 #define RM_HEADER_SIZE 0x12
126 static const unsigned char rm_header[]={ 125 static const unsigned char rm_header[]={
127 0x2e, 0x52, 0x4d, 0x46, /* object_id ".RMF" */ 126 0x2e, 0x52, 0x4d, 0x46, /* object_id ".RMF" */
128 0x00, 0x00, 0x00, 0x12, /* header_size 0x12 */ 127 0x00, 0x00, 0x00, 0x12, /* header_size 0x12 */
129 0x00, 0x00, /* object_version 0x00 */ 128 0x00, 0x00, /* object_version 0x00 */
130 0x00, 0x00, 0x00, 0x00, /* file_version 0x00 */ 129 0x00, 0x00, 0x00, 0x00, /* file_version 0x00 */
131 0x00, 0x00, 0x00, 0x06 /* num_headers 0x06 */ 130 0x00, 0x00, 0x00, 0x06 /* num_headers 0x06 */
132 }; 131 };
133 132
134 /* data chunk header */ 133 /* data chunk header */
135 #define PNM_DATA_HEADER_SIZE 18
136 static const unsigned char pnm_data_header[]={ 134 static const unsigned char pnm_data_header[]={
137 'D','A','T','A', 135 'D','A','T','A',
138 0,0,0,0, /* data chunk size */ 136 0,0,0,0, /* data chunk size */
139 0,0, /* object version */ 137 0,0, /* object version */
140 0,0,0,0, /* num packets */ 138 0,0,0,0, /* num packets */
156 static const unsigned char pnm_timestamp[] = "[15/06/1999:22:22:49 00:00]"; 154 static const unsigned char pnm_timestamp[] = "[15/06/1999:22:22:49 00:00]";
157 static const unsigned char pnm_guid[] = "3eac2411-83d5-11d2-f3ea-d7c3a51aa8b0"; 155 static const unsigned char pnm_guid[] = "3eac2411-83d5-11d2-f3ea-d7c3a51aa8b0";
158 static const unsigned char pnm_response[] = "97715a899cbe41cee00dd434851535bf"; 156 static const unsigned char pnm_response[] = "97715a899cbe41cee00dd434851535bf";
159 static const unsigned char client_string[] = "WinNT_9.0_6.0.6.45_plus32_MP60_en-US_686l"; 157 static const unsigned char client_string[] = "WinNT_9.0_6.0.6.45_plus32_MP60_en-US_686l";
160 158
161 #define PNM_HEADER_SIZE 11
162 static const unsigned char pnm_header[] = { 159 static const unsigned char pnm_header[] = {
163 'P','N','A', 160 'P','N','A',
164 0x00, 0x0a, 161 0x00, 0x0a,
165 0x00, 0x14, 162 0x00, 0x14,
166 0x00, 0x02, 163 0x00, 0x02,
167 0x00, 0x01 }; 164 0x00, 0x01 };
168 165
169 #define PNM_CLIENT_CAPS_SIZE 126
170 static const unsigned char pnm_client_caps[] = { 166 static const unsigned char pnm_client_caps[] = {
171 0x07, 0x8a, 'p','n','r','v', 167 0x07, 0x8a, 'p','n','r','v',
172 0, 0x90, 'p','n','r','v', 168 0, 0x90, 'p','n','r','v',
173 0, 0x64, 'd','n','e','t', 169 0, 0x64, 'd','n','e','t',
174 0, 0x46, 'p','n','r','v', 170 0, 0x46, 'p','n','r','v',
192 188
193 static const uint32_t pnm_default_bandwidth=10485800; 189 static const uint32_t pnm_default_bandwidth=10485800;
194 static const uint32_t pnm_available_bandwidths[]={14400,19200,28800,33600,34430,57600, 190 static const uint32_t pnm_available_bandwidths[]={14400,19200,28800,33600,34430,57600,
195 115200,262200,393216,524300,1544000,10485800}; 191 115200,262200,393216,524300,1544000,10485800};
196 192
197 #define PNM_TWENTYFOUR_SIZE 16
198 static const unsigned char pnm_twentyfour[]={ 193 static const unsigned char pnm_twentyfour[]={
199 0xd5, 0x42, 0xa3, 0x1b, 0xef, 0x1f, 0x70, 0x24, 194 0xd5, 0x42, 0xa3, 0x1b, 0xef, 0x1f, 0x70, 0x24,
200 0x85, 0x29, 0xb3, 0x8d, 0xba, 0x11, 0xf3, 0xd6 }; 195 0x85, 0x29, 0xb3, 0x8d, 0xba, 0x11, 0xf3, 0xd6 };
201 196
202 /* now other data follows. marked with 0x0000 at the beginning */ 197 /* now other data follows. marked with 0x0000 at the beginning */
203 static int after_chunks_length=6;
204 static const unsigned char after_chunks[]={ 198 static const unsigned char after_chunks[]={
205 0x00, 0x00, /* mark */ 199 0x00, 0x00, /* mark */
206 200
207 0x50, 0x84, /* seems to be fixated */ 201 0x50, 0x84, /* seems to be fixated */
208 0x1f, 0x3a /* varies on each request (checksum ?)*/ 202 0x1f, 0x3a /* varies on each request (checksum ?)*/
437 */ 431 */
438 432
439 static void pnm_send_request(pnm_t *p, uint32_t bandwidth) { 433 static void pnm_send_request(pnm_t *p, uint32_t bandwidth) {
440 434
441 uint16_t i16; 435 uint16_t i16;
442 int c=PNM_HEADER_SIZE; 436 int c=sizeof(pnm_header);
443 char fixme[]={0,1}; 437 char fixme[]={0,1};
444 438
445 memcpy(p->buffer,pnm_header,PNM_HEADER_SIZE); 439 memcpy(p->buffer,pnm_header,sizeof(pnm_header));
446 c+=pnm_write_chunk(PNA_CLIENT_CHALLANGE,strlen(pnm_challenge), 440 c+=pnm_write_chunk(PNA_CLIENT_CHALLANGE,strlen(pnm_challenge),
447 pnm_challenge,&p->buffer[c]); 441 pnm_challenge,&p->buffer[c]);
448 c+=pnm_write_chunk(PNA_CLIENT_CAPS,PNM_CLIENT_CAPS_SIZE, 442 c+=pnm_write_chunk(PNA_CLIENT_CAPS,sizeof(pnm_client_caps),
449 pnm_client_caps,&p->buffer[c]); 443 pnm_client_caps,&p->buffer[c]);
450 c+=pnm_write_chunk(0x0a,0,NULL,&p->buffer[c]); 444 c+=pnm_write_chunk(0x0a,0,NULL,&p->buffer[c]);
451 c+=pnm_write_chunk(0x0c,0,NULL,&p->buffer[c]); 445 c+=pnm_write_chunk(0x0c,0,NULL,&p->buffer[c]);
452 c+=pnm_write_chunk(0x0d,0,NULL,&p->buffer[c]); 446 c+=pnm_write_chunk(0x0d,0,NULL,&p->buffer[c]);
453 c+=pnm_write_chunk(0x16,2,fixme,&p->buffer[c]); 447 c+=pnm_write_chunk(0x16,2,fixme,&p->buffer[c]);
462 c+=pnm_write_chunk(0x10,0,NULL,&p->buffer[c]); 456 c+=pnm_write_chunk(0x10,0,NULL,&p->buffer[c]);
463 c+=pnm_write_chunk(0x15,0,NULL,&p->buffer[c]); 457 c+=pnm_write_chunk(0x15,0,NULL,&p->buffer[c]);
464 c+=pnm_write_chunk(0x12,0,NULL,&p->buffer[c]); 458 c+=pnm_write_chunk(0x12,0,NULL,&p->buffer[c]);
465 c+=pnm_write_chunk(PNA_GUID,strlen(pnm_guid), 459 c+=pnm_write_chunk(PNA_GUID,strlen(pnm_guid),
466 pnm_guid,&p->buffer[c]); 460 pnm_guid,&p->buffer[c]);
467 c+=pnm_write_chunk(PNA_TWENTYFOUR,PNM_TWENTYFOUR_SIZE, 461 c+=pnm_write_chunk(PNA_TWENTYFOUR,sizeof(pnm_twentyfour),
468 pnm_twentyfour,&p->buffer[c]); 462 pnm_twentyfour,&p->buffer[c]);
469 463
470 /* data after chunks */ 464 /* data after chunks */
471 memcpy(&p->buffer[c],after_chunks,after_chunks_length); 465 memcpy(&p->buffer[c],after_chunks,sizeof(after_chunks));
472 c+=after_chunks_length; 466 c+=sizeof(after_chunks);
473 467
474 /* client id string */ 468 /* client id string */
475 p->buffer[c]=PNA_CLIENT_STRING; 469 p->buffer[c]=PNA_CLIENT_STRING;
476 i16=BE_16D((strlen(client_string)-1)); /* don't know why do we have -1 here */ 470 i16=BE_16D((strlen(client_string)-1)); /* don't know why do we have -1 here */
477 memcpy(&p->buffer[c+1],&i16,2); 471 memcpy(&p->buffer[c+1],&i16,2);
539 chunk_size=pnm_get_chunk(p,HEADER_SIZE-size,&chunk_type,ptr,&nr); 533 chunk_size=pnm_get_chunk(p,HEADER_SIZE-size,&chunk_type,ptr,&nr);
540 if (chunk_size < 0) return 0; 534 if (chunk_size < 0) return 0;
541 if (chunk_type == 0) break; 535 if (chunk_type == 0) break;
542 if (chunk_type == PNA_TAG) 536 if (chunk_type == PNA_TAG)
543 { 537 {
544 memcpy(ptr, rm_header, RM_HEADER_SIZE); 538 memcpy(ptr, rm_header, sizeof(rm_header));
545 chunk_size=RM_HEADER_SIZE; 539 chunk_size=sizeof(rm_header);
546 *need_response=nr; 540 *need_response=nr;
547 } 541 }
548 if (chunk_type == DATA_TAG) 542 if (chunk_type == DATA_TAG)
549 chunk_size=0; 543 chunk_size=0;
550 if (chunk_type == RMF_TAG) 544 if (chunk_type == RMF_TAG)
571 /* read challenge */ 565 /* read challenge */
572 memcpy (p->buffer, ptr, PREAMBLE_SIZE); 566 memcpy (p->buffer, ptr, PREAMBLE_SIZE);
573 rm_read (p->s, &p->buffer[PREAMBLE_SIZE], 64); 567 rm_read (p->s, &p->buffer[PREAMBLE_SIZE], 64);
574 568
575 /* now write a data header */ 569 /* now write a data header */
576 memcpy(ptr, pnm_data_header, PNM_DATA_HEADER_SIZE); 570 memcpy(ptr, pnm_data_header, sizeof(pnm_data_header));
577 size+=PNM_DATA_HEADER_SIZE; 571 size+=sizeof(pnm_data_header);
578 /* 572 /*
579 h=rmff_scan_header(p->header); 573 h=rmff_scan_header(p->header);
580 rmff_fix_header(h); 574 rmff_fix_header(h);
581 p->header_len=rmff_get_header_size(h); 575 p->header_len=rmff_get_header_size(h);
582 rmff_dump_header(h, p->header, HEADER_SIZE); 576 rmff_dump_header(h, p->header, HEADER_SIZE);