Skip to content

Commit

Permalink
netxml-ups: incremental commit
Browse files Browse the repository at this point in the history
1/ Removed useless System.Network.* NMC variables
2/ Removed usage of strndup & fixed a related bug
  • Loading branch information
Vaclav Krpec authored and Vaclav Krpec committed Jun 6, 2013
1 parent 6ffc259 commit e54ce1c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
47 changes: 23 additions & 24 deletions drivers/mge-xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,27 +539,11 @@ static const char *mge_timer_shutdown(const char *val)

static xml_info_t mge_xml2nut[] = {
/* NMC configuration (mapped 1:1 for now) */
{ "System.Network.HostName", ST_FLAG_RW, 0, "System.Network.HostName", 0, 0, NULL },
{ "System.Network.IPAddress", ST_FLAG_RW, 0, "System.Network.IPAddress", 0, 0, NULL },
{ "System.Network.IPMask", ST_FLAG_RW, 0, "System.Network.IPMask", 0, 0, NULL },
{ "System.Network.IPGateway", ST_FLAG_RW, 0, "System.Network.IPGateway", 0, 0, NULL },
{ "System.Network.DomainName", ST_FLAG_RW, 0, "System.Network.DomainName", 0, 0, NULL },
{ "System.Network.DHCP", ST_FLAG_RW, 0, "System.Network.DHCP", 0, 0, NULL },
{ "System.Network.PrimaryDNS", ST_FLAG_RW, 0, "System.Network.PrimaryDNS", 0, 0, NULL },
{ "System.Network.SecondaryDNS", ST_FLAG_RW, 0, "System.Network.SecondaryDNS", 0, 0, NULL },
{ "System.Network.IPv6Enable", ST_FLAG_RW, 0, "System.Network.IPv6Enable", 0, 0, NULL },
{ "System.Network.IPv6AutoConfig", ST_FLAG_RW, 0, "System.Network.IPv6AutoConfig", 0, 0, NULL },
{ "System.Network.IPv6Address1", ST_FLAG_RW, 0, "System.Network.IPv6Address1", 0, 0, NULL },
{ "System.Network.PrefixLength", ST_FLAG_RW, 0, "System.Network.PrefixLength", 0, 0, NULL },
{ "System.Network.IPv6DefaultGateway", ST_FLAG_RW, 0, "System.Network.IPv6DefaultGateway", 0, 0, NULL },
{ "System.Network.SmtpServer.HostName", ST_FLAG_RW, 0, "System.Network.SmtpServer.HostName", 0, 0, NULL },
{ "System.Network.SmtpServer.Authentication", ST_FLAG_RW, 0, "System.Network.SmtpServer.Authentication", 0, 0, NULL },
{ "System.Network.SmtpServer.Login", ST_FLAG_RW, 0, "System.Network.SmtpServer.Login", 0, 0, NULL },
{ "System.Network.SmtpServer.Password", ST_FLAG_RW, 0, "System.Network.SmtpServer.Password", 0, 0, NULL },
{ "System.Contact", ST_FLAG_RW, 0, "System.Contact", 0, 0, NULL },
{ "System.Location", ST_FLAG_RW, 0, "System.Location", 0, 0, NULL },
{ "System.Language", ST_FLAG_RW, 0, "System.Language", 0, 0, NULL },
{ "device.contact", ST_FLAG_RW, 0, "System.Contact", 0, 0, NULL },
{ "device.location", ST_FLAG_RW, 0, "System.Location", 0, 0, NULL },
/* Not used for now; might however be used in future for history & stats collection
{ "System.History.Log.Interval", ST_FLAG_RW, 0, "System.History.Log.Interval", 0, 0, NULL },
*/
{ "System.Environment.Log.Interval", ST_FLAG_RW, 0, "System.Environment.Log.Interval", 0, 0, NULL },
{ "System.Outlet[1].iName", ST_FLAG_RW, 0, "System.Outlet[1].iName", 0, 0, NULL },
/* Mapped as ups.delay.shutdown
Expand Down Expand Up @@ -1441,7 +1425,7 @@ const char *vname_mge_xml2nut(const char *name) {
return NULL;
}

const char *vvalue_mge_xml2nut(const char *name, const char *value) {
char *vvalue_mge_xml2nut(const char *name, const char *value, size_t len) {
assert(NULL != name);

size_t i = 0;
Expand All @@ -1451,10 +1435,25 @@ const char *vvalue_mge_xml2nut(const char *name, const char *value) {

if (NULL != info->nutname)
if (0 == strcasecmp(name, info->nutname)) {
if (NULL != info->convert)
return info->convert(value);
/* Copy value */
char *vcpy = (char *)malloc((len + 1) * sizeof(char));

if (NULL == vcpy)
return vcpy;

memcpy(vcpy, value, len * sizeof(char));
vcpy[len] = '\0';

/* Convert */
if (NULL != info->convert) {
char *vconv = info->convert(vcpy);

free(vcpy);

return vconv;
}
else
return value;
return vcpy;
}
}

Expand Down
6 changes: 5 additions & 1 deletion drivers/mge-xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ const char * vname_mge_xml2nut(const char *name);
/**
* \brief Convert MGE XML variable value to NUT value
*
* The function produces a newly created C-string that should
* be destroyed using \c free.
*
* \param name NUT variable name
* \param value MGE XML variable value
* \param len MGE XML variable value length (in characters)
*
* \return NUT variable value
*/
const char *vvalue_mge_xml2nut(const char *name, const char *value);
char *vvalue_mge_xml2nut(const char *name, const char *value, size_t len);

/**
* \brief Register set of R/W variables
Expand Down
6 changes: 3 additions & 3 deletions drivers/netxml-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,15 +1404,15 @@ static int set_object_raw_resp_cdata(
return state;

if (OBJECT_OK == handle->status) {
const char *value;
char *value;

/* Set last object value */
assert(NULL != handle->tail);
assert(NULL != handle->tail->payld.resp.name);

value = vvalue_mge_xml2nut(handle->tail->payld.resp.name, cdata);
value = vvalue_mge_xml2nut(handle->tail->payld.resp.name, cdata, len);

handle->tail->payld.resp.value = strndup(value, len);
handle->tail->payld.resp.value = value;

if (NULL == handle->tail->payld.resp.value)
handle->status = OBJECT_ERROR;
Expand Down

0 comments on commit e54ce1c

Please sign in to comment.