mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Add manifest name to meshmb restful output
This commit is contained in:
parent
8e9877b3ce
commit
eff46c9030
1
httpd.h
1
httpd.h
@ -214,6 +214,7 @@ typedef struct httpd_request
|
||||
size_t rowcount;
|
||||
time_ms_t end_time;
|
||||
time_s_t timestamp;
|
||||
bool_t eof;
|
||||
} plylist;
|
||||
|
||||
struct {
|
||||
|
@ -17,6 +17,7 @@ import java.util.Map;
|
||||
public class MessagePlyList extends AbstractJsonList<PlyMessage, IOException> {
|
||||
private final SigningKey bundleId;
|
||||
private final String sinceToken;
|
||||
private String name;
|
||||
|
||||
public MessagePlyList(ServalDHttpConnectionFactory httpConnector, SigningKey bundleId, String sinceToken){
|
||||
super(httpConnector, new JSONTableScanner()
|
||||
@ -28,6 +29,20 @@ public class MessagePlyList extends AbstractJsonList<PlyMessage, IOException> {
|
||||
this.sinceToken = sinceToken;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void consumeHeader() throws JSONInputException, IOException {
|
||||
Object tok = json.nextToken();
|
||||
if (tok.equals("name")) {
|
||||
json.consume(JSONTokeniser.Token.COLON);
|
||||
name = json.consume(String.class);
|
||||
json.consume(JSONTokeniser.Token.COMMA);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleResponseError() throws IOException, ServalDInterfaceException {
|
||||
// TODO handle specific errors
|
||||
|
@ -142,8 +142,10 @@ static int strn_to_position_token(const char *str, uint64_t *position, const cha
|
||||
|
||||
static int next_ply_message(httpd_request *r){
|
||||
if (!message_ply_is_open(&r->u.plylist.ply_reader)){
|
||||
if (message_ply_read_open(&r->u.plylist.ply_reader, &r->bid)==-1)
|
||||
if (message_ply_read_open(&r->u.plylist.ply_reader, &r->bid)==-1){
|
||||
r->u.plylist.eof = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// skip back to where we were
|
||||
if (r->u.plylist.current_offset)
|
||||
@ -179,6 +181,7 @@ static int next_ply_message(httpd_request *r){
|
||||
break;
|
||||
|
||||
case MESSAGE_BLOCK_TYPE_MESSAGE:
|
||||
r->u.plylist.eof = 0;
|
||||
return 1;
|
||||
|
||||
case MESSAGE_BLOCK_TYPE_ACK:
|
||||
@ -190,6 +193,7 @@ static int next_ply_message(httpd_request *r){
|
||||
break;
|
||||
}
|
||||
}
|
||||
r->u.plylist.eof = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -210,7 +214,17 @@ static int restful_meshmb_list_json_content_chunk(struct http_request *hr, strbu
|
||||
|
||||
switch (r->u.plylist.phase) {
|
||||
case LIST_HEADER:
|
||||
strbuf_puts(b, "{\n\"header\":[");
|
||||
|
||||
strbuf_puts(b, "{\n");
|
||||
|
||||
// open the ply now in order to read the manifest name
|
||||
if (!message_ply_is_open(&r->u.plylist.ply_reader))
|
||||
next_ply_message(r);
|
||||
|
||||
if (r->u.plylist.ply_reader.name)
|
||||
strbuf_sprintf(b, "\"name\":\"%s\",\n", r->u.plylist.ply_reader.name);
|
||||
|
||||
strbuf_puts(b, "\"header\":[");
|
||||
unsigned i;
|
||||
for (i = 0; i != NELS(headers); ++i) {
|
||||
if (i)
|
||||
@ -230,7 +244,8 @@ ROWS:
|
||||
// re-load the current message text
|
||||
if (next_ply_message(r)!=1)
|
||||
goto END;
|
||||
}
|
||||
} else if (r->u.plylist.eof)
|
||||
goto END;
|
||||
|
||||
if (r->u.plylist.rowcount!=0)
|
||||
strbuf_putc(b, ',');
|
||||
|
@ -138,6 +138,8 @@ int message_ply_read_open(struct message_ply_read *ply, const rhizome_bid_t *bid
|
||||
|
||||
assert(m->filesize != RHIZOME_SIZE_UNSET);
|
||||
ply->read.offset = ply->read.length = m->filesize;
|
||||
if (m->name && *m->name)
|
||||
ply->name = str_edup(m->name);
|
||||
ret = 0;
|
||||
}
|
||||
rhizome_manifest_free(m);
|
||||
@ -160,6 +162,10 @@ void message_ply_read_close(struct message_ply_read *ply)
|
||||
free(ply->record);
|
||||
ply->record=NULL;
|
||||
}
|
||||
if (ply->name){
|
||||
free((void*)ply->name);
|
||||
ply->name = NULL;
|
||||
}
|
||||
ply->record_size=0;
|
||||
ply->buff.len=0;
|
||||
rhizome_read_close(&ply->read);
|
||||
|
@ -24,6 +24,8 @@ struct message_ply_read {
|
||||
struct rhizome_read read;
|
||||
// block buffer
|
||||
struct rhizome_read_buffer buff;
|
||||
// copy of the manifest name field
|
||||
const char *name;
|
||||
// details of the current record
|
||||
uint64_t record_end_offset;
|
||||
uint16_t record_length;
|
||||
|
Loading…
Reference in New Issue
Block a user