mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-16 02:30:19 +00:00
Replaced GLib allocation helpers in history management with standard free/strdup to reduce unnecessary GLib coupling.
Updated the network helper API to use uint32_t and standard allocation/duplication routines, dropping the GLib include from the implementation and adding <stdint.h> to the header.
This commit is contained in:
@@ -18,14 +18,13 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <glib.h>
|
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
history_add (struct history *his, char *text)
|
history_add (struct history *his, char *text)
|
||||||
{
|
{
|
||||||
g_free (his->lines[his->realpos]);
|
free (his->lines[his->realpos]);
|
||||||
his->lines[his->realpos] = g_strdup (text);
|
his->lines[his->realpos] = strdup (text);
|
||||||
his->realpos++;
|
his->realpos++;
|
||||||
if (his->realpos == HISTORY_SIZE)
|
if (his->realpos == HISTORY_SIZE)
|
||||||
his->realpos = 0;
|
his->realpos = 0;
|
||||||
@@ -40,7 +39,7 @@ history_free (struct history *his)
|
|||||||
{
|
{
|
||||||
if (his->lines[i])
|
if (his->lines[i])
|
||||||
{
|
{
|
||||||
g_free (his->lines[i]);
|
free (his->lines[i]);
|
||||||
his->lines[i] = 0;
|
his->lines[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <glib.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -54,7 +54,7 @@ net_set_socket_options (int sok)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
net_ip (guint32 addr)
|
net_ip (uint32_t addr)
|
||||||
{
|
{
|
||||||
struct in_addr ia;
|
struct in_addr ia;
|
||||||
|
|
||||||
@@ -67,13 +67,13 @@ net_store_destroy (netstore * ns)
|
|||||||
{
|
{
|
||||||
if (ns->ip6_hostent)
|
if (ns->ip6_hostent)
|
||||||
freeaddrinfo (ns->ip6_hostent);
|
freeaddrinfo (ns->ip6_hostent);
|
||||||
g_free (ns);
|
free (ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
netstore *
|
netstore *
|
||||||
net_store_new (void)
|
net_store_new (void)
|
||||||
{
|
{
|
||||||
return g_new0 (netstore, 1);
|
return calloc (1, sizeof (netstore));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =================== IPV6 ================== */
|
/* =================== IPV6 ================== */
|
||||||
@@ -121,11 +121,11 @@ net_resolve (netstore * ns, char *hostname, int port, char **real_host)
|
|||||||
ipstring, sizeof (ipstring), NULL, 0, NI_NUMERICHOST);
|
ipstring, sizeof (ipstring), NULL, 0, NI_NUMERICHOST);
|
||||||
|
|
||||||
if (ns->ip6_hostent->ai_canonname)
|
if (ns->ip6_hostent->ai_canonname)
|
||||||
*real_host = g_strdup (ns->ip6_hostent->ai_canonname);
|
*real_host = strdup (ns->ip6_hostent->ai_canonname);
|
||||||
else
|
else
|
||||||
*real_host = g_strdup (hostname);
|
*real_host = strdup (hostname);
|
||||||
|
|
||||||
return g_strdup (ipstring);
|
return strdup (ipstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the only thing making this interface unclean, this shitty sok4, sok6 business */
|
/* the only thing making this interface unclean, this shitty sok4, sok6 business */
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#ifndef ZOITECHAT_NETWORK_H
|
#ifndef ZOITECHAT_NETWORK_H
|
||||||
#define ZOITECHAT_NETWORK_H
|
#define ZOITECHAT_NETWORK_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef struct netstore_
|
typedef struct netstore_
|
||||||
{
|
{
|
||||||
#ifdef NETWORK_PRIVATE
|
#ifdef NETWORK_PRIVATE
|
||||||
@@ -36,7 +38,7 @@ void net_store_destroy (netstore *ns);
|
|||||||
int net_connect (netstore *ns, int sok4, int sok6, int *sok_return);
|
int net_connect (netstore *ns, int sok4, int sok6, int *sok_return);
|
||||||
char *net_resolve (netstore *ns, char *hostname, int port, char **real_host);
|
char *net_resolve (netstore *ns, char *hostname, int port, char **real_host);
|
||||||
void net_bind (netstore *tobindto, int sok4, int sok6);
|
void net_bind (netstore *tobindto, int sok4, int sok6);
|
||||||
char *net_ip (guint32 addr);
|
char *net_ip (uint32_t addr);
|
||||||
void net_sockets (int *sok4, int *sok6);
|
void net_sockets (int *sok4, int *sok6);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user