loudmouth/lm-misc.c
author psykose <alice@ayaya.dev>
Thu, 21 Apr 2022 20:23:32 +0200
changeset 744 4ebe32453682
parent 690 7ccf2113ec5f
permissions -rw-r--r--
fix macro define for freeaddrinfo with asyncns previously, this define was only made in lm-asyncns-resolver.c, which does not propagate it to lm-resolver.c, where freeaddrinfo() is used. this means that when asyncns support is used, the standard libc freeaddrinfo() is called on an addrinfo acquired from asyncns_getaddrinfo, which is undefined behaviour, and leads to a segfault on musl libc.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
516
4dd3aa6b83e5 Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents: 515
diff changeset
     1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     2
/*
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     3
 * Copyright (C) 2006 Imendio AB
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     4
 *
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public License as
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     7
 * published by the Free Software Foundation; either version 2 of the
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     8
 * License, or (at your option) any later version.
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     9
 *
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    13
 * Lesser General Public License for more details.
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    14
 *
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public
690
7ccf2113ec5f Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
    16
 * License along with this program; if not, see <https://www.gnu.org/licenses>
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    17
 */
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    18
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    19
#include <config.h>
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    20
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    21
#include <string.h>
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    22
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    23
#include "lm-misc.h"
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    24
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    25
static void
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    26
misc_setup_source (GMainContext *context,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    27
                   GSource      *source,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    28
                   GSourceFunc   function,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    29
                   gpointer      data)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    30
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    31
    g_source_set_callback (source, (GSourceFunc)function, data, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    32
    g_source_attach (source, context);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    33
    g_source_unref (source);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    34
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    35
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    36
GSource *
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    37
lm_misc_add_io_watch (GMainContext *context,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    38
                      GIOChannel   *channel,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    39
                      GIOCondition  condition,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    40
                      GIOFunc       function,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    41
                      gpointer      data)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    42
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    43
    GSource *source;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    44
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    45
    g_return_val_if_fail (channel != NULL, 0);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    46
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    47
    source = g_io_create_watch (channel, condition);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    48
    misc_setup_source (context, source, (GSourceFunc) function, data);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    49
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    50
    return source;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    51
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    52
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    53
GSource *
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    54
lm_misc_add_idle (GMainContext *context,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    55
                  GSourceFunc   function,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    56
                  gpointer      data)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    57
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    58
    GSource *source;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    59
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    60
    g_return_val_if_fail (function != NULL, 0);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    61
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    62
    source = g_idle_source_new ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    63
    misc_setup_source (context, source, function, data);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    64
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    65
    return source;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    66
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    67
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    68
GSource *
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    69
lm_misc_add_timeout (GMainContext *context,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    70
                     guint         interval,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    71
                     GSourceFunc   function,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    72
                     gpointer      data)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    73
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    74
    GSource *source;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    75
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    76
    g_return_val_if_fail (function != NULL, 0);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    77
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    78
    source = g_timeout_source_new (interval);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    79
    misc_setup_source (context, source, function, data);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    80
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    81
    return source;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    82
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    83
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    84
const char *
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    85
lm_misc_io_condition_to_str  (GIOCondition condition)
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    86
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    87
    static char buf[256];
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    88
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    89
    buf[0] = '\0';
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    90
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    91
    if(condition & G_IO_ERR)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    92
        strcat(buf, "G_IO_ERR ");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    93
    if(condition & G_IO_HUP)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    94
        strcat(buf, "G_IO_HUP ");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    95
    if(condition & G_IO_NVAL)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    96
        strcat(buf, "G_IO_NVAL ");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    97
    if(condition & G_IO_IN)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    98
        strcat(buf, "G_IO_IN ");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    99
    if(condition & G_IO_OUT)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   100
        strcat(buf, "G_IO_OUT ");
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   101
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   102
    return buf;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   103
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   104