extcap: Fix of handling default values
This commit is contained in:
parent
02238edf92
commit
0c0f731c92
25
extcap.c
25
extcap.c
|
@ -1019,7 +1019,7 @@ extcap_get_if_configuration_values(const char * ifname, const char * argname, GH
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
extcap_has_configuration(const char *ifname, gboolean is_required)
|
_extcap_requires_configuration_int(const char *ifname, gboolean check_required)
|
||||||
{
|
{
|
||||||
GList *arguments = 0;
|
GList *arguments = 0;
|
||||||
GList *walker = 0, * item = 0;
|
GList *walker = 0, * item = 0;
|
||||||
|
@ -1039,10 +1039,11 @@ extcap_has_configuration(const char *ifname, gboolean is_required)
|
||||||
{
|
{
|
||||||
extcap_arg *arg = (extcap_arg *)(item->data);
|
extcap_arg *arg = (extcap_arg *)(item->data);
|
||||||
/* Should required options be present, or any kind of options */
|
/* Should required options be present, or any kind of options */
|
||||||
if (!is_required)
|
if (!check_required)
|
||||||
{
|
{
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
|
/* Following branch is executed when check of required items is requested */
|
||||||
else if (arg->is_required)
|
else if (arg->is_required)
|
||||||
{
|
{
|
||||||
const gchar *stored = NULL;
|
const gchar *stored = NULL;
|
||||||
|
@ -1060,13 +1061,7 @@ extcap_has_configuration(const char *ifname, gboolean is_required)
|
||||||
|
|
||||||
if (arg->is_required)
|
if (arg->is_required)
|
||||||
{
|
{
|
||||||
/* If stored and defval is identical and the argument is required,
|
if (!defval && (!stored || !*stored))
|
||||||
* configuration is needed */
|
|
||||||
if (defval && stored && g_strcmp0(stored, defval) == 0)
|
|
||||||
{
|
|
||||||
found = TRUE;
|
|
||||||
}
|
|
||||||
else if (!defval && (!stored || !*stored))
|
|
||||||
{
|
{
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1091,6 +1086,18 @@ extcap_has_configuration(const char *ifname, gboolean is_required)
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
extcap_has_configuration(const char *ifname)
|
||||||
|
{
|
||||||
|
return _extcap_requires_configuration_int(ifname, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
extcap_requires_configuration(const char *ifname)
|
||||||
|
{
|
||||||
|
return _extcap_requires_configuration_int(ifname, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean cb_verify_filter(extcap_callback_info_t cb_info)
|
static gboolean cb_verify_filter(extcap_callback_info_t cb_info)
|
||||||
{
|
{
|
||||||
extcap_filter_status *status = (extcap_filter_status *)cb_info.data;
|
extcap_filter_status *status = (extcap_filter_status *)cb_info.data;
|
||||||
|
|
15
extcap.h
15
extcap.h
|
@ -185,17 +185,22 @@ extcap_free_if_configuration(GList *list, gboolean free_args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if an interface has configurable options.
|
* Checks to see if an interface has configurable options.
|
||||||
* If is_required is FALSE: returns TRUE if the extcap interface has
|
* Initializes the extcap interface list if that hasn't already been done.
|
||||||
* configurable options.
|
* @param ifname Interface to check.
|
||||||
* If is_required is TRUE: returns TRUE when the extcap interface has
|
*/
|
||||||
|
gboolean
|
||||||
|
extcap_has_configuration(const char * ifname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an interface has configurable options and if all are configured.
|
||||||
|
* Returns TRUE when the extcap interface has
|
||||||
* configurable options that required modification. (For example, when an
|
* configurable options that required modification. (For example, when an
|
||||||
* argument is required but empty.)
|
* argument is required but empty.)
|
||||||
* Initializes the extcap interface list if that hasn't already been done.
|
* Initializes the extcap interface list if that hasn't already been done.
|
||||||
* @param ifname Interface to check.
|
* @param ifname Interface to check.
|
||||||
* @param is_required Required configuration flag.
|
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
extcap_has_configuration(const char * ifname, gboolean is_required);
|
extcap_requires_configuration(const char * ifname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if the interface has an associated toolbar.
|
* Checks to see if the interface has an associated toolbar.
|
||||||
|
|
|
@ -822,7 +822,7 @@ void LograyMainWindow::startCapture(QStringList interfaces _U_) {
|
||||||
/* device is EXTCAP and is selected. Check if all mandatory
|
/* device is EXTCAP and is selected. Check if all mandatory
|
||||||
* settings are set.
|
* settings are set.
|
||||||
*/
|
*/
|
||||||
if (extcap_has_configuration(device->name, TRUE))
|
if (extcap_requires_configuration(device->name))
|
||||||
{
|
{
|
||||||
/* Request openning of extcap options dialog */
|
/* Request openning of extcap options dialog */
|
||||||
QString device_name(device->name);
|
QString device_name(device->name);
|
||||||
|
|
|
@ -504,7 +504,7 @@ void CaptureOptionsDialog::itemClicked(QTreeWidgetItem *item, int column)
|
||||||
if (device->if_info.type == IF_EXTCAP) {
|
if (device->if_info.type == IF_EXTCAP) {
|
||||||
/* this checks if configuration is required and not yet provided or saved via prefs */
|
/* this checks if configuration is required and not yet provided or saved via prefs */
|
||||||
QString device_name = ti->data(col_extcap_, Qt::UserRole).value<QString>();
|
QString device_name = ti->data(col_extcap_, Qt::UserRole).value<QString>();
|
||||||
if (extcap_has_configuration((const char *)(device_name.toStdString().c_str()), FALSE))
|
if (extcap_has_configuration((const char *)(device_name.toStdString().c_str())))
|
||||||
{
|
{
|
||||||
emit showExtcapOptions(device_name, false);
|
emit showExtcapOptions(device_name, false);
|
||||||
return;
|
return;
|
||||||
|
@ -538,7 +538,7 @@ void CaptureOptionsDialog::itemDoubleClicked(QTreeWidgetItem *item, int column)
|
||||||
if (device->if_info.type == IF_EXTCAP) {
|
if (device->if_info.type == IF_EXTCAP) {
|
||||||
/* this checks if configuration is required and not yet provided or saved via prefs */
|
/* this checks if configuration is required and not yet provided or saved via prefs */
|
||||||
QString device_name = ti->data(col_extcap_, Qt::UserRole).value<QString>();
|
QString device_name = ti->data(col_extcap_, Qt::UserRole).value<QString>();
|
||||||
if (extcap_has_configuration((const char *)(device_name.toStdString().c_str()), TRUE))
|
if (extcap_requires_configuration((const char *)(device_name.toStdString().c_str())))
|
||||||
{
|
{
|
||||||
emit showExtcapOptions(device_name, true);
|
emit showExtcapOptions(device_name, true);
|
||||||
return;
|
return;
|
||||||
|
@ -619,7 +619,7 @@ void CaptureOptionsDialog::on_buttonBox_accepted()
|
||||||
if (device && device->if_info.type == IF_EXTCAP) {
|
if (device && device->if_info.type == IF_EXTCAP) {
|
||||||
/* this checks if configuration is required and not yet provided or saved via prefs */
|
/* this checks if configuration is required and not yet provided or saved via prefs */
|
||||||
QString device_name = ti->data(col_extcap_, Qt::UserRole).value<QString>();
|
QString device_name = ti->data(col_extcap_, Qt::UserRole).value<QString>();
|
||||||
if (extcap_has_configuration((const char *)(device_name.toStdString().c_str()), TRUE))
|
if (extcap_requires_configuration((const char *)(device_name.toStdString().c_str())))
|
||||||
{
|
{
|
||||||
emit showExtcapOptions(device_name, true);
|
emit showExtcapOptions(device_name, true);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -429,11 +429,6 @@ void ExtArgRadio::setDefaultValue()
|
||||||
ExtArgBool::ExtArgBool(extcap_arg * argument, QObject * parent) :
|
ExtArgBool::ExtArgBool(extcap_arg * argument, QObject * parent) :
|
||||||
ExtcapArgument(argument, parent), boolBox(0) {}
|
ExtcapArgument(argument, parent), boolBox(0) {}
|
||||||
|
|
||||||
QWidget * ExtArgBool::createLabel(QWidget * parent)
|
|
||||||
{
|
|
||||||
return new QWidget(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget * ExtArgBool::createEditor(QWidget * parent)
|
QWidget * ExtArgBool::createEditor(QWidget * parent)
|
||||||
{
|
{
|
||||||
bool state = defaultBool();
|
bool state = defaultBool();
|
||||||
|
@ -486,7 +481,7 @@ QString ExtArgBool::prefValue()
|
||||||
|
|
||||||
bool ExtArgBool::isValid()
|
bool ExtArgBool::isValid()
|
||||||
{
|
{
|
||||||
/* A bool is allways valid, but the base function checks on string length,
|
/* A bool is always valid, but the base function checks on string length,
|
||||||
* which will fail with boolflags */
|
* which will fail with boolflags */
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,7 +235,6 @@ class ExtArgBool : public ExtcapArgument
|
||||||
public:
|
public:
|
||||||
ExtArgBool(extcap_arg * argument, QObject *parent = Q_NULLPTR);
|
ExtArgBool(extcap_arg * argument, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
virtual QWidget * createLabel(QWidget * parent);
|
|
||||||
virtual QWidget * createEditor(QWidget * parent);
|
virtual QWidget * createEditor(QWidget * parent);
|
||||||
|
|
||||||
virtual QString call();
|
virtual QString call();
|
||||||
|
|
|
@ -448,15 +448,32 @@ bool ExtcapOptionsDialog::saveOptionToCaptureInfo()
|
||||||
{
|
{
|
||||||
QString call = (*iter)->call();
|
QString call = (*iter)->call();
|
||||||
QString value = (*iter)->value();
|
QString value = (*iter)->value();
|
||||||
|
QString prefValue = (*iter)->prefValue();
|
||||||
|
|
||||||
if ((*iter)->argument()->arg_type != EXTCAP_ARG_BOOLFLAG && value.length() == 0)
|
if ((*iter)->argument()->arg_type != EXTCAP_ARG_BOOLFLAG && value.length() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (call.length() <= 0)
|
if (call.length() <= 0) {
|
||||||
|
/* BOOLFLAG was cleared, make its value empty */
|
||||||
|
if ((*iter)->argument()->arg_type == EXTCAP_ARG_BOOLFLAG) {
|
||||||
|
*(*iter)->argument()->pref_valptr[0] = 0;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (value.compare((*iter)->defaultValue()) == 0)
|
if (value.compare((*iter)->defaultValue()) == 0) {
|
||||||
|
extcap_arg *arg = (*iter)->argument();
|
||||||
|
|
||||||
|
// If previous value is not default, set it to default value
|
||||||
|
if (arg->default_complex != NULL && arg->default_complex->_val != NULL) {
|
||||||
|
g_free(*arg->pref_valptr);
|
||||||
|
*arg->pref_valptr = g_strdup(arg->default_complex->_val);
|
||||||
|
} else {
|
||||||
|
// Set empty value if there is no default value
|
||||||
|
*arg->pref_valptr[0] = 0;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
gchar * call_string = g_strdup(call.toStdString().c_str());
|
gchar * call_string = g_strdup(call.toStdString().c_str());
|
||||||
gchar * value_string = NULL;
|
gchar * value_string = NULL;
|
||||||
|
@ -464,6 +481,14 @@ bool ExtcapOptionsDialog::saveOptionToCaptureInfo()
|
||||||
value_string = g_strdup(value.toStdString().c_str());
|
value_string = g_strdup(value.toStdString().c_str());
|
||||||
|
|
||||||
g_hash_table_insert(ret_args, call_string, value_string);
|
g_hash_table_insert(ret_args, call_string, value_string);
|
||||||
|
|
||||||
|
// For current value we need strdup even it is empty
|
||||||
|
value_string = g_strdup(prefValue.toStdString().c_str());
|
||||||
|
// Update current value with new value
|
||||||
|
// We use prefValue because for bool/boolflag it returns value
|
||||||
|
// even it is false
|
||||||
|
g_free(*(*iter)->argument()->pref_valptr);
|
||||||
|
*(*iter)->argument()->pref_valptr = value_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device->external_cap_args_settings != NULL)
|
if (device->external_cap_args_settings != NULL)
|
||||||
|
@ -558,7 +583,9 @@ GHashTable *ExtcapOptionsDialog::getArgumentSettings(bool useCallsAsKey, bool in
|
||||||
if (dynamic_cast<ExtArgBool *>((*iter)) != NULL)
|
if (dynamic_cast<ExtArgBool *>((*iter)) != NULL)
|
||||||
{
|
{
|
||||||
value = ((ExtArgBool *)*iter)->prefValue();
|
value = ((ExtArgBool *)*iter)->prefValue();
|
||||||
isBoolflag = true;
|
// For boolflag there should be no value
|
||||||
|
if ((*iter)->argument()->arg_type != EXTCAP_ARG_BOOLFLAG)
|
||||||
|
isBoolflag = true;
|
||||||
}
|
}
|
||||||
else if (dynamic_cast<ExtArgRadio *>((*iter)) != NULL)
|
else if (dynamic_cast<ExtArgRadio *>((*iter)) != NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -426,7 +426,7 @@ void InterfaceFrame::on_interfaceTree_doubleClicked(const QModelIndex &index)
|
||||||
if (extcap_string.length() > 0)
|
if (extcap_string.length() > 0)
|
||||||
{
|
{
|
||||||
/* this checks if configuration is required and not yet provided or saved via prefs */
|
/* this checks if configuration is required and not yet provided or saved via prefs */
|
||||||
if (extcap_has_configuration((const char *)(device_name.toStdString().c_str()), TRUE))
|
if (extcap_requires_configuration((const char *)(device_name.toStdString().c_str())))
|
||||||
{
|
{
|
||||||
emit showExtcapOptions(device_name, true);
|
emit showExtcapOptions(device_name, true);
|
||||||
return;
|
return;
|
||||||
|
@ -458,7 +458,7 @@ void InterfaceFrame::on_interfaceTree_clicked(const QModelIndex &index)
|
||||||
if (extcap_string.length() > 0)
|
if (extcap_string.length() > 0)
|
||||||
{
|
{
|
||||||
/* this checks if configuration is required and not yet provided or saved via prefs */
|
/* this checks if configuration is required and not yet provided or saved via prefs */
|
||||||
if (extcap_has_configuration((const char *)(device_name.toStdString().c_str()), FALSE))
|
if (extcap_has_configuration((const char *)(device_name.toStdString().c_str())))
|
||||||
{
|
{
|
||||||
emit showExtcapOptions(device_name, false);
|
emit showExtcapOptions(device_name, false);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -871,7 +871,7 @@ void WiresharkMainWindow::startCapture(QStringList interfaces _U_) {
|
||||||
/* device is EXTCAP and is selected. Check if all mandatory
|
/* device is EXTCAP and is selected. Check if all mandatory
|
||||||
* settings are set.
|
* settings are set.
|
||||||
*/
|
*/
|
||||||
if (extcap_has_configuration(device->name, TRUE))
|
if (extcap_requires_configuration(device->name))
|
||||||
{
|
{
|
||||||
/* Request openning of extcap options dialog */
|
/* Request openning of extcap options dialog */
|
||||||
QString device_name(device->name);
|
QString device_name(device->name);
|
||||||
|
|
Loading…
Reference in New Issue