804 i += q_decoding_len; |
804 i += q_decoding_len; |
805 |
805 |
806 // Source EID length SDNV |
806 // Source EID length SDNV |
807 if ( (q_decoding_len = sdnv_decode (&(buf[i]), |
807 if ( (q_decoding_len = sdnv_decode (&(buf[i]), |
808 buf_len - i, |
808 buf_len - i, |
809 &(bpq->original_id.source_len))) == -1 ) { |
809 (u_int64_t*)&(bpq->original_id.source_len))) == -1 ) { |
810 fprintf (stderr, "Error decoding source EID length\n"); |
810 fprintf (stderr, "Error decoding source EID length\n"); |
811 return -1; |
811 return -1; |
812 } |
812 } |
813 i += q_decoding_len; |
813 i += q_decoding_len; |
814 |
814 |
815 // Source EID n-bytes |
815 // Source EID n-bytes |
816 if (i<buf_len && bpq->original_id.source_len <= DTN_MAX_ENDPOINT_ID) { |
816 if (i<buf_len && bpq->original_id.source_len <= DTN_MAX_ENDPOINT_ID) { |
817 strncpy(bpq->original_id.source.uri, &(buf[i]), bpq->original_id.source_len); |
817 strncpy(bpq->original_id.source.uri, (char*)&(buf[i]), bpq->original_id.source_len); |
818 i += bpq->original_id.source_len; |
818 i += bpq->original_id.source_len; |
819 } else { |
819 } else { |
820 fprintf (stderr, "Error copying source EID\n"); |
820 fprintf (stderr, "Error copying source EID\n"); |
821 return -1; |
821 return -1; |
822 } |
822 } |
823 |
823 |
824 // BPQ-value-length SDNV |
824 // BPQ-value-length SDNV |
825 if ( (q_decoding_len = sdnv_decode (&(buf[i]), |
825 if ( (q_decoding_len = sdnv_decode (&(buf[i]), |
826 buf_len - i, |
826 buf_len - i, |
827 &(bpq->query.query_len))) == -1 ) { |
827 (u_int64_t*)&(bpq->query.query_len))) == -1 ) { |
828 fprintf (stderr, "Error decoding BPQ-value-length\n"); |
828 fprintf (stderr, "Error decoding BPQ-value-length\n"); |
829 return -1; |
829 return -1; |
830 } |
830 } |
831 i += q_decoding_len; |
831 i += q_decoding_len; |
832 |
832 |
833 // BPQ-value n-bytes |
833 // BPQ-value n-bytes |
834 if (i<buf_len) bpq->query.query_val = &(buf[i]); |
834 if (i<buf_len) bpq->query.query_val = (char*)&(buf[i]); |
835 i += bpq->query.query_len; |
835 i += bpq->query.query_len; |
836 |
836 |
837 |
837 |
838 // number of fragments SDNV |
838 // number of fragments SDNV |
839 if ( (f_decoding_len = sdnv_decode (&(buf[i]), |
839 if ( (f_decoding_len = sdnv_decode (&(buf[i]), |
840 buf_len - i, |
840 buf_len - i, |
841 &(bpq->fragments.num_frag_returned))) == -1 ) { |
841 (u_int64_t*)&(bpq->fragments.num_frag_returned))) == -1 ) { |
842 fprintf (stderr, "Error decoding number of fragments\n"); |
842 fprintf (stderr, "Error decoding number of fragments\n"); |
843 return -1; |
843 return -1; |
844 } |
844 } |
845 i += f_decoding_len; |
845 i += f_decoding_len; |
846 |
846 |
847 for (j=0; i<buf_len && j<bpq->fragments.num_frag_returned; ++j) { |
847 for (j=0; i<buf_len && j<bpq->fragments.num_frag_returned; ++j) { |
848 |
848 |
849 // fragment offsets SDNV |
849 // fragment offsets SDNV |
850 if ( (decoding_len = sdnv_decode (&(buf[i]), |
850 if ( (decoding_len = sdnv_decode (&(buf[i]), |
851 buf_len - i, |
851 buf_len - i, |
852 &(bpq->fragments.frag_offsets[j]))) == -1 ) { |
852 (u_int64_t*)&(bpq->fragments.frag_offsets[j]))) == -1 ) { |
853 fprintf (stderr, "Error decoding fragment[%d] offset\n", j); |
853 fprintf (stderr, "Error decoding fragment[%d] offset\n", j); |
854 return -1; |
854 return -1; |
855 } |
855 } |
856 i += decoding_len; |
856 i += decoding_len; |
857 |
857 |
858 // fragment lengths SDNV |
858 // fragment lengths SDNV |
859 if ( (decoding_len = sdnv_decode (&(buf[i]), |
859 if ( (decoding_len = sdnv_decode (&(buf[i]), |
860 buf_len - i, |
860 buf_len - i, |
861 &(bpq->fragments.frag_lenghts[j]))) == -1 ) { |
861 (u_int64_t*)&(bpq->fragments.frag_lenghts[j]))) == -1 ) { |
862 fprintf (stderr, "Error decoding fragment[%d] length\n", j); |
862 fprintf (stderr, "Error decoding fragment[%d] length\n", j); |
863 return -1; |
863 return -1; |
864 } |
864 } |
865 i += decoding_len; |
865 i += decoding_len; |
866 } |
866 } |
878 fprintf (stdout, " creation ts seq: %d\n", |
878 fprintf (stdout, " creation ts seq: %d\n", |
879 (int) bpq->original_id.creation_ts.seqno); |
879 (int) bpq->original_id.creation_ts.seqno); |
880 fprintf (stdout, " source eid len: %d\n", |
880 fprintf (stdout, " source eid len: %d\n", |
881 (int) bpq->original_id.source_len); |
881 (int) bpq->original_id.source_len); |
882 fprintf (stdout, " source eid: %s\n", |
882 fprintf (stdout, " source eid: %s\n", |
883 (int) bpq->original_id.source.uri); |
883 bpq->original_id.source.uri); |
884 |
884 |
885 fprintf (stdout, " query len: %d\n", bpq->query.query_len); |
885 fprintf (stdout, " query len: %d\n", bpq->query.query_len); |
886 fprintf (stdout, " q_decoding_len: %d\n", q_decoding_len); |
886 fprintf (stdout, " q_decoding_len: %d\n", q_decoding_len); |
887 fprintf (stdout, " query val: %s\n", bpq->query.query_val); |
887 fprintf (stdout, " query val: %s\n", bpq->query.query_val); |
888 |
888 |
928 memset(&payload, 0, sizeof(dtn_bundle_payload_t)); |
928 memset(&payload, 0, sizeof(dtn_bundle_payload_t)); |
929 |
929 |
930 // set the bpq block data |
930 // set the bpq block data |
931 bpq_block_data.kind = BPQ_BLOCK_KIND_QUERY; |
931 bpq_block_data.kind = BPQ_BLOCK_KIND_QUERY; |
932 bpq_block_data.matching_rule = matching_rule; |
932 bpq_block_data.matching_rule = matching_rule; |
|
933 |
|
934 bpq_block_data.original_id.creation_ts.secs = 0; |
|
935 bpq_block_data.original_id.creation_ts.seqno = 0; |
|
936 bpq_block_data.original_id.source = *src_eid; |
|
937 bpq_block_data.original_id.source_len = strlen(src_eid->uri); |
|
938 |
933 bpq_block_data.query.query_len = strlen(query) + 1; // include the null char at the end |
939 bpq_block_data.query.query_len = strlen(query) + 1; // include the null char at the end |
934 bpq_block_data.query.query_val = query; |
940 bpq_block_data.query.query_val = query; |
935 bpq_block_data.fragments.num_frag_returned = 0; |
941 bpq_block_data.fragments.num_frag_returned = 0; |
936 bpq_block_data.fragments.frag_offsets = NULL; |
942 bpq_block_data.fragments.frag_offsets = NULL; |
937 bpq_block_data.fragments.frag_lenghts = NULL; |
943 bpq_block_data.fragments.frag_lenghts = NULL; |