Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
static
GQueue *split_message(const struct session *sess, const gchar *text, const gchar *event) {
    GQueue *list   = g_queue_new();
    gchar *nick    = g_strdup(sess->server->nick);
    gchar *target  = g_strdup(sess->channel);
    gchar *host, *temp;
    gchar *tempstr = "\0";
    gint len;
    gchar *note_stop = g_strdup(prefs.text_overflow_stop);
    gint stop_len    = strlen(note_stop);

    /*
     * build the base string so we know how many bytes to subtract from the
     * absolute maximum imposed by the IRC standard
     */
    if (sess->me && sess->me->hostname) {
        host = g_strdup(sess->me->hostname);
        temp = g_strdup_printf(":%s!%s@%s %s %s :", nick, prefs.username, host, event, target);
        len  = strlen(temp) + 9; /* this is for CTCP ACTION */
    } else {
        /*
         * we don't have a hostname, for some reason, so just assume
         * it's a maximum of 64 chars
         */
        temp = g_strdup_printf(":%s!%s@%s %s %s :", nick, prefs.username, "", event, target);
        len  = strlen(temp) + 9 + 64; /* this is for CTCP ACTION */
    }

    g_free(temp);

    /*
     * iterate through the string and push each segment onto a list so we can
     * later send them out one at a time.
     */
    while ((strlen(text) + len + stop_len) > IRC_MAX_LENGTH-1) {
        tempstr = g_strrstr_len(text, IRC_MAX_LENGTH - (len + stop_len), " ");
        temp = g_strndup(text, tempstr-text);
        g_queue_push_tail(list, g_strconcat(temp, " ", note_stop, NULL));
        text = tempstr;
    }
    g_queue_push_tail(list, g_strdup(text));

    return list;
}