* Gets the rtp stats and tries to store them in a context, if that's possible * Returns: * 1: success, stored in ctx and/or taken from ctx * 0: query ok, but didn't get to save the buffer in ctx * -1: failure */
| 4108 | * -1: failure |
| 4109 | */ |
| 4110 | static int rtpe_fetch_stats(struct sip_msg *msg, bencode_buffer_t *retbuf, bencode_item_t **retdict) |
| 4111 | { |
| 4112 | /* we need a ctx */ |
| 4113 | struct rtpe_ctx *ctx; |
| 4114 | bencode_item_t *dict; |
| 4115 | static bencode_buffer_t bencbuf; |
| 4116 | |
| 4117 | /* caching mechanism for statistics */ |
| 4118 | ctx = rtpe_ctx_get(); |
| 4119 | if (ctx) { |
| 4120 | /* allocate stats now */ |
| 4121 | if (ctx->stats) { |
| 4122 | if (!ctx->stats->dict) /* there was a previous run and resulted in an error */ |
| 4123 | return -1; |
| 4124 | *retbuf = ctx->stats->buf; |
| 4125 | *retdict = ctx->stats->dict; |
| 4126 | return 1; |
| 4127 | } |
| 4128 | ctx->stats = pkg_malloc(sizeof *ctx->stats); |
| 4129 | if (!ctx->stats) { |
| 4130 | LM_ERR("not enough pkg for stats!\n"); |
| 4131 | /* cannot store stats */ |
| 4132 | ctx = NULL; |
| 4133 | } else { |
| 4134 | memset(ctx->stats, 0, sizeof *ctx->stats); |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | dict = rtpe_function_call_ok(&bencbuf, msg, OP_QUERY, |
| 4139 | NULL, NULL, NULL, NULL, NULL, NULL); |
| 4140 | if (!dict) |
| 4141 | return -1; |
| 4142 | |
| 4143 | /* if thers's no ctx, we make the request on the spot, but we don't save |
| 4144 | * the reply, because we don't have where */ |
| 4145 | if (ctx) { |
| 4146 | ctx->stats->buf = bencbuf; |
| 4147 | ctx->stats->dict = dict; |
| 4148 | *retbuf = bencbuf; |
| 4149 | *retdict = dict; |
| 4150 | return 1; |
| 4151 | } else { |
| 4152 | *retbuf = bencbuf; |
| 4153 | *retdict = dict; |
| 4154 | return 0; |
| 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | /* |
| 4159 | * Returns the current RTP-Statistics from the RTP-Proxy |
no test coverage detected