apps/dtnquery/dtnquery.c
changeset 28 406d4f7eb00d
parent 23 18b4c80456cf
child 32 64b5c8f5be17
equal deleted inserted replaced
27:28b7fb13e35d 28:406d4f7eb00d
    37 // todo: move these out to a header file
    37 // todo: move these out to a header file
    38 #define DTN_BPQ_LITERAL 1
    38 #define DTN_BPQ_LITERAL 1
    39 #define DTN_BPQ_BASE64 2
    39 #define DTN_BPQ_BASE64 2
    40 #define DTN_BPQ_FILE 3
    40 #define DTN_BPQ_FILE 3
    41 
    41 
    42 #define DTN_BPQ_EXACT 1
       
    43 
       
    44 #define DTN_BPQ_SEND 1
    42 #define DTN_BPQ_SEND 1
    45 #define DTN_BPQ_RECV 2
    43 #define DTN_BPQ_RECV 2
    46 #define DTN_BPQ_SEND_RECV 3
    44 #define DTN_BPQ_SEND_RECV 3
    47 
    45 
    48 #define DTN_BPQ_BLOCK_TYPE 0xC8
    46 #define DTN_BPQ_BLOCK_TYPE 0xC8
    49 #define DTN_BPQ_BLOCK_FLAGS 0x00
       
    50 
       
    51 #define DTN_BPQ_KIND_QUERY 0x00
       
    52 #define DTN_BPQ_KIND_RESPONSE 0x01
       
    53 
    47 
    54 // Find the maximum commandline length
    48 // Find the maximum commandline length
    55 #ifdef __FreeBSD__
    49 #ifdef __FreeBSD__
    56 /* Needed for PATH_MAX, Linux doesn't need it */
    50 /* Needed for PATH_MAX, Linux doesn't need it */
    57 #include <sys/syslimits.h>
    51 #include <sys/syslimits.h>
   247                 usage();
   241                 usage();
   248                 exit(1);
   242                 exit(1);
   249             }
   243             }
   250         case 'u':
   244         case 'u':
   251             if (!strcasecmp(optarg, "exact")) {
   245             if (!strcasecmp(optarg, "exact")) {
   252                 *matching_rule = DTN_BPQ_EXACT;
   246                 *matching_rule = BPQ_MATCHING_RULE_EXACT;
   253                 break;
   247                 break;
   254             } else {
   248             } else {
   255                 fprintf(stderr, "invalid query type '%s'\n", optarg);
   249                 fprintf(stderr, "invalid query type '%s'\n", optarg);
   256                 usage();
   250                 usage();
   257                 exit(1);
   251                 exit(1);
   438     }
   432     }
   439     REQUIRE(query_type == DTN_BPQ_LITERAL ||
   433     REQUIRE(query_type == DTN_BPQ_LITERAL ||
   440             query_type == DTN_BPQ_BASE64  ||
   434             query_type == DTN_BPQ_BASE64  ||
   441             query_type == DTN_BPQ_FILE, "-t <query type> invalid type\n");
   435             query_type == DTN_BPQ_FILE, "-t <query type> invalid type\n");
   442 
   436 
   443     REQUIRE(matching_rule == DTN_BPQ_EXACT, "-u <matching rule> invalid rule\n");
   437     REQUIRE(matching_rule == BPQ_MATCHING_RULE_EXACT,
       
   438          "-u <matching rule> invalid rule\n");
   444     REQUIRE(bundle_expiry > 0, "-e <expiry> must be a positive integer\n");
   439     REQUIRE(bundle_expiry > 0, "-e <expiry> must be a positive integer\n");
   445 #undef REQUIRE
   440 #undef REQUIRE
   446 //todo: check this is ok
   441 //todo: check this is ok
   447     return 0;
   442     return 0;
   448 }
   443 }
   778     memset(&bpq_block,      0, sizeof(dtn_extension_block_t));
   773     memset(&bpq_block,      0, sizeof(dtn_extension_block_t));
   779     memset(&bpq_block_data, 0, sizeof(dtn_bpq_extension_block_data_t));
   774     memset(&bpq_block_data, 0, sizeof(dtn_bpq_extension_block_data_t));
   780     memset(&payload,        0, sizeof(dtn_bundle_payload_t));
   775     memset(&payload,        0, sizeof(dtn_bundle_payload_t));
   781     
   776     
   782     // set the bpq block data
   777     // set the bpq block data
   783     bpq_block_data.kind = DTN_BPQ_KIND_QUERY;
   778     bpq_block_data.kind = BPQ_BLOCK_KIND_QUERY;
   784     bpq_block_data.matching_rule = matching_rule;
   779     bpq_block_data.matching_rule = matching_rule;
   785     bpq_block_data.query.query_len = strlen(query) + 1;     // include the null char at the end
   780     bpq_block_data.query.query_len = strlen(query) + 1;     // include the null char at the end
   786     bpq_block_data.query.query_val = query; 
   781     bpq_block_data.query.query_val = query; 
   787     bpq_block_data.fragments.num_frag_returned = 0;
   782     bpq_block_data.fragments.num_frag_returned = 0;
   788     bpq_block_data.fragments.frag_offsets = NULL;
   783     bpq_block_data.fragments.frag_offsets = NULL;
   790 
   785 
   791     buf_len = bpq_to_char_array(&bpq_block_data, buf, PATH_MAX, verbose);
   786     buf_len = bpq_to_char_array(&bpq_block_data, buf, PATH_MAX, verbose);
   792 
   787 
   793     // set the bpq block
   788     // set the bpq block
   794     bpq_block.type = DTN_BPQ_BLOCK_TYPE;
   789     bpq_block.type = DTN_BPQ_BLOCK_TYPE;
   795     bpq_block.flags = DTN_BPQ_BLOCK_FLAGS;
   790     bpq_block.flags = BLOCK_FLAG_REPLICATE;
   796     bpq_block.data.data_len = buf_len;
   791     bpq_block.data.data_len = buf_len;
   797     bpq_block.data.data_val = buf;
   792     bpq_block.data.data_val = buf;
   798     
   793     
   799     // set the payload (empty)
   794     // set the payload (empty)
   800     dtn_set_payload(&payload, DTN_PAYLOAD_MEM, NULL, 0);    
   795     dtn_set_payload(&payload, DTN_PAYLOAD_MEM, NULL, 0);    
   947     char dest_eid_name[PATH_MAX];
   942     char dest_eid_name[PATH_MAX];
   948     char reply_eid_name[PATH_MAX];
   943     char reply_eid_name[PATH_MAX];
   949     char filename[PATH_MAX];
   944     char filename[PATH_MAX];
   950     char query[PATH_MAX];
   945     char query[PATH_MAX];
   951     int query_type = DTN_BPQ_LITERAL;
   946     int query_type = DTN_BPQ_LITERAL;
   952     int matching_rule = DTN_BPQ_EXACT;
   947     int matching_rule = BPQ_MATCHING_RULE_EXACT;
   953     int mode = DTN_BPQ_SEND_RECV;
   948     int mode = DTN_BPQ_SEND_RECV;
   954     int count = 1;
   949     int count = 1;
   955     dtn_timeval_t timeout = DTN_TIMEOUT_INF;    //forever
   950     dtn_timeval_t timeout = DTN_TIMEOUT_INF;    //forever
   956     dtn_timeval_t bundle_expiry = 3600;         //one hour
   951     dtn_timeval_t bundle_expiry = 3600;         //one hour
   957     dtn_reg_id_t regid = DTN_REGID_NONE;
   952     dtn_reg_id_t regid = DTN_REGID_NONE;