Browse Source

TT#91150 abstractise NG protocol handling

Change-Id: If00eede6803d9618c32dccbdcf82f5e41b64b2bf
pull/1093/head
Richard Fuchs 5 years ago
parent
commit
e662b596f8
2 changed files with 37 additions and 18 deletions
  1. +34
    -18
      daemon/control_ng.c
  2. +3
    -0
      include/control_ng.h

+ 34
- 18
daemon/control_ng.c View File

@ -101,7 +101,7 @@ static void pretty_print(bencode_item_t *el, GString *s) {
} }
} }
struct control_ng_stats* get_control_ng_stats(struct control_ng* c, const sockaddr_t *addr) {
struct control_ng_stats* get_control_ng_stats(const sockaddr_t *addr) {
struct control_ng_stats* cur; struct control_ng_stats* cur;
mutex_lock(&rtpe_cngs_lock); mutex_lock(&rtpe_cngs_lock);
@ -116,25 +116,23 @@ struct control_ng_stats* get_control_ng_stats(struct control_ng* c, const sockad
return cur; return cur;
} }
static void control_ng_incoming(struct obj *obj, str *buf, const endpoint_t *sin, char *addr,
socket_t *ul)
int control_ng_process(str *buf, const endpoint_t *sin, char *addr,
void (*cb)(str *, str *, const endpoint_t *, void *), void *p1)
{ {
struct control_ng *c = (void *) obj;
bencode_buffer_t bencbuf; bencode_buffer_t bencbuf;
bencode_item_t *dict, *resp; bencode_item_t *dict, *resp;
str cmd = STR_NULL, cookie, data, reply, *to_send, callid; str cmd = STR_NULL, cookie, data, reply, *to_send, callid;
const char *errstr, *resultstr; const char *errstr, *resultstr;
struct iovec iov[3];
unsigned int iovlen;
GString *log_str; GString *log_str;
struct timeval cmd_start, cmd_stop, cmd_process_time; struct timeval cmd_start, cmd_stop, cmd_process_time;
struct control_ng_stats* cur = get_control_ng_stats(c,&sin->address);
struct control_ng_stats* cur = get_control_ng_stats(&sin->address);
int funcret = -1;
str_chr_str(&data, buf, ' '); str_chr_str(&data, buf, ' ');
if (!data.s || data.s == buf->s) { if (!data.s || data.s == buf->s) {
ilog(LOG_WARNING, "Received invalid data on NG port (no cookie) from %s: " STR_FORMAT_M, ilog(LOG_WARNING, "Received invalid data on NG port (no cookie) from %s: " STR_FORMAT_M,
addr, STR_FMT_M(buf)); addr, STR_FMT_M(buf));
return;
return funcret;
} }
int ret = bencode_buffer_init(&bencbuf); int ret = bencode_buffer_init(&bencbuf);
@ -336,16 +334,8 @@ send_resp:
} }
send_only: send_only:
iovlen = 3;
iov[0].iov_base = cookie.s;
iov[0].iov_len = cookie.len;
iov[1].iov_base = " ";
iov[1].iov_len = 1;
iov[2].iov_base = to_send->s;
iov[2].iov_len = to_send->len;
socket_sendiov(ul, iov, iovlen, sin);
funcret = 0;
cb(&cookie, to_send, sin, p1);
if (resp) if (resp)
cookie_cache_insert(&ng_cookie_cache, &cookie, &reply); cookie_cache_insert(&ng_cookie_cache, &cookie, &reply);
@ -357,6 +347,32 @@ send_only:
out: out:
bencode_buffer_free(&bencbuf); bencode_buffer_free(&bencbuf);
log_info_clear(); log_info_clear();
return funcret;
}
static void control_ng_send(str *cookie, str *body, const endpoint_t *sin, void *p1) {
socket_t *ul = p1;
struct iovec iov[3];
unsigned int iovlen;
iovlen = 3;
iov[0].iov_base = cookie->s;
iov[0].iov_len = cookie->len;
iov[1].iov_base = " ";
iov[1].iov_len = 1;
iov[2].iov_base = body->s;
iov[2].iov_len = body->len;
socket_sendiov(ul, iov, iovlen, sin);
}
static void control_ng_incoming(struct obj *obj, str *buf, const endpoint_t *sin, char *addr,
socket_t *ul)
{
control_ng_process(buf, sin, addr, control_ng_send, ul);
} }


+ 3
- 0
include/control_ng.h View File

@ -4,6 +4,7 @@
#include "obj.h" #include "obj.h"
#include "udp_listener.h" #include "udp_listener.h"
#include "socket.h" #include "socket.h"
#include "str.h"
struct poller; struct poller;
@ -40,6 +41,8 @@ struct control_ng {
struct control_ng *control_ng_new(struct poller *, endpoint_t *, unsigned char); struct control_ng *control_ng_new(struct poller *, endpoint_t *, unsigned char);
void control_ng_init(void); void control_ng_init(void);
void control_ng_cleanup(void); void control_ng_cleanup(void);
int control_ng_process(str *buf, const endpoint_t *sin, char *addr,
void (*cb)(str *, str *, const endpoint_t *, void *), void *p1);
extern mutex_t rtpe_cngs_lock; extern mutex_t rtpe_cngs_lock;
extern GHashTable *rtpe_cngs_hash; extern GHashTable *rtpe_cngs_hash;


Loading…
Cancel
Save