Commit 391496b3 authored by Slava Monich's avatar Slava Monich

[mms-engine] Added x-wap-profile header (UAProf)

The value is configurable from the command line and via GSettings
parent 016d7a03
......@@ -30,6 +30,7 @@ typedef struct mms_app_options {
int flags;
char* dir;
char* user_agent;
char* uaprof;
MMSConfig config;
MMSSettingsSimData settings;
} MMSAppOptions;
......@@ -192,7 +193,9 @@ mms_app_parse_options(
{ "pix-limit", 'p', 0, G_OPTION_ARG_DOUBLE,
&megapixels, "Maximum pixel count for outgoing images", "MPIX" },
{ "user-agent", 'u', 0, G_OPTION_ARG_STRING,
&opt->user_agent, "User-Agent header", "STRING" },
&opt->user_agent, "The value of the User-Agent header", "STRING" },
{ "x-wap-profile", 'x', 0, G_OPTION_ARG_STRING,
&opt->uaprof, "User agent profile", "URL" },
{ "keep-running", 'k', 0, G_OPTION_ARG_NONE, &keep_running,
"Keep running after everything is done", NULL },
{ "keep-temp-files", 't', 0, G_OPTION_ARG_NONE,
......@@ -266,6 +269,10 @@ mms_app_parse_options(
opt->settings.user_agent = opt->user_agent;
opt->flags |= MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT;
}
if (opt->uaprof) {
opt->settings.uaprof = opt->uaprof;
opt->flags |= MMS_ENGINE_FLAG_OVERRIDE_UAPROF;
}
if (opt->dir) opt->config.root_dir = opt->dir;
if (keep_running) opt->flags |= MMS_ENGINE_FLAG_KEEP_RUNNING;
if (session_bus) {
......@@ -322,6 +329,7 @@ int main(int argc, char* argv[])
}
g_free(opt.dir);
g_free(opt.user_agent);
g_free(opt.uaprof);
mms_lib_deinit();
return result;
}
......@@ -405,6 +405,12 @@ mms_engine_new(
settings->sim_defaults.data.user_agent =
settings->sim_defaults.user_agent = g_strdup(override->user_agent);
}
if (flags & MMS_ENGINE_FLAG_OVERRIDE_UAPROF) {
settings->flags |= MMS_SETTINGS_FLAG_OVERRIDE_UAPROF;
g_free(settings->sim_defaults.uaprof);
settings->sim_defaults.data.uaprof =
settings->sim_defaults.uaprof = g_strdup(override->uaprof);
}
if (flags & MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT) {
settings->flags |= MMS_SETTINGS_FLAG_OVERRIDE_SIZE_LIMIT;
settings->sim_defaults.data.size_limit = override->size_limit;
......
......@@ -27,6 +27,7 @@
#define MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT (0x02)
#define MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT (0x04)
#define MMS_ENGINE_FLAG_OVERRIDE_MAX_PIXELS (0x08)
#define MMS_ENGINE_FLAG_OVERRIDE_UAPROF (0x10)
typedef struct mms_engine MMSEngine;
......
......@@ -29,6 +29,7 @@ struct mms_config {
/* Persistent mutable per-SIM settings */
struct mms_settings_sim_data {
const char* user_agent; /* User agent string */
const char* uaprof; /* User agent profile string */
unsigned int size_limit; /* Maximum size of m-Send.req PDU */
unsigned int max_pixels; /* Pixel limit for outbound images */
gboolean allow_dr; /* Allow sending delivery reports */
......@@ -38,6 +39,7 @@ struct mms_settings_sim_data {
typedef struct mms_settings_sim_data_copy {
MMSSettingsSimData data; /* Settings data */
char* user_agent; /* Allocated copy of user_agent */
char* uaprof; /* Allocated copy of uaprof */
} MMSSettingsSimDataCopy;
/* Instance */
......@@ -51,6 +53,7 @@ struct mms_settings {
#define MMS_SETTINGS_FLAG_OVERRIDE_SIZE_LIMIT (0x02)
#define MMS_SETTINGS_FLAG_OVERRIDE_MAX_PIXELS (0x04)
#define MMS_SETTINGS_FLAG_OVERRIDE_ALLOW_DR (0x08)
#define MMS_SETTINGS_FLAG_OVERRIDE_UAPROF (0x10)
};
/* Class */
......@@ -61,11 +64,14 @@ typedef struct mms_settings_class {
const char* imsi);
} MMSSettingsClass;
/* Default values */
#define MMS_SETTINGS_DEFAULT_USER_AGENT "Mozilla/5.0 (Sailfish; Jolla)"
#define MMS_SETTINGS_DEFAULT_SIZE_LIMIT (300*1024)
#define MMS_SETTINGS_DEFAULT_MAX_PIXELS (3000000)
#define MMS_SETTINGS_DEFAULT_ALLOW_DR TRUE
/* Default values. If the GSettings backend is used (mms-settings-dconf)
* then these should match the default values defined in the GSettings
* schema (org.nemomobile.mms.sim.gschema.xml) */
#define MMS_SETTINGS_DEFAULT_USER_AGENT "Mozilla/5.0 (Sailfish; Jolla)"
#define MMS_SETTINGS_DEFAULT_UAPROF "http://www.jolla.com/uaprof/Jolla.xml"
#define MMS_SETTINGS_DEFAULT_SIZE_LIMIT (300*1024)
#define MMS_SETTINGS_DEFAULT_MAX_PIXELS (3000000)
#define MMS_SETTINGS_DEFAULT_ALLOW_DR TRUE
GType mms_settings_get_type(void);
#define MMS_TYPE_SETTINGS (mms_settings_get_type())
......
......@@ -41,6 +41,7 @@ mms_settings_sim_data_default(
{
memset(data, 0, sizeof(*data));
data->user_agent = MMS_SETTINGS_DEFAULT_USER_AGENT;
data->uaprof = MMS_SETTINGS_DEFAULT_UAPROF;
data->size_limit = MMS_SETTINGS_DEFAULT_SIZE_LIMIT;
data->max_pixels = MMS_SETTINGS_DEFAULT_MAX_PIXELS;
data->allow_dr = MMS_SETTINGS_DEFAULT_ALLOW_DR;
......@@ -52,11 +53,14 @@ mms_settings_sim_data_copy(
const MMSSettingsSimData* src)
{
g_free(dest->user_agent);
g_free(dest->uaprof);
if (src) {
dest->data = *src;
dest->data.user_agent = dest->user_agent = g_strdup(src->user_agent);
dest->data.uaprof = dest->uaprof = g_strdup(src->uaprof);
} else {
dest->user_agent = NULL;
dest->uaprof = NULL;
mms_settings_sim_data_default(&dest->data);
}
}
......
......@@ -192,6 +192,12 @@ mms_http_transfer_new(
soup_message_set_flags(tx->message,
SOUP_MESSAGE_NO_REDIRECT |
SOUP_MESSAGE_NEW_CONNECTION);
if (cfg->uaprof && cfg->uaprof[0]) {
const char* uaprof_header = "x-wap-profile";
MMS_VERBOSE("%s %s", uaprof_header, cfg->uaprof);
soup_message_headers_append(tx->message->request_headers,
uaprof_header, cfg->uaprof);
}
/* We shouldn't need this extra reference but otherwise
* SoupMessage gets deallocated too early. Not sure why. */
g_object_ref(tx->message);
......
......@@ -7,6 +7,11 @@
<summary>User-Agent string.</summary>
<description>The value of User-Agent header to use when communicating with the MMS server.</description>
</key>
<key type="s" name="user-agent-profile">
<default>'http://www.jolla.com/uaprof/Jolla.xml'</default>
<summary>User-Agent Profile string.</summary>
<description>The value of x-wap-profile header to use when communicating with the MMS server.</description>
</key>
<key type="u" name="max-message-size">
<default>307200</default>
<summary>Maximum size of an outbound MMS message.</summary>
......
......@@ -41,6 +41,7 @@ G_DEFINE_TYPE(MMSSettingsDconf, mms_settings_dconf, MMS_TYPE_SETTINGS);
#define MMS_DCONF_PATH_PREFIX "/"
#define MMS_DCONF_KEY_USER_AGENT "user-agent"
#define MMS_DCONF_KEY_UAPROF "user-agent-profile"
#define MMS_DCONF_KEY_SIZE_LIMIT "max-message-size"
#define MMS_DCONF_KEY_MAX_PIXELS "max-pixels"
#define MMS_DCONF_KEY_ALLOW_DR "allow-delivery-reports"
......@@ -63,12 +64,29 @@ mms_settings_dconf_update_user_agent(
} else {
MMSSettingsSimDataCopy* copy = &dconf->imsi_data;
g_free(copy->user_agent);
copy->data.user_agent =
copy->user_agent = value;
copy->data.user_agent = copy->user_agent = value;
MMS_DEBUG("%s = %s", key, copy->data.user_agent);
}
}
static
void
mms_settings_dconf_update_uaprof(
MMSSettingsDconf* dconf,
const char* key)
{
char* value = g_settings_get_string(dconf->gs, key);
if (dconf->settings.flags & MMS_SETTINGS_FLAG_OVERRIDE_UAPROF) {
MMS_DEBUG("%s = %s (ignored)", key, value);
g_free(value);
} else {
MMSSettingsSimDataCopy* copy = &dconf->imsi_data;
g_free(copy->uaprof);
copy->data.uaprof = copy->uaprof = value;
MMS_DEBUG("%s = %s", key, copy->data.uaprof);
}
}
static
void
mms_settings_dconf_update_size_limit(
......@@ -101,7 +119,7 @@ mms_settings_dconf_update_max_pixels(
static
void
mms_settings_dconf_update_max_allow_dr(
mms_settings_dconf_update_allow_dr(
MMSSettingsDconf* dconf,
const char* key)
{
......@@ -115,10 +133,11 @@ mms_settings_dconf_update_max_allow_dr(
}
static const MMSSettingsDconfKey mms_settings_dconf_keys[] = {
{ MMS_DCONF_KEY_USER_AGENT, mms_settings_dconf_update_user_agent },
{ MMS_DCONF_KEY_SIZE_LIMIT, mms_settings_dconf_update_size_limit },
{ MMS_DCONF_KEY_MAX_PIXELS, mms_settings_dconf_update_max_pixels },
{ MMS_DCONF_KEY_ALLOW_DR, mms_settings_dconf_update_max_allow_dr },
{ MMS_DCONF_KEY_USER_AGENT, mms_settings_dconf_update_user_agent },
{ MMS_DCONF_KEY_UAPROF, mms_settings_dconf_update_uaprof },
{ MMS_DCONF_KEY_SIZE_LIMIT, mms_settings_dconf_update_size_limit },
{ MMS_DCONF_KEY_MAX_PIXELS, mms_settings_dconf_update_max_pixels },
{ MMS_DCONF_KEY_ALLOW_DR, mms_settings_dconf_update_allow_dr },
};
static
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment