~clint-fewbar/ubuntu/precise/modemmanager/fix-removed-not-purged

« back to all changes in this revision

Viewing changes to src/mm-serial-parsers.c

  • Committer: Package Import Robot
  • Author(s): Artem Popov
  • Date: 2012-01-02 13:32:18 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120102133218-f2xuil48af71xa7b
Tags: upstream-0.5+git.20111231t174444.1e332ab
ImportĀ upstreamĀ versionĀ 0.5+git.20111231t174444.1e332ab

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
        } else
126
126
            code = MM_MOBILE_ERROR_UNKNOWN;
127
127
 
128
 
        g_match_info_free (match_info);
129
 
 
130
128
        switch (code) {
131
129
        case 0: /* OK */
132
130
            break;
155
153
        remove_matches (parser->generic_response, response);
156
154
    }
157
155
 
 
156
    g_match_info_free (match_info);
 
157
 
158
158
    if (!found) {
159
159
        found = g_regex_match_full (parser->detailed_error, response->str, response->len, 0, 0, &match_info, NULL);
160
 
 
161
160
        if (found) {
162
161
            str = g_match_info_fetch (match_info, 1);
163
162
            if (str) {
166
165
            } else
167
166
                code = MM_MOBILE_ERROR_UNKNOWN;
168
167
 
169
 
            g_match_info_free (match_info);
170
168
            local_error = mm_mobile_error_for_code (code);
171
169
        }
 
170
        g_match_info_free (match_info);
172
171
    }
173
172
 
174
173
    if (found)
260
259
    GMatchInfo *match_info;
261
260
    GError *local_error = NULL;
262
261
    gboolean found = FALSE;
263
 
    char *str;
 
262
    char *str = NULL;
264
263
    int code;
265
264
 
266
265
    g_return_val_if_fail (parser != NULL, FALSE);
267
266
    g_return_val_if_fail (response != NULL, FALSE);
268
267
 
269
 
    if (G_UNLIKELY (!response->len || !strlen (response->str)))
 
268
    /* Skip NUL bytes if they are found leading the response */
 
269
    while (response->len > 0 && response->str[0] == '\0')
 
270
        g_string_erase (response, 0, 1);
 
271
 
 
272
    if (G_UNLIKELY (!response->len))
270
273
        return FALSE;
271
274
 
272
275
    /* First, check for successful responses */
306
309
            str = g_match_info_fetch (match_info, 1);
307
310
            g_assert (str);
308
311
            local_error = mm_mobile_error_for_code (atoi (str));
309
 
            g_free (str);
310
 
            g_match_info_free (match_info);
311
312
            goto done;
312
313
        }
 
314
        g_match_info_free (match_info);
313
315
    }
314
316
 
315
317
    /* Numeric CME errors */
320
322
        str = g_match_info_fetch (match_info, 1);
321
323
        g_assert (str);
322
324
        local_error = mm_mobile_error_for_code (atoi (str));
323
 
        g_free (str);
324
 
        g_match_info_free (match_info);
325
325
        goto done;
326
326
    }
 
327
    g_match_info_free (match_info);
327
328
 
328
329
    /* Numeric CMS errors */
329
330
    /* Todo
337
338
        str = g_match_info_fetch (match_info, 1);
338
339
        g_assert (str);
339
340
        local_error = mm_mobile_error_for_code (atoi (str));
340
 
        g_free (str);
341
 
        g_match_info_free (match_info);
342
341
        goto done;
343
342
    }
 
343
    g_match_info_free (match_info);
344
344
 
345
345
    /* String CME errors */
346
346
    found = g_regex_match_full (parser->regex_cme_error_str,
350
350
        str = g_match_info_fetch (match_info, 1);
351
351
        g_assert (str);
352
352
        local_error = mm_mobile_error_for_string (str);
353
 
        g_free (str);
354
 
        g_match_info_free (match_info);
355
353
        goto done;
356
354
    }
 
355
    g_match_info_free (match_info);
357
356
 
358
357
    /* Motorola EZX errors */
359
358
    found = g_regex_match_full (parser->regex_ezx_error,
363
362
        str = g_match_info_fetch (match_info, 1);
364
363
        g_assert (str);
365
364
        local_error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN);
366
 
        g_free (str);
367
 
        g_match_info_free (match_info);
368
365
        goto done;
369
366
    }
 
367
    g_match_info_free (match_info);
370
368
 
371
369
    /* Last resort; unknown error */
372
370
    found = g_regex_match_full (parser->regex_unknown_error,
373
371
                                response->str, response->len,
374
 
                                0, 0, NULL, NULL);
 
372
                                0, 0, &match_info, NULL);
375
373
    if (found) {
376
374
        local_error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN);
377
375
        goto done;
378
376
    }
 
377
    g_match_info_free (match_info);
379
378
 
380
379
    /* Connection failures */
381
380
    found = g_regex_match_full (parser->regex_connect_failed,
398
397
            code = MM_MODEM_CONNECT_ERROR_NO_CARRIER;
399
398
        }
400
399
 
401
 
        g_free (str);
402
 
        g_match_info_free (match_info);
403
 
 
404
400
        local_error = mm_modem_connect_error_for_code (code);
405
401
    }
406
402
 
407
403
done:
 
404
    g_free (str);
 
405
    g_match_info_free (match_info);
408
406
    if (found)
409
407
        response_clean (response);
410
408
 
426
424
    g_regex_unref (parser->regex_ok);
427
425
    g_regex_unref (parser->regex_connect);
428
426
    g_regex_unref (parser->regex_cme_error);
 
427
    g_regex_unref (parser->regex_cms_error);
429
428
    g_regex_unref (parser->regex_cme_error_str);
430
429
    g_regex_unref (parser->regex_ezx_error);
431
430
    g_regex_unref (parser->regex_unknown_error);