aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/call.c
blob: 0434c94183c6c03da2bddb104e0b722db7841b4e (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
/**
 * This file is part of libsamsung-ipc.
 *
 * 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 3 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 <radio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.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)
{
    assert(message != NULL);

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

    message->type = type;
    message->identity = identity;
    message->prefix = prefix;
    message->length = strlen(number);

    assert(message->length <= OUTGOING_NUMBER_MAX_LENGTH);

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

/**
 * Retrieve number of calls in list of calls.
 **/
unsigned int ipc_call_list_response_get_num_entries(struct ipc_message_info *response)
{
    unsigned int count = 0, n = 0;

    assert(response != NULL);
    assert(response->data != NULL);

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

/**
 * 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 = 0, pos = 1, n = 0;
    struct ipc_call_list_entry *entry = NULL;

    assert(response != NULL);
    assert(response->data != NULL);

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

    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 = 0, pos = 1, n = 0;
    struct ipc_call_list_entry *entry = NULL;
    char *number = NULL;

    assert(response != NULL);
    assert(response->data != NULL);

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

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

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

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

    return number;
}

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