-
Notifications
You must be signed in to change notification settings - Fork 1
/
sr_consume.h
121 lines (95 loc) · 2.99 KB
/
sr_consume.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* vim:set ft=c ts=4 sw=2 sts=2 et cindent: */
/*
* Usage info after license block.
*
* This code is by Peter Silva copyright (c) 2017 part of MetPX.
* copyright is to the Government of Canada. code is GPL.
*
* based on a amqp_sendstring from rabbitmq-c package
* the original license is below:
*/
/*
Minimal c implementation to allow posting of sr_post(7) messages.
call an sr_context_init to set things up.
then sr_post will post files,
then sr_close to tear the connection down.
there is an all in one function: connect_and_post that does all of the above.
*/
#ifndef SR_CONSUME_H
#define SR_CONSUME_H 1
/*
picking a maximum message size to create a static buffer.
There is no maximum defined for Sarracenia. Maximum message size varies
by broker implementation, so using extraordinarily large messages is risky.
in v03 there is content embedding to satisfy WMO ET-CTS, so the messages
can be bigger. probably not a good idea in practice.
*/
#define SR_SARRAC_MAXIMUM_MESSAGE_LEN (1024*1024)
#include "sr_context.h"
struct sr_message_s {
char atime[SR_TIMESTRLEN];
char datestamp[SR_TIMESTRLEN];
char exchange[AMQP_MAX_SS];
char link[PATH_MAXNUL];
int mode;
char mtime[SR_TIMESTRLEN];
char parts_s;
long parts_blksz;
long parts_blkcount;
long parts_rem;
long parts_num;
char relPath[PATH_MAXNUL];
char queue[AMQP_MAX_SS];
char rename[PATH_MAXNUL];
char routing_key[AMQP_MAX_SS];
char source[AMQP_MAX_SS];
char sum[SR_SUMSTRLEN];
char url[PATH_MAXNUL];
struct sr_header_s *user_headers;
// sr_report(7) fields.
float duration;
char consumingurl[PATH_MAXNUL];
char consuminguser[PATH_MAXNUL];
int statuscode;
};
char *v03identity(struct sr_message_s *m);
//extern struct sr_message_s msg;
bool sr_consume_setup(struct sr_context *sr_c);
/*
declare and bind queue over a connection already established by context_init
return: 1 on success, 0 on failure.
*/
int sr_consume_cleanup(struct sr_context *sr_c);
/*
delete queue declared by setup.
*/
char *sr_message_partstr(struct sr_message_s *m);
/*
return the parts string for an sr_message given the message structure.
*/
char *sr_message_2log(struct sr_message_s *m);
/*
make a string in the format for log messages.
*/
void sr_message_2json(struct sr_message_s *m);
/*
print a message to stdout, the entire thing, in json save/restore format.
*/
void sr_message_2url(struct sr_message_s *m);
/*
print a message to stdout, just the pathname to stdout.
*/
#define SR_CONSUME_BROKEN (struct sr_message_s *)(0x37)
struct sr_message_s *sr_consume(struct sr_context *sr_c);
/*
* return value:
* * pointer to struct of the message received.
* * NULL - connection is good, no message currently available.
* * SR_CONSUME_BROKEN: connection is bad, restart.
*/
bool sr_message_valid(struct sr_log_context_s *logctx, struct sr_message_s *m);
/*
* return True if the message passes validity tests (so will be properly processed.)
* may print messages about formatting errors.
*/
#endif