Skip to content

Commit

Permalink
Merge branch 'octal' into 'master'
Browse files Browse the repository at this point in the history
Workaround for broken MMS proxy IP address

See merge request !16
  • Loading branch information
Slava Monich committed Jun 20, 2017
2 parents 31c8128 + a7a0c55 commit b3f1977
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 24 deletions.
46 changes: 45 additions & 1 deletion mms-lib/src/mms_task_http.c
Expand Up @@ -20,6 +20,8 @@

#include <gutil_misc.h>

#include <ctype.h>

#ifndef _WIN32
# include <sys/ioctl.h>
# include <arpa/inet.h>
Expand Down Expand Up @@ -178,6 +180,46 @@ mms_http_create_session(
SoupURI* proxy_uri = mms_http_uri_parse(conn->mmsproxy);
if (proxy_uri) {
GDEBUG("MMS proxy %s", conn->mmsproxy);
if (proxy_uri->host[0] == '0' || strstr(proxy_uri->host, ".0")) {
/*
* Some operators provide IP address of the MMS proxy
* prepending zeros to each number shorter then 3 digits,
* e.g. "192.168.094.023" instead of "192.168.94.23".
* That may look nicer but it's actually wrong because
* the numbers starting with zeros are interpreted as
* octal numbers. In the example above 023 actually means
* 16 and 094 is not a valid number at all.
*
* In addition to publishing these broken settings on their
* web sites, some of the operators send them over the air,
* in which case we can't even blame the user for entering
* an invalid IP address. We better be prepared to deal with
* those.
*
* Since nobody in the world seems to be actually using the
* octal notation to write an IP address, let's remove the
* leading zeros if we find them in the host part of the MMS
* proxy URL.
*/
char* host;
char** parts = g_strsplit(proxy_uri->host, ".", -1);
guint count = g_strv_length(parts);
if (count == 4) {
char** ptr = parts;
while (*ptr) {
char* part = *ptr;
while (part[0] == '0' && isdigit(part[1])) {
memmove(part, part+1, strlen(part));
}
*ptr++ = part;
}
host = g_strjoinv(".", parts);
GDEBUG("MMS proxy host %s => %s", proxy_uri->host, host);
soup_uri_set_host(proxy_uri, host);
g_free(host);
}
g_strfreev(parts);
}
g_object_set(session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
soup_uri_free(proxy_uri);
}
Expand Down Expand Up @@ -266,7 +308,9 @@ mms_task_http_receive_progress(
MMSTaskHttpPriv* priv = http->priv;
MMSHttpTransfer* tx = priv->tx;
if (tx) {
GASSERT(tx->bytes_received <= tx->bytes_to_receive);
/* Some operators don't provide Content-Length */
GASSERT(!tx->bytes_to_receive ||
tx->bytes_received <= tx->bytes_to_receive);
mms_transfer_list_transfer_receive_progress(http->transfers,
http->task.id, priv->transfer_type, tx->bytes_received,
tx->bytes_to_receive);
Expand Down
8 changes: 4 additions & 4 deletions mms-lib/test/common/test_connection.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -74,8 +74,8 @@ mms_connection_test_set_state(
MMSConnection*
mms_connection_test_new(
const char* imsi,
unsigned short port,
gboolean proxy)
const char* proxy,
unsigned short port)
{
MMSConnectionTest* test = g_object_new(MMS_TYPE_CONNECTION_TEST, NULL);
MMSConnection* conn = &test->connection;
Expand All @@ -84,7 +84,7 @@ mms_connection_test_new(
conn->netif = test->netif = g_strdup("lo");
if (proxy) {
test->mmsc = g_strdup("http://mmsc");
test->mmsproxy = g_strdup_printf("127.0.0.1:%hu", port);
test->mmsproxy = g_strdup_printf("%s:%hu", proxy, port);
} else {
test->mmsc = g_strdup_printf("http://127.0.0.1:%hu", port);
}
Expand Down
8 changes: 4 additions & 4 deletions mms-lib/test/common/test_connection.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand All @@ -9,7 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/

#ifndef TEST_CONNECTION_H
Expand All @@ -20,8 +20,8 @@
MMSConnection*
mms_connection_test_new(
const char* imsi,
unsigned short port,
gboolean proxy);
const char* proxy,
unsigned short port);

#endif /* TEST_CONNECTION_H */

Expand Down
25 changes: 18 additions & 7 deletions mms-lib/test/common/test_connman.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -25,7 +25,7 @@ typedef struct mms_connman_test {
MMSConnMan cm;
MMSConnection* conn;
unsigned short port;
gboolean proxy;
char* proxy;
char* default_imsi;
gboolean offline;
mms_connman_test_connect_fn connect_fn;
Expand Down Expand Up @@ -58,15 +58,24 @@ mms_connman_test_make_busy(
g_idle_add(mms_connman_test_busy_cb, test);
}

void
mms_connman_test_set_proxy(
MMSConnMan* cm,
const char* proxy,
unsigned short port)
{
MMSConnManTest* test = MMS_CONNMAN_TEST(cm);
test->proxy = g_strdup(proxy);
test->port = port;
}

void
mms_connman_test_set_port(
MMSConnMan* cm,
unsigned short port,
gboolean proxy)
{
MMSConnManTest* test = MMS_CONNMAN_TEST(cm);
test->port = port;
test->proxy = proxy;
return mms_connman_test_set_proxy(cm, proxy ? "127.0.0.1" : NULL, port);
}

void
Expand Down Expand Up @@ -133,7 +142,7 @@ mms_connman_test_open_connection(
return NULL;
} else {
mms_connman_test_make_busy(test);
test->conn = mms_connection_test_new(imsi, test->port, test->proxy);
test->conn = mms_connection_test_new(imsi, test->proxy, test->port);
if (test->connect_fn) test->connect_fn(test->connect_param);
return mms_connection_ref(test->conn);
}
Expand All @@ -153,7 +162,9 @@ void
mms_connman_test_finalize(
GObject* object)
{
g_free(MMS_CONNMAN_TEST(object)->default_imsi);
MMSConnManTest* test = MMS_CONNMAN_TEST(object);
g_free(test->proxy);
g_free(test->default_imsi);
G_OBJECT_CLASS(mms_connman_test_parent_class)->finalize(object);
}

Expand Down
10 changes: 8 additions & 2 deletions mms-lib/test/common/test_connman.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand All @@ -9,7 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/

#ifndef TEST_CONNMAN_H
Expand All @@ -25,6 +25,12 @@ void
MMSConnMan*
mms_connman_test_new(void);

void
mms_connman_test_set_proxy(
MMSConnMan* cm,
const char* proxy,
unsigned short port);

void
mms_connman_test_set_port(
MMSConnMan* cm,
Expand Down
10 changes: 7 additions & 3 deletions mms-lib/test/coverage/run
Expand Up @@ -33,9 +33,13 @@ for t in $TESTS ; do
popd
done

# LCOV 1.10 has branch coverage disabled per default
LCOV_OPT="--rc lcov_branch_coverage=1"
GENHTML_OPT="--branch-coverage"

FULL_COV="$COV_DIR/full.gcov"
MMSLIB_COV="$COV_DIR/mms-lib.gcov"
rm -f "$FULL_COV" "$MMSLIB_COV"
lcov -c -d "$BASE_DIR/build/$FLAVOR" -b "$BASE_DIR" -o "$FULL_COV" || exit 1
lcov -e "$FULL_COV" "$BASE_DIR/src/*" -o "$MMSLIB_COV" || exit 1
genhtml "$MMSLIB_COV" --output-directory "$COV_DIR/results" || exit 1
lcov $LCOV_OPT -c -d "$BASE_DIR/build/$FLAVOR" -b "$BASE_DIR" -o "$FULL_COV" || exit 1
lcov $LCOV_OPT -e "$FULL_COV" "$BASE_DIR/src/*" -o "$MMSLIB_COV" || exit 1
genhtml $GENHTML_OPT -t mms-engine "$MMSLIB_COV" --output-directory "$COV_DIR/results" || exit 1

0 comments on commit b3f1977

Please sign in to comment.