static char* duplicate_and_sanitize(const char *text)
{
+ DEBUG("Sanitizing text to speak...");
+ DEBUG("Text before sanitization: '%s'", text);
Eina_Strbuf *buf = eina_strbuf_new();
+ if(buf == NULL)
+ {
+ ERROR("Eina_Strbuf allocation failed!");
+ return NULL;
+ }
eina_strbuf_append_length(buf, text, strlen(text));
+ eina_strbuf_trim(buf);
while(eina_strbuf_replace_all(buf, " ", " ") > 0);
char *ret = eina_strbuf_string_steal(buf);
eina_strbuf_free(buf);
+ DEBUG("Text after sanitization: %s", ret);
return ret;
}
tts_speak_customized(char *text_to_speak, Eina_Bool want_discard_previous_reading,
Eina_Bool discardable, AtspiAccessible *obj, unsigned int delay)
{
- // A command that cannot be discarded and does not compress the queue is not allowed.
if (text_to_speak == NULL) return NULL;
+ char *text_to_speak_sanitized = duplicate_and_sanitize(text_to_speak);
+ if (text_to_speak_sanitized == NULL)
+ {
+ ERROR("Text sanitization went wrong!");
+ return NULL;
+ }
+ if (!g_strcmp0("", text_to_speak_sanitized))
+ {
+ DEBUG("Text to speak is empty! Doing nothing...");
+ free(text_to_speak_sanitized); // using regular free because it was allocated by regular malloc via eina_strbuf_string_steal().
+ return NULL;
+ }
// note: this log is used by unversal-switch batch mode
// it must be exactly here
{
- char *reading_text = g_strdup(text_to_speak);
- if(!reading_text) return NULL;
+ char *reading_text = g_strdup(text_to_speak_sanitized);
+ if(!reading_text)
+ {
+ ERROR("Problem with memory allocation!");
+ free(text_to_speak_sanitized);
+ return NULL;
+ }
int i;
for(i = 0; reading_text[i] && i < 3900; ++i) if (reading_text[i] < ' ' || reading_text[i] == 127) reading_text[i] = ' ';
reading_text[i] = 0;
g_free(reading_text);
}
+ // A command that cannot be discarded and does not compress the queue is not allowed.
if (!discardable && !want_discard_previous_reading) {
char buffer[32];
- g_snprintf(buffer, 32, "%s", text_to_speak);
+ g_snprintf(buffer, 32, "%s", text_to_speak_sanitized);
WARNING("rejecting non-discardable, non-compressing command '%s...'", buffer);
+ free(text_to_speak_sanitized);
return NULL;
}
Service_Data *sd = get_pointer_to_service_data_struct();
if (!sd || !sd->tts)
+ {
+ ERROR("Problem with accessing service data struct!");
+ free(text_to_speak_sanitized);
return NULL;
+ }
tts_state_e state;
tts_get_state(sd->tts, &state);
char text[64];
- g_strlcpy(text, text_to_speak, 63);
+ g_strlcpy(text, text_to_speak_sanitized, 63);
text[63] = 0;
DEBUG("READ COMMAND PARAMS, TEXT: %s, DISCARDABLE: %d, ATSPI_OBJECT: %p, DELAY %d", text, discardable, obj, delay);
Read_Command *rc = g_malloc0(sizeof(Read_Command));
- if (!rc) return NULL;
+ if (!rc)
+ {
+ ERROR("Problem with memory allocation!");
+ free(text_to_speak_sanitized);
+ return NULL;
+ }
Read_Context *ctx = &rc->context;
- ctx->text = duplicate_and_sanitize(text_to_speak);
+
+ ctx->text = text_to_speak_sanitized;
ctx->chunk_count = 0;
ctx->last_id = -1;