serial-parsers: remove v0 and v1_e1 parsers, which are unused
Given that we now perform our own built-in echo removal in the v1 parser, we no longer need the v1_e1 parser. The v0 parser was also unused from long ago.
This commit is contained in:
@@ -79,139 +79,6 @@ remove_matches (GRegex *r, GString *string)
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GRegex *generic_response;
|
||||
GRegex *detailed_error;
|
||||
GRegex *cms_error;
|
||||
} MMSerialParserV0;
|
||||
|
||||
gpointer
|
||||
mm_serial_parser_v0_new (void)
|
||||
{
|
||||
MMSerialParserV0 *parser;
|
||||
GRegexCompileFlags flags = G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW | G_REGEX_OPTIMIZE;
|
||||
|
||||
parser = g_slice_new (MMSerialParserV0);
|
||||
|
||||
parser->generic_response = g_regex_new ("(\\d)\\0?\\r$", flags, 0, NULL);
|
||||
parser->detailed_error = g_regex_new ("\\+CME ERROR:\\s*(\\d+)\\r\\n$", flags, 0, NULL);
|
||||
parser->cms_error = g_regex_new ("\\+CMS ERROR:\\s*(\\d+)\\r\\n$", flags, 0, NULL);
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_serial_parser_v0_parse (gpointer data,
|
||||
GString *response,
|
||||
GError **error)
|
||||
{
|
||||
MMSerialParserV0 *parser = (MMSerialParserV0 *) data;
|
||||
GMatchInfo *match_info;
|
||||
char *str;
|
||||
GError *local_error = NULL;
|
||||
int code;
|
||||
gboolean found;
|
||||
|
||||
g_return_val_if_fail (parser != NULL, FALSE);
|
||||
g_return_val_if_fail (response != NULL, FALSE);
|
||||
|
||||
if (G_UNLIKELY (!response->len || !strlen (response->str)))
|
||||
return FALSE;
|
||||
|
||||
found = g_regex_match_full (parser->generic_response, response->str, response->len, 0, 0, &match_info, NULL);
|
||||
if (found) {
|
||||
str = g_match_info_fetch (match_info, 1);
|
||||
if (str) {
|
||||
code = atoi (str);
|
||||
g_free (str);
|
||||
} else
|
||||
code = MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN;
|
||||
|
||||
switch (code) {
|
||||
case 0: /* OK */
|
||||
break;
|
||||
case 1: /* CONNECT */
|
||||
break;
|
||||
case 3: /* NO CARRIER */
|
||||
local_error = mm_connection_error_for_code (MM_CONNECTION_ERROR_NO_CARRIER);
|
||||
break;
|
||||
case 4: /* ERROR */
|
||||
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN);
|
||||
break;
|
||||
case 6: /* NO DIALTONE */
|
||||
local_error = mm_connection_error_for_code (MM_CONNECTION_ERROR_NO_DIALTONE);
|
||||
break;
|
||||
case 7: /* BUSY */
|
||||
local_error = mm_connection_error_for_code (MM_CONNECTION_ERROR_BUSY);
|
||||
break;
|
||||
case 8: /* NO ANSWER */
|
||||
local_error = mm_connection_error_for_code (MM_CONNECTION_ERROR_NO_ANSWER);
|
||||
break;
|
||||
default:
|
||||
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN);
|
||||
break;
|
||||
}
|
||||
|
||||
remove_matches (parser->generic_response, response);
|
||||
}
|
||||
|
||||
g_match_info_free (match_info);
|
||||
|
||||
if (!found) {
|
||||
found = g_regex_match_full (parser->detailed_error, response->str, response->len, 0, 0, &match_info, NULL);
|
||||
if (found) {
|
||||
str = g_match_info_fetch (match_info, 1);
|
||||
if (str) {
|
||||
code = atoi (str);
|
||||
g_free (str);
|
||||
} else
|
||||
code = MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN;
|
||||
|
||||
local_error = mm_mobile_equipment_error_for_code (code);
|
||||
}
|
||||
g_match_info_free (match_info);
|
||||
|
||||
if (!found) {
|
||||
found = g_regex_match_full (parser->cms_error, response->str, response->len, 0, 0, &match_info, NULL);
|
||||
if (found) {
|
||||
str = g_match_info_fetch (match_info, 1);
|
||||
if (str) {
|
||||
code = atoi (str);
|
||||
g_free (str);
|
||||
} else
|
||||
code = MM_MESSAGE_ERROR_UNKNOWN;
|
||||
|
||||
local_error = mm_message_error_for_code (code);
|
||||
}
|
||||
g_match_info_free (match_info);
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
response_clean (response);
|
||||
|
||||
if (local_error) {
|
||||
mm_dbg ("Got failure code %d: %s", local_error->code, local_error->message);
|
||||
g_propagate_error (error, local_error);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
void
|
||||
mm_serial_parser_v0_destroy (gpointer data)
|
||||
{
|
||||
MMSerialParserV0 *parser = (MMSerialParserV0 *) data;
|
||||
|
||||
g_return_if_fail (parser != NULL);
|
||||
|
||||
g_regex_unref (parser->generic_response);
|
||||
g_regex_unref (parser->detailed_error);
|
||||
g_regex_unref (parser->cms_error);
|
||||
|
||||
g_slice_free (MMSerialParserV0, data);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
/* Regular expressions for successful replies */
|
||||
GRegex *regex_ok;
|
||||
@@ -467,54 +334,3 @@ mm_serial_parser_v1_destroy (gpointer data)
|
||||
|
||||
g_slice_free (MMSerialParserV1, data);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
gpointer v1;
|
||||
GRegex *regex_echo;
|
||||
} MMSerialParserV1E1;
|
||||
|
||||
gpointer
|
||||
mm_serial_parser_v1_e1_new (void)
|
||||
{
|
||||
MMSerialParserV1E1 *parser;
|
||||
GRegexCompileFlags flags = G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW | G_REGEX_OPTIMIZE;
|
||||
|
||||
parser = g_slice_new (MMSerialParserV1E1);
|
||||
parser->v1 = mm_serial_parser_v1_new ();
|
||||
|
||||
/* Does not start with '<CR><LF>' and ends with '<CR>'. */
|
||||
parser->regex_echo = g_regex_new ("^(?!\\r\\n).+\\r", flags, 0, NULL);
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_serial_parser_v1_e1_parse (gpointer data,
|
||||
GString *response,
|
||||
GError **error)
|
||||
{
|
||||
MMSerialParserV1E1 *parser = (MMSerialParserV1E1 *) data;
|
||||
GMatchInfo *match_info = NULL;
|
||||
|
||||
/* Remove the command echo */
|
||||
if (g_regex_match_full (parser->regex_echo, response->str, response->len, 0, 0, &match_info, NULL)) {
|
||||
gchar *match = g_match_info_fetch (match_info, 0);
|
||||
|
||||
g_string_erase (response, 0, strlen (match));
|
||||
g_free (match);
|
||||
g_match_info_free (match_info);
|
||||
}
|
||||
|
||||
return mm_serial_parser_v1_parse (parser->v1, response, error);
|
||||
}
|
||||
|
||||
void
|
||||
mm_serial_parser_v1_e1_destroy (gpointer data)
|
||||
{
|
||||
MMSerialParserV1E1 *parser = (MMSerialParserV1E1 *) data;
|
||||
|
||||
g_regex_unref (parser->regex_echo);
|
||||
mm_serial_parser_v1_destroy (parser->v1);
|
||||
|
||||
g_slice_free (MMSerialParserV1E1, data);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,6 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
gpointer mm_serial_parser_v0_new (void);
|
||||
gboolean mm_serial_parser_v0_parse (gpointer parser,
|
||||
GString *response,
|
||||
GError **error);
|
||||
void mm_serial_parser_v0_destroy (gpointer parser);
|
||||
|
||||
|
||||
gpointer mm_serial_parser_v1_new (void);
|
||||
void mm_serial_parser_v1_set_custom_regex (gpointer data,
|
||||
GRegex *successful,
|
||||
@@ -34,11 +27,4 @@ gboolean mm_serial_parser_v1_parse (gpointer parser,
|
||||
GError **error);
|
||||
void mm_serial_parser_v1_destroy (gpointer parser);
|
||||
|
||||
|
||||
gpointer mm_serial_parser_v1_e1_new (void);
|
||||
gboolean mm_serial_parser_v1_e1_parse (gpointer parser,
|
||||
GString *response,
|
||||
GError **error);
|
||||
void mm_serial_parser_v1_e1_destroy (gpointer parser);
|
||||
|
||||
#endif /* MM_SERIAL_PARSERS_H */
|
||||
|
||||
Reference in New Issue
Block a user