01: /*
02: * Copyright (c) 2000 by Matt Welsh and The Regents of the University of
03: * California. All rights reserved.
04: *
05: * Permission to use, copy, modify, and distribute this software and its
06: * documentation for any purpose, without fee, and without written agreement is
07: * hereby granted, provided that the above copyright notice and the following
08: * two paragraphs appear in all copies of this software.
09: *
10: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
11: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
12: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
13: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14: *
15: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
19: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
20: *
21: * Author: Matt Welsh <mdw@cs.berkeley.edu>
22: *
23: */
24:
25: package seda.sandStorm.lib.Gnutella;
26:
27: import java.util.*;
28: import java.io.*;
29: import java.net.*;
30:
31: /**
32: * A Gnutella query hit.
33: */
34: public class GnutellaQueryHit {
35: public int index;
36: public int size;
37: public String filename;
38:
39: //static GnutellaQueryHit[] read(int n, byte payload, int offset) {
40: // int index;
41: // int size;
42: // String fname;
43: // int off = offset;
44: // int num = 0;
45:
46: // while ((off < payload.length-16) && (num < n)) {
47: // index = GnutellaPacket.readLEInt(payload, off); off += 4;
48: // size = GnutellaPacket.readLEInt(payload, off); off += 4;
49: // // Look for double null
50: // int n;
51: // for (n = off; n < payload.length-17; n++) {
52: // if (payload[n] == 0) break;
53: // }
54: // if (payload[n+1] != 0) {
55: // off = n+1; continue;
56: // }
57: // filename = new String(payload, off, n-1);
58: // off = n+2;
59:
60: public GnutellaQueryHit(byte payload[], int offset) {
61: System.err.println("QueryHit: index " + index + ", size "
62: + size + ", fname " + filename);
63: }
64:
65: public GnutellaQueryHit(int index, int size, String filename) {
66: this .index = index;
67: this .size = size;
68: this .filename = filename;
69: }
70:
71: // Return size in bytes
72: int getSize() {
73: // Ends in double-NULL
74: return 8 + filename.length() + 2;
75: }
76:
77: // Dump to given byte array
78: public void dump(byte barr[], int offset) {
79: GnutellaPacket.writeLEInt(index, barr, offset);
80: GnutellaPacket.writeLEInt(size, barr, offset + 4);
81: byte data[] = filename.getBytes();
82: System.arraycopy(data, 0, barr, offset + 8, data.length);
83: barr[offset + 8 + data.length] = (byte) 0;
84: barr[offset + 8 + data.length + 1] = (byte) 0;
85: }
86:
87: }
|