Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH] voicecall: Limit tone string length per request.
@ 2010-10-25  5:51 Andrzej Zaborowski
  2010-10-25  5:51 ` [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication Andrzej Zaborowski
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Andrzej Zaborowski @ 2010-10-25  5:51 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1247 bytes --]

Also change to avoid memcpying into a buffer.
---
 src/voicecall.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index 26cfb9a..bd64432 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -2472,7 +2472,7 @@ static gboolean tone_request_run(gpointer user_data)
 {
 	struct ofono_voicecall *vc = user_data;
 	struct tone_queue_entry *entry = g_queue_peek_head(vc->toneq);
-	char buf[256];
+	char final;
 	unsigned len;
 
 	vc->tone_source = 0;
@@ -2483,14 +2483,17 @@ static gboolean tone_request_run(gpointer user_data)
 	len = strcspn(entry->left, "pP");
 
 	if (len) {
-		if (len >= sizeof(buf))
-			len = sizeof(buf) - 1;
+		if (len > 8) /* Arbitrary length limit per request */
+			len = 8;
 
-		memcpy(buf, entry->left, len);
-		buf[len] = '\0';
-		entry->left += len;
+		/* Temporarily move the end of the string */
+		final = entry->left[len];
+		entry->left[len] = '\0';
+
+		vc->driver->send_tones(vc, entry->left, tone_request_cb, vc);
 
-		vc->driver->send_tones(vc, buf, tone_request_cb, vc);
+		entry->left += len;
+		entry->left[0] = final;
 	} else
 		tone_request_cb(NULL, vc);
 
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests.
@ 2010-10-11  7:51 Andrzej Zaborowski
  2010-10-11  7:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
  0 siblings, 1 reply; 7+ messages in thread
From: Andrzej Zaborowski @ 2010-10-11  7:51 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4370 bytes --]

---
 src/stkagent.c |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/stkagent.h |   13 ++++++++
 2 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/src/stkagent.c b/src/stkagent.c
index 354b87d..e123bd2 100644
--- a/src/stkagent.c
+++ b/src/stkagent.c
@@ -861,3 +861,97 @@ int stk_agent_confirm_call(struct stk_agent *agent, const char *text,
 
 	return 0;
 }
+
+static void play_tone_cb(DBusPendingCall *call, void *data)
+{
+	struct stk_agent *agent = data;
+	stk_agent_tone_cb cb = agent->user_cb;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	enum stk_agent_result result;
+	gboolean remove_agent;
+
+	if (check_error(agent, reply,
+			ALLOWED_ERROR_TERMINATE, &result) == -EINVAL) {
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	if (dbus_message_get_args(reply, NULL, DBUS_TYPE_INVALID) == FALSE) {
+		ofono_error("Can't parse the reply to PlayTone()");
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	cb(result, agent->user_data);
+	goto done;
+
+	CALLBACK_END();
+}
+
+int stk_agent_play_tone(struct stk_agent *agent, const char *text,
+			const struct stk_icon_id *icon, ofono_bool_t vibrate,
+			const char *tone, stk_agent_tone_cb cb, void *user_data,
+			ofono_destroy_func destroy, int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"PlayTone");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &tone,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon->id,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, play_tone_cb,
+					agent, NULL);
+
+	return 0;
+}
+
+int stk_agent_loop_tone(struct stk_agent *agent, const char *text,
+			const struct stk_icon_id *icon, ofono_bool_t vibrate,
+			const char *tone, stk_agent_tone_cb cb, void *user_data,
+			ofono_destroy_func destroy, int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"LoopTone");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &tone,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon->id,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, play_tone_cb,
+					agent, NULL);
+
+	return 0;
+}
diff --git a/src/stkagent.h b/src/stkagent.h
index 97c4eca..c8e1886 100644
--- a/src/stkagent.h
+++ b/src/stkagent.h
@@ -56,6 +56,9 @@ typedef void (*stk_agent_confirmation_cb)(enum stk_agent_result result,
 typedef void (*stk_agent_string_cb)(enum stk_agent_result result,
 					char *string, void *user_data);
 
+typedef void (*stk_agent_tone_cb)(enum stk_agent_result result,
+						void *user_data);
+
 struct stk_agent *stk_agent_new(const char *path, const char *sender,
 					ofono_bool_t remove_on_terminate);
 
@@ -121,5 +124,15 @@ int stk_agent_confirm_call(struct stk_agent *agent, const char *text,
 				stk_agent_confirmation_cb cb, void *user_data,
 				ofono_destroy_func destroy, int timeout);
 
+int stk_agent_play_tone(struct stk_agent *agent, const char *text,
+			const struct stk_icon_id *icon, ofono_bool_t vibrate,
+			const char *tone, stk_agent_tone_cb cb, void *user_data,
+			ofono_destroy_func destroy, int timeout);
+
+int stk_agent_loop_tone(struct stk_agent *agent, const char *text,
+			const struct stk_icon_id *icon, ofono_bool_t vibrate,
+			const char *tone, stk_agent_tone_cb cb, void *user_data,
+			ofono_destroy_func destroy, int timeout);
+
 void append_menu_items_variant(DBusMessageIter *iter,
 				const struct stk_menu_item *items);
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-10-25 22:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-25  5:51 [PATCH] voicecall: Limit tone string length per request Andrzej Zaborowski
2010-10-25  5:51 ` [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication Andrzej Zaborowski
2010-10-25 22:27   ` Denis Kenzior
2010-10-25  5:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
2010-10-25 22:27   ` Denis Kenzior
2010-10-25 22:27 ` [PATCH] voicecall: Limit tone string length per request Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2010-10-11  7:51 [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests Andrzej Zaborowski
2010-10-11  7:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox