#include <stdlib.h>
#include "log.h"
+#include "memory.h"
#include "list.h"
#include "client.h"
#include "messages.h"
sendmsg->payload.channelState->channel_id = ch_itr->id;
sendmsg->payload.channelState->n_links = ch_itr->linkcount;
- links = (uint32_t *)malloc(ch_itr->linkcount * sizeof(uint32_t));
+ links = (uint32_t*)Memory_safeMalloc(
+ ch_itr->linkcount,
+ sizeof(uint32_t));
list_iterate(itr, &ch_itr->channel_links) { /* Iterate links */
+ channellist_t *chl;
channel_t *ch;
- ch = list_get_entry(itr, channel_t, link_node);
+ chl = list_get_entry(itr, channellist_t, node);
+ ch = chl->chan;
links[i++] = ch->id;
}
sendmsg->payload.channelState->links = links;
sendmsg->payload.userState->session = client->sessionId;
sendmsg->payload.userState->name = strdup(client->username);
sendmsg->payload.userState->has_channel_id = true;
- sendmsg->payload.userState->channel_id = ((channel_t *)client->channel)->id;
+ sendmsg->payload.userState->channel_id = client->channel->id;
if (defaultChan->silent) {
sendmsg->payload.userState->has_suppress = true;
sendmsg->payload.userState->session = client_itr->sessionId;
sendmsg->payload.userState->name = strdup(client_itr->username);
sendmsg->payload.userState->has_channel_id = true;
- sendmsg->payload.userState->channel_id = ((channel_t *)client_itr->channel)->id;
- sendmsg->payload.userState->has_suppress = ((channel_t *)client_itr->channel)->silent;
- sendmsg->payload.userState->suppress = ((channel_t *)client_itr->channel)->silent;
+ sendmsg->payload.userState->channel_id = client_itr->channel->id;
+ sendmsg->payload.userState->has_suppress = client_itr->channel->silent;
+ sendmsg->payload.userState->suppress = client_itr->channel->silent;
- client_itr->isSuppressed = ((channel_t *)client_itr->channel)->silent;
+ client_itr->isSuppressed = client_itr->channel->silent;
if (client_itr->self_deaf) {
sendmsg->payload.userState->has_self_deaf = true;
char *message;
uint32_t *tree_id;
- message = malloc(strlen(client->username) + 32);
- if (!message)
- Log_fatal("Out of memory");
- tree_id = malloc(sizeof(uint32_t));
- if (!tree_id)
- Log_fatal("Out of memory");
+ message = Memory_safeMalloc(1, strlen(client->username) + 32);
+ tree_id = Memory_safeMalloc(1, sizeof(uint32_t));
*tree_id = 0;
sendmsg = Msg_create(TextMessage);
sendmsg->payload.textMessage->message = message;
}
}
if (msg->payload.userState->has_plugin_context) {
- if (client->context)
- free(client->context);
- client->context = malloc(msg->payload.userState->plugin_context.len);
- if (client->context == NULL)
- Log_fatal("Out of memory");
+ free(client->context);
+ client->context = Memory_safeMalloc(1, msg->payload.userState->plugin_context.len);
memcpy(client->context, msg->payload.userState->plugin_context.data,
msg->payload.userState->plugin_context.len);
Log_debug("Client version 0x%x", client->version);
}
if (msg->payload.version->release) {
- if (client->release) free(client->release);
+ free(client->release);
client->release = strdup(msg->payload.version->release);
Log_debug("Client release %s", client->release);
}
if (msg->payload.version->os) {
- if (client->os) free(client->os);
+ free(client->os);
client->os = strdup(msg->payload.version->os);
Log_debug("Client OS %s", client->os);
}
if (msg->payload.version->os_version) {
- if (client->os_version) free(client->os_version);
+ free(client->os_version);
client->os_version = strdup(msg->payload.version->os_version);
Log_debug("Client OS version %s", client->os_version);
}
sendmsg->payload.userStats->version->os_version = strdup(target->os_version);
sendmsg->payload.userStats->n_celt_versions = target->codec_count;
- sendmsg->payload.userStats->celt_versions = malloc(sizeof(int32_t) * target->codec_count);
- if (!sendmsg->payload.userStats->celt_versions)
- Log_fatal("Out of memory");
+ sendmsg->payload.userStats->celt_versions
+ = Memory_safeMalloc(target->codec_count, sizeof(int32_t));
i = 0;
while (Client_codec_iterate(target, &codec_itr) != NULL)
sendmsg->payload.userStats->celt_versions[i++] = codec_itr->codec;
sendmsg->payload.userStats->opus = target->bOpus;
/* Address */
- sendmsg->payload.userStats->has_address = true;
- sendmsg->payload.userStats->address.data = malloc(sizeof(uint8_t) * 16);
- if (!sendmsg->payload.userStats->address.data)
- Log_fatal("Out of memory");
- memset(sendmsg->payload.userStats->address.data, 0, 16);
- /* ipv4 representation as ipv6 address. Supposedly correct. */
- memset(&sendmsg->payload.userStats->address.data[10], 0xff, 2); /* IPv4 */
- if(target->remote_tcp.ss_family == AF_INET)
- memcpy(&sendmsg->payload.userStats->address.data[12], &((struct sockaddr_in*)&target->remote_tcp)->sin_addr, 4);
- else
- memcpy(&sendmsg->payload.userStats->address.data[0], &((struct sockaddr_in6*)&target->remote_tcp)->sin6_addr, 16);
- sendmsg->payload.userStats->address.len = 16;
+ if (getBoolConf(SHOW_ADDRESSES)) {
+ sendmsg->payload.userStats->has_address = true;
+ sendmsg->payload.userStats->address.data
+ = Memory_safeMalloc(16, sizeof(uint8_t));
+ memset(sendmsg->payload.userStats->address.data, 0, 16);
+ /* ipv4 representation as ipv6 address. Supposedly correct. */
+ memset(&sendmsg->payload.userStats->address.data[10], 0xff, 2); /* IPv4 */
+ if(target->remote_tcp.ss_family == AF_INET)
+ memcpy(&sendmsg->payload.userStats->address.data[12], &((struct sockaddr_in*)&target->remote_tcp)->sin_addr, 4);
+ else
+ memcpy(&sendmsg->payload.userStats->address.data[0], &((struct sockaddr_in6*)&target->remote_tcp)->sin6_addr, 16);
+ sendmsg->payload.userStats->address.len = 16;
+ } else {
+ sendmsg->payload.userStats->has_address = false;
+ }
}
/* BW */
sendmsg->payload.userStats->has_bandwidth = true;