Simplify the send_info API
authorDenis Kenzior <denkenz@gmail.com>
Wed, 31 Mar 2010 01:29:10 +0000 (20:29 -0500)
committerDenis Kenzior <denkenz@gmail.com>
Wed, 31 Mar 2010 01:29:10 +0000 (20:29 -0500)
gatchat/gatserver.c
gatchat/gatserver.h

index e04e0d2..4904adf 100644 (file)
@@ -169,7 +169,7 @@ static void send_result_common(GAtServer *server, const char *result)
 
 {
        struct v250_settings v250 = server->v250;
-       char buf[MAX_TEXT_SIZE];
+       char buf[MAX_TEXT_SIZE + 1];
        char t = v250.s3;
        char r = v250.s4;
        unsigned int len;
@@ -180,14 +180,15 @@ static void send_result_common(GAtServer *server, const char *result)
        if (result == NULL)
                return;
 
+       if (strlen(result) > 2048)
+               return;
+
        if (v250.is_v1)
-               len = snprintf(buf, sizeof(buf), "%c%c%s%c%c", t, r, result,
-                               t, r);
+               len = sprintf(buf, "%c%c%s%c%c", t, r, result, t, r);
        else
-               len = snprintf(buf, sizeof(buf), "%s%c", result,
-                               t);
+               len = sprintf(buf, "%s%c", result, t);
 
-       send_common(server, buf, MIN(len, sizeof(buf)-1));
+       send_common(server, buf, len);
 }
 
 void g_at_server_send_final(GAtServer *server, GAtServerResult result)
@@ -233,32 +234,21 @@ void g_at_server_send_unsolicited(GAtServer *server, const char *result)
        send_result_common(server, result);
 }
 
-void g_at_server_send_info(GAtServer *server, const char *info)
-{
-       send_result_common(server, info);
-}
-
-void g_at_server_send_info_lines(GAtServer *server, GSList *text)
+void g_at_server_send_info(GAtServer *server, const char *line, gboolean last)
 {
-       char buf[MAX_TEXT_SIZE];
+       char buf[MAX_TEXT_SIZE + 1];
        char t = server->v250.s3;
        char r = server->v250.s4;
        unsigned int len;
-       GSList *l;
 
-       if (!text)
+       if (strlen(line) > 2048)
                return;
 
-       for (l = text; l; l = l->next) {
-               char *line = l->data;
-               if (!line)
-                       return;
-
-               len = snprintf(buf, sizeof(buf), "%c%c%s", t, r, line);
-               send_common(server, buf, MIN(len, sizeof(buf)-1));
-       }
+       if (last)
+               len = sprintf(buf, "%c%c%s%c%c", t, r, line, t, r);
+       else
+               len = sprintf(buf, "%c%c%s", t, r, line);
 
-       len = snprintf(buf, sizeof(buf), "%c%c", t, r);
        send_common(server, buf, len);
 }
 
index 2628faf..bba8c2b 100644 (file)
@@ -99,18 +99,14 @@ void g_at_server_send_intermediate(GAtServer *server, const char *result);
 /* Send an unsolicited result code. E.g. RING */
 void g_at_server_send_unsolicited(GAtServer *server, const char *result);
 
-/* Send an information text. The text could contain multiple lines. Each
- * line, including line terminators, should not exceed 2048 characters.
- */
-void g_at_server_send_info_lines(GAtServer *server, GSList *text);
-
 /*
  * Send a single response line for the command.  The line should be no longer
  * than 2048 characters.  If the response contains multiple lines, use
- * g_at_server_send_info_lines instead, since the formatting of 27.007
- * compliant multi-line responses is different.
+ * FALSE for the 'last' parameter for lines 1 .. n -1, and 'TRUE' for the last
+ * line.  This is required for formatting of 27.007 compliant multi-line
+ * responses.
  */
-void g_at_server_send_info(GAtServer *server, const char *line);
+void g_at_server_send_info(GAtServer *server, const char *line, gboolean last);
 
 #ifdef __cplusplus
 }