static mUpnpXmlNode *mupnp_control_action_response_createresponsenode(mUpnpAction *action) { mUpnpXmlNode *actionNameResNode; char nodeName[MUPNP_ACTOINNAME_LEN_MAX + sizeof(MUPNP_SOAP_METHODNS) + sizeof(MUPNP_SOAP_DELIM) + sizeof(MUPNP_SOAP_RESPONSE) + 1]; char attrName[sizeof(MUPNP_SOAP_ATTRIBUTE_XMLNS) + sizeof(MUPNP_SOAP_DELIM) + sizeof(MUPNP_SOAP_METHODNS) + 1]; const char *actionName; mUpnpXmlNode *serviceNode; mUpnpService *service; mUpnpArgumentList *argList; mUpnpArgument *arg; mUpnpXmlNode *argNode; mupnp_log_debug_l4("Entering...\n"); actionNameResNode = mupnp_xml_node_new(); /* action name */ actionName = mupnp_action_getname(action); mupnp_strcpy(nodeName, MUPNP_SOAP_METHODNS); mupnp_strcat(nodeName, MUPNP_SOAP_DELIM); mupnp_strncat(nodeName, actionName, MUPNP_ACTOINNAME_LEN_MAX); mupnp_strcat(nodeName, MUPNP_SOAP_RESPONSE); mupnp_xml_node_setname(actionNameResNode, nodeName); /* service attribute */ serviceNode = mupnp_service_getservicenode(mupnp_action_getservice(action)); if (serviceNode != NULL) { service = mupnp_service_new(); mupnp_service_setservicenode(service, serviceNode); mupnp_strcpy(attrName, MUPNP_SOAP_ATTRIBUTE_XMLNS); mupnp_strcat(attrName, MUPNP_SOAP_DELIM); mupnp_strcat(attrName, MUPNP_SOAP_METHODNS); mupnp_xml_node_setattribute(actionNameResNode, attrName, mupnp_service_getservicetype(service)); mupnp_service_delete(service); } /* arguments */ argList = mupnp_action_getargumentlist(action); for (arg = mupnp_argumentlist_gets(argList); arg != NULL; arg = mupnp_argument_next(arg)) { if (mupnp_argument_isoutdirection(arg) == false) continue; argNode = mupnp_xml_node_new(); mupnp_xml_node_setname(argNode, mupnp_argument_getname(arg)); mupnp_xml_node_setvalue(argNode, mupnp_argument_getvalue(arg)); mupnp_xml_node_addchildnode(actionNameResNode, argNode); } return actionNameResNode; mupnp_log_debug_l4("Leaving...\n"); }
static int filter_duplicate_m_search(mUpnpSSDPPacket *ssdpPkt) { mUpnpTime *timestamps = ssdpPkt->timestamps; size_t s_length; int loc; const char *st; char *id_string, *r_address, port[6]; mUpnpTime curr_time; mupnp_log_debug_l4("Entering...\n"); /* Initializing hash table to zero */ if (!ssdpPkt->initialized) { ssdpPkt->initialized = 1; memset(timestamps, '\0', MUPNP_SSDP_FILTER_TABLE_SIZE * sizeof( mUpnpTime )); } r_address = mupnp_string_getvalue(ssdpPkt->dgmPkt->remoteAddress); st = mupnp_ssdp_packet_getst(ssdpPkt); sprintf(port, "%d", ssdpPkt->dgmPkt->remotePort); /* Catenating remote address string with ssdp ST header field. */ s_length = strlen( r_address ) + strlen( st ) + strlen( port ); id_string = (char *)malloc( s_length + 1 ); if ( NULL == id_string ) { mupnp_log_debug_s("Memory allocation problem!\n"); return FALSE; } memset(id_string, '\0', s_length + 1); mupnp_strcat(id_string, r_address ); mupnp_strcat(id_string, port); mupnp_strcat(id_string, st ); loc = simple_string_hash(id_string, MUPNP_SSDP_FILTER_TABLE_SIZE); mupnp_log_debug("Calculated hash: %d\n", loc); free(id_string); curr_time = mupnp_getcurrentsystemtime(); if ( 0 == timestamps[loc] ) { timestamps[loc] = curr_time; mupnp_log_debug("First packet... Updating hash table.\n"); return FALSE; } else if ( ( curr_time - timestamps[loc] ) < MUPNP_DEVICE_M_SEARCH_FILTER_INTERVAL ) { mupnp_log_debug("Filtering packet!\n"); timestamps[loc] = curr_time; return TRUE; } else { timestamps[loc] = curr_time; mupnp_log_debug("Old timestamp found, just updating it.\n"); return FALSE; } mupnp_log_debug_l4("Leaving...\n"); }