-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.c
More file actions
146 lines (143 loc) · 4.68 KB
/
connection.c
File metadata and controls
146 lines (143 loc) · 4.68 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*******************************************************************************
* astapi - library for using Asterisk Manager API.
* Copyright (C) 2010 Baligh GUESMI
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc.,
******************************************************************************/
/*******************************************************************************
* @file connection.c
* @brief
* @author Baligh.GUESMI
* @date 20100524
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "astlog.h"
#include "astman.h"
static struct mansession *gSession;
static int _is_connected = 0;
static char gUsername[80];
static char gSecret[60];
static char gHost[20];
static int gPort;
/*******************************************************************************
* \fn int astInit()
* \brief
* \return
******************************************************************************/
int astInit()
{
gSession = NULL;
_is_connected = 0;
return ASTMAN_SUCCESS;
}
/*******************************************************************************
* \fn int astConnect(char * username, char *secret, char *host, int port)
* \brief
* \return
******************************************************************************/
int astConnect(char * username, char *secret, char *host, int port)
{
int res = ASTMAN_SUCCESS;
astlog_init();
if(astman_strlen_zero(username)) {
astlog(ASTLOG_WARNING, "Username for Login is empty");
}
strncpy(gUsername, username, 80);
strncpy(gSecret, secret, 60);
strncpy(gHost, host, 20);
gPort = port;
gSession = astman_open();
gSession->debug = 0;
astman_connect(gSession, gHost, gPort);
if(astman_login(gSession, gUsername, gSecret) == ASTMAN_FAILURE)
{
astlog(ASTLOG_ERROR, "Error in authorization");
res = ASTMAN_FAILURE;
goto Exit;
}
_is_connected = 1; /* set connected to TRUE */
Exit:
astlog_end();
return res;
}
/*******************************************************************************
* \fn int astDisconnect()
* \brief
* \return
******************************************************************************/
int astDisconnect()
{
astlog_init();
astman_logoff(gSession);
astman_disconnect(gSession);
_is_connected = 0; // FIX ISSUE 1: chrisTr1987
astlog_end();
return ASTMAN_SUCCESS;
}
/*******************************************************************************
* \fn int astIsConnected()
* \brief
* \return
******************************************************************************/
int astIsConnected()
{
return _is_connected;
}
/*******************************************************************************
* \fn char* astConnectionGetUsername()
* \brief
* \return
******************************************************************************/
char* astConnectionGetUsername()
{
return gUsername;
}
/*******************************************************************************
* \fn char* astConnectionGetUsername()
* \brief
* \return
******************************************************************************/
char* astConnectionGetPassword()
{
return gSecret;
}
/*******************************************************************************
* \fn char* astConnectionGetUsername()
* \brief
* \return
******************************************************************************/
char* astConnectionGetHost()
{
return gHost;
}
/*******************************************************************************
* \fn char* astConnectionGetUsername()
* \brief
* \return
******************************************************************************/
int astConnectionGetPort()
{
return gPort;
}
/*******************************************************************************
* \fn char* astConnectionGetUsername()
* \brief
* \return
******************************************************************************/
struct mansession* astConnectionGetSession()
{
return gSession;
}