summaryrefslogtreecommitdiffstats
path: root/tinyDEMO/cmd.c
blob: a2d6c8975c40d082ec2b8d37c3450793b412a765 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright (C) 2009 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*	
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO 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.
*	
* DOUBANGO 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 DOUBANGO.
*
*/
#include "cmd.h"

#include "dssl.h"

#include "tsk_memory.h"
#include "tsk_string.h"
#include "tsk_debug.h"

//#define PAD "  "

static int pred_find_opt_by_type(const tsk_list_item_t *item, const void *type);

/* parse a command line */
cmd_t* cmd_parse(const char* buffer, tsk_size_t size, tsk_bool_t *comment, tsk_params_L_t* params)
{	
	return dssl_parse(buffer, size, comment, params);
}

///* print usage */
void cmd_print_help()
{
	printf("\n\n========================= Usage =========================\n\n");
	printf("Please refer to the Programmer's Guide at\n http://www.doubango.org/\n\n");

//
//	printf("Usage:\n");
//	printf(PAD"++[command] --[opts]\n\n");
//
//	/* Commands */
//	printf("Commands:\n--\n");
//	printf(PAD"[++audio] or [++a"PAD"%s", "Make audio call\n--\n");
//	printf(PAD"[++audiovideo] or [++av]"PAD"%s", "Make audio/video call\n--\n");
//	printf(PAD"[++config-file] or [++cf]"PAD"%s", "Load opts from config file\n--\n");
//	printf(PAD"[++config-session] | [++css]"PAD"%s", "Configure an 3GPP IMS/LTE session\n--\n");
//	printf(PAD"[++config-stack] | [++cst]"PAD"%s", "Configure an 3GPP IMS/LTE stack\n--\n");
//	printf(PAD"[++exit] | [++e]"PAD"%s", "Exit the application\n--\n");
//	printf(PAD"[++file] | [++f]"PAD"%s", "Send a file. The stack must be running (see ++run command). To abort the File transfer, use ++hangup.\n--\n");
//	printf(PAD"[++hangup] | [++hp]"PAD"%s", "Hangup any SIP session (unREGISTER, unSUBSCRIBE, unPUBLISH, HangUp Call, Abort ...).\n--\n");
//	printf(PAD"[++help] | [++h]"PAD"%s", "Print this help screen\n--\n");
//	printf(PAD"[++message] | [++m]"PAD"%s", "Send Pager Mode IM. The stack must be running (see ++run command).\n\n");
//	printf(PAD"[++publish] | [++pub]"PAD"%s", "Send PUBLISH message. The stack must be running (see ++run command). To unPUBLISH, use ++hanggup.\n--\n");
//	printf(PAD"[++quit] | [++q]"PAD"%s", "Quit the application\n--\n");
//	printf(PAD"[++run]"PAD"%s", "Start/Run the 3GPP IMS/LTE stack. Mandatory before starting to do anything.\n--\n");
//	printf(PAD"[++sms]"PAD"%s", "Send Binary SMS (RP-DATA). The stack must be running (see ++run command).\n--\n");
//	printf(PAD"[++subscribe] | [++sub]"PAD"%s", "Send SUBSCRIBE message. The stack must be running (see ++run command). To unSUBSCRIBE, use ++hangup.\n--\n");
//	printf(PAD"[++video] or [++v]"PAD"%s", "Make video call\n--\n");
//
//	printf("\n\n========================= =========================\n\n");
}

cmd_t* cmd_create(cmd_type_t type)
{
	return tsk_object_new(cmd_def_t, type);
}

static tsk_object_t* cmd_ctor(tsk_object_t * self, va_list * app)
{
	cmd_t *cmd = self;
	if(cmd){
		cmd->type = va_arg(*app, cmd_type_t);
		cmd->opts = tsk_list_create();
	}
	return self;
}

static tsk_object_t* cmd_dtor(tsk_object_t * self)
{ 
	cmd_t *cmd = self;
	if(cmd){
		TSK_OBJECT_SAFE_FREE(cmd->opts);
		TSK_FREE(cmd->sidparam);
	}

	return self;
}

static const tsk_object_def_t cmd_def_s = 
{
	sizeof(cmd_t),
	cmd_ctor, 
	cmd_dtor,
	tsk_null, 
};
const tsk_object_def_t *cmd_def_t = &cmd_def_s;


opt_t* opt_create(opt_type_t type, lv_t level, const char* value)
{
	return tsk_object_new(opt_def_t, type, level, value);
}

const opt_t* opt_get_by_type(const opts_L_t* opts, opt_type_t type)
{
	const tsk_list_item_t* item;
	if((item = tsk_list_find_item_by_pred(opts, pred_find_opt_by_type, &type))){
		return item->data;
	}
	return tsk_null;
}

static int pred_find_opt_by_type(const tsk_list_item_t *item, const void *type)
{
	if(item && item->data){
		opt_t *opt = item->data;
		return (opt->type - *((opt_type_t*)type));
	}
	return -1;
}

static tsk_object_t* opt_ctor(tsk_object_t * self, va_list * app)
{
	opt_t *opt = self;
	if(opt){
		opt->type = va_arg(*app, opt_type_t);
		opt->lv = va_arg(*app, lv_t);
		opt->value = tsk_strdup(va_arg(*app, const char*));
	}
	return self;
}

static tsk_object_t* opt_dtor(tsk_object_t * self)
{ 
	opt_t *opt = self;
	if(opt){
		TSK_FREE(opt->value);
	}

	return self;
}

static const tsk_object_def_t opt_def_s = 
{
	sizeof(opt_t),
	opt_ctor, 
	opt_dtor,
	tsk_null, 
};
const tsk_object_def_t *opt_def_t = &opt_def_s;
OpenPOWER on IntegriCloud