aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/call.c
blob: 74da56950009055203bca64f6105dd170a205af3 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * This file is part of libsamsung-ipc.
 *
 * Copyright (C) 2013 Paul Kocialkowsk <contact@paulk.fr>
 * Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
 *
 * libsamsung-ipc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * libsamsung-ipc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with libsamsung-ipc.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdlib.h>
#include <string.h>

#include <samsung-ipc.h>

#define OUTGOING_NUMBER_MAX_LENGTH 86

void ipc_call_outgoing_setup(struct ipc_call_outgoing *message, unsigned char type,
    unsigned char identity, unsigned char prefix, char *number)
{
    int length;

    if (message == NULL || number == NULL)
        return;

    length = strlen(number);
    if (length > OUTGOING_NUMBER_MAX_LENGTH)
        length = OUTGOING_NUMBER_MAX_LENGTH;

    memset(message, 0, sizeof(struct ipc_call_outgoing));

    message->type = type;
    message->identity = identity;
    message->prefix = prefix;
    message->length = length;

    strncpy((char *) message->number, number, length);
}

/* Retrieve number of calls in list of calls */
unsigned int ipc_call_list_response_get_num_entries(struct ipc_message_info *response)
{
    if (response == NULL || response->data == NULL || response->length < sizeof(unsigned int))
        return 0;

    return *((unsigned int *) response->data);
}

/* Retrieve one specific entry from a list of calls */
struct ipc_call_list_entry* ipc_call_list_response_get_entry(struct ipc_message_info *response,
    unsigned int num)
{
    unsigned int count, pos, n;
    struct ipc_call_list_entry *entry = NULL;

    count = ipc_call_list_response_get_num_entries(response);
    if (num > count || count == 0)
        return NULL;

    pos = 1;
    for (n = 0; n < num + 1; n++)
    {
        entry = (struct ipc_call_list_entry *) (response->data + pos);
        pos += (unsigned int) (sizeof(struct ipc_call_list_entry) + entry->number_len);
    }

    return entry;
}

/* Retrieve the number of a call entry in the list of calls */
char *ipc_call_list_response_get_entry_number(struct ipc_message_info *response,
    unsigned int num)
{
    unsigned int count, pos, n;
    struct ipc_call_list_entry *entry = NULL;
    char *number;

    count = ipc_call_list_response_get_num_entries(response);
    if (num > count || count == 0)
        return NULL;

    pos = 1;
    for (n = 0; n < num + 1; n++)
    {
        if (entry != NULL)
            pos += entry->number_len;

        entry = (struct ipc_call_list_entry *) (response->data + pos);
        pos += (unsigned int) sizeof(struct ipc_call_list_entry);
    }

    if (entry == NULL || (unsigned char *) (response->data + pos) == NULL)
        return NULL;

    number = (char *) malloc(sizeof(char) * entry->number_len);
    strncpy(number, (char *) (response->data + pos), entry->number_len);

    return number;
}

unsigned char *ipc_call_cont_dtmf_burst_pack(struct ipc_call_cont_dtmf *message,
    unsigned char *burst, int burst_len)
{
    unsigned char *data = NULL;
    int data_len = sizeof(struct ipc_call_cont_dtmf) + burst_len;

    if (message == NULL || burst == NULL || burst_len <= 0)
        return NULL;

    data = (unsigned char *) malloc(sizeof(unsigned char) * data_len);
    memset(data, 0, data_len);

    memcpy(data, message, sizeof(struct ipc_call_cont_dtmf));
    memcpy(data + sizeof(struct ipc_call_cont_dtmf), burst, burst_len);

    return data;
}

// vim:ts=4:sw=4:expandtab