mini_parse.c revision 9a690580
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * Convert from our hexdump format to binary: 4 * 5 * perl -p -ne 's/^[[:xdigit:]]+\s+//;s~ \|.*~~;s/\s+//g;s/([[:xdigit:]]{2})/chr hex$1/ge' 6 */ 7 8#include <assert.h> 9#include <stdio.h> 10#include <stdint.h> 11#include <stdlib.h> 12#include <string.h> 13#include <unistd.h> 14 15#include <sys/queue.h> 16#include <sys/types.h> 17#include <sys/stat.h> 18#include <fcntl.h> 19 20#include "lsquic.h" 21#include "lsquic_types.h" 22#include "lsquic_int_types.h" 23#include "lsquic_packet_common.h" 24#include "lsquic_packet_gquic.h" 25#include "lsquic_packet_in.h" 26#include "lsquic_packet_out.h" 27#include "lsquic_mm.h" 28#include "lsquic_hash.h" 29#include "lsquic_conn.h" 30#include "lsquic_rtt.h" 31#include "lsquic_mini_conn.h" 32#include "lsquic_engine_public.h" 33#include "lsquic_util.h" 34#include "lsquic_logger.h" 35#include "lsquic_str.h" 36 37 38int 39lsquic_enc_session_decrypt (void *enc_session_p, enum lsquic_version version, 40 uint8_t path_id, uint64_t pack_num, 41 unsigned char *buf, size_t *header_len, size_t data_len, 42 unsigned char *diversification_nonce, 43 unsigned char *buf_out, size_t max_out_len, size_t *out_len) 44{ 45 memcpy(buf_out, buf, *header_len + data_len); 46 *out_len = data_len; 47 return 0; 48} 49 50 51int 52main (int argc, char **argv) 53{ 54 int opt; 55 int fd = STDIN_FILENO; 56 struct lsquic_engine_public enpub; 57 struct lsquic_conn *lconn; 58 lsquic_packet_in_t packet_in; 59 unsigned char buf[0x1000]; 60 ssize_t packet_sz; 61 enum lsquic_version ver = LSQVER_043; 62 63 memset(&enpub, 0, sizeof(enpub)); 64 lsquic_mm_init(&enpub.enp_mm); 65 66 lsquic_log_to_fstream(stderr, 0); 67 lsq_log_levels[LSQLM_MINI_CONN] = LSQ_LOG_DEBUG; 68 lsq_log_levels[LSQLM_NOMODULE] = LSQ_LOG_DEBUG; 69 70 while (-1 != (opt = getopt(argc, argv, "v:f:h"))) 71 { 72 switch (opt) 73 { 74 case 'v': 75 ver = atoi(optarg); 76 break; 77 case 'f': 78 fd = open(optarg, O_RDONLY); 79 if (fd < 0) 80 { 81 perror("open"); 82 exit(EXIT_FAILURE); 83 } 84 break; 85 case 'h': 86 fprintf(stderr, "usage: %s [-v version] [-f input-file]\n", argv[0]); 87 exit(EXIT_SUCCESS); 88 default: 89 exit(EXIT_FAILURE); 90 } 91 } 92 93 packet_sz = read(fd, buf, sizeof(buf)); 94 if (packet_sz < 0) 95 { 96 perror("read"); 97 exit(EXIT_FAILURE); 98 } 99 100 memset(&packet_in, 0, sizeof(packet_in)); 101 packet_in.pi_packno = 1; 102 packet_in.pi_header_sz = 0; 103 packet_in.pi_data_sz = packet_sz; 104 packet_in.pi_data = buf; 105 packet_in.pi_refcnt = 1; 106 107 lconn = lsquic_mini_conn_new(&enpub, &packet_in, ver); 108 lconn->cn_if->ci_packet_in(lconn, &packet_in); 109 110 exit(EXIT_SUCCESS); 111} 112