text
stringlengths
0
1.99k
if ((ret = pmlist_Find(ext_port, proto, int_ip)) != NULL)
{
trace(3, "Found port map to already exist. Replacing");
pmlist_Delete(ret);
}
new = pmlist_NewNode(atoi(bool_enabled), atol(int_duration), "",
ext_port, int_port, proto, int_ip, desc);
result = pmlist_PushBack(new);
...
}
...
}
The pmlist_NewNode() function, defined in the pmlist.c file, performs
checks to ensure that the values contained in the SOAP request are valid.
To clarify the information presented so far, the diagram below summarizes
the call stack as neatly as possible.
+------------------+
| main() |
+------------------+
|
v
+------------------------+
| EventHandler() |
+------------------------+
|
v
+---------------------------+
| HandleActionRequest() |
+---------------------------+
|
v
+--------------------------+
| AddPortMapping() |
+--------------------------+
/ \
v v
+------------------+ +---------------------+
| pmlist_NewNode() | | pmlist_PushBack() |<---+
+------------------+ +---------------------+ |
| | |
| | |
+----struct portMap------|---------------+
|
v
+-------------------------+
| pmlist_AddPortMapping() |
+-------------------------+
|
v
+------------+
| system() |
+------------+
struct portMap* pmlist_NewNode(int enabled, long int duration,
char *remoteHost, char *externalPort,
char *internalPort, char *protocol,
char *internalClient, char *desc)
{
struct portMap* temp = (struct portMap*) malloc(
sizeof(struct portMap)
);
temp->m_PortMappingEnabled = enabled;
if (remoteHost && strlen(remoteHost) < sizeof(temp->m_RemoteHost))
strcpy(temp->m_RemoteHost, remoteHost);
else
strcpy(temp->m_RemoteHost, "");
if (strlen(externalPort) < sizeof(temp->m_ExternalPort))
strcpy(temp->m_ExternalPort, externalPort);
else
strcpy(temp->m_ExternalPort, "");
if (strlen(internalPort) < sizeof(temp->m_InternalPort))
strcpy(temp->m_InternalPort, internalPort);
else
strcpy(temp->m_InternalPort, "");
if (strlen(protocol) < sizeof(temp->m_PortMappingProtocol))
strcpy(temp->m_PortMappingProtocol, protocol);
else
strcpy(temp->m_PortMappingProtocol, "");
if (strlen(internalClient) < sizeof(temp->m_InternalClient))
strcpy(temp->m_InternalClient, internalClient);
else
strcpy(temp->m_InternalClient, "");
if (strlen(desc) < sizeof(temp->m_PortMappingDescription))
strcpy(temp->m_PortMappingDescription, desc);
else
strcpy(temp->m_PortMappingDescription, "");
temp->m_PortMappingLeaseDuration = duration;
temp->next = NULL;
temp->prev = NULL;