Example #1
0
void mupnp_controlpoint_adddevicebyssdppacket(mUpnpControlPoint* ctrlPoint, mUpnpSSDPPacket* ssdpPkt)
{
  mUpnpDevice* dev = NULL;
  const char* usn = NULL;
  char udn[MUPNP_UDN_LEN_MAX];
  MUPNP_DEVICE_LISTENER listener = NULL;
  mUpnpDeviceStatus status = 0;

  mupnp_log_debug_l4("Entering...\n");

  listener = mupnp_controlpoint_getdevicelistener(ctrlPoint);

  usn = mupnp_ssdp_packet_getusn(ssdpPkt);
  mupnp_usn_getudn(usn, udn, sizeof(udn));

  mupnp_controlpoint_lock(ctrlPoint);

  dev = mupnp_controlpoint_getdevicebyudn(ctrlPoint, udn);

  if (dev != NULL) {
    /* Device was found from local cache */
    if (mupnp_device_updatefromssdppacket(dev, ssdpPkt) == true) {
      mupnp_mutex_lock(ctrlPoint->expMutex);
      mupnp_cond_signal(ctrlPoint->expCond);
      mupnp_mutex_unlock(ctrlPoint->expMutex);

      /* Device was successfully updated */
      status = mUpnpDeviceStatusUpdated;
    }
    else { /* Problems occurred in device update */
      status = mUpnpDeviceStatusInvalid;
    }
  }
  else {
    /* This is a new device */
    dev = mupnp_controlpoint_createdevicefromssdkpacket(ssdpPkt);
    if (dev == NULL) {
      /* Problems occurred in device creation */
      status = mUpnpDeviceStatusInvalid;
    }
    else {
      mupnp_controlpoint_adddevice(ctrlPoint, dev);

      /* Device added, wake up expirationhandler thread */
      mupnp_mutex_lock(ctrlPoint->expMutex);
      mupnp_cond_signal(ctrlPoint->expCond);
      mupnp_mutex_unlock(ctrlPoint->expMutex);

      status = mUpnpDeviceStatusAdded;
    }
  }

  mupnp_controlpoint_unlock(ctrlPoint);

  if (listener != NULL) {
    listener(ctrlPoint, udn, status);
  }

  mupnp_log_debug_l4("Leaving...\n");
}
Example #2
0
bool mupnp_controlpoint_lock(mUpnpControlPoint *ctrlPoint)
{
	mupnp_log_debug_l4("Entering...\n");

	return mupnp_mutex_lock(ctrlPoint->mutex);

	mupnp_log_debug_l4("Leaving...\n");
}
void mupnp_http_persistentconnection_lock(void)
{
	mupnp_log_debug_l4("Entering...\n");

       if (persistent_connection_mutex == NULL) return;
       mupnp_mutex_lock(persistent_connection_mutex);

	mupnp_log_debug_l4("Leaving...\n");
}
Example #4
0
BOOL mupnp_cond_wait(mUpnpCond *cond, mUpnpMutex *mutex, unsigned long timeout)
{
#if defined(WIN32) && !defined(ITRON)
	DWORD timeout_s = (timeout == 0 ? INFINITE : timeout);
	mupnp_mutex_unlock(mutex);
	WaitForSingleObject(cond->condID, timeout_s);
	mupnp_mutex_lock(mutex);
#elif defined(BTRON)
	/* TODO: Add implementation */
#elif defined(ITRON)
	/* TODO: Add implementation */
#elif defined(TENGINE) && !defined(PROCESS_BASE)
	/* TODO: Add implementation */
#elif defined(TENGINE) && defined(PROCESS_BASE)
	/* TODO: Add implementation */
#else
	struct timeval  now;
	struct timespec timeout_s;
	
	mupnp_log_debug_l4("Entering...\n");

	gettimeofday(&now, NULL);
	
	if (timeout < 1)
	{
		pthread_cond_wait(&cond->condID, &mutex->mutexID);
	} else {
		timeout_s.tv_sec = now.tv_sec + timeout;
		timeout_s.tv_nsec = now.tv_usec * 1000;
		pthread_cond_timedwait(&cond->condID, &mutex->mutexID, &timeout_s);
	}
#endif
	mupnp_log_debug_l4("Leaving...\n");

	return TRUE;
}
Example #5
0
File: log.c Project: dwlinux/mupnpc
/**
 * Multiplex log messages into different targets (streams), should be used via convenience macros
 * @param severity Message severity
 * @param file File name where the function is called
 * @param line_n Line number where the function is called
 * @param function Function name where this function is called
 * @param format Format string for the actual log message
 * @param ... Possible parameters for the format string
 */
void mupnp_log_print(int severity, const char *file, int line_n, const char *function, const char *format, ...)
{
	va_list list;

	char log_line[MAX_LOG_STRING], *l_ptr, t_ptr[MAX_LOG_STRING];
	int prefix_length = -1;
	struct fd_list *temp = NULL;
	size_t timestamp;
	struct tm *timestamp_human_readable;

	/* If output targets are empty, do return */
    if (!descriptor_list)
		return;

	/* If logger is not initialized, do it now */
	if (!initialized) log_init_with_defaults();

	/* If separator is not set, do it now */
	if (NULL == separator) mupnp_log_set_separator(" : ");

	/* Create a mutex */
	if (!print_mutex)
		print_mutex = mupnp_mutex_new();
	mupnp_mutex_lock(print_mutex);
	
	/* Create timestamp for the log prefix */
	timestamp = time(NULL);
	timestamp_human_readable = localtime(&timestamp);
	
#if !defined(WIN32)
	strftime(t_ptr, MAX_LOG_STRING, "%c", timestamp_human_readable);
#else
	snprintf(log_line, MAX_LOG_STRING, "%d-%d-%d %d:%d %d", 
		timestamp_human_readable->tm_year + 1900,
		timestamp_human_readable->tm_mon + 1,
		timestamp_human_readable->tm_mday,
		timestamp_human_readable->tm_hour,
		timestamp_human_readable->tm_min,
		timestamp_human_readable->tm_sec);
#endif
	/* Creating the full log prefix */
	prefix_length = snprintf(log_line, MAX_LOG_STRING, "%s%s%s%s%s%s%d%s%s%s ", 
			t_ptr, 
			separator, 
			map_severity(severity), 
			separator,
			file, 
			separator,
			line_n,
			separator,
			function,
			separator);

	/* Setting pointer where the actual message should start */
	l_ptr = &log_line[prefix_length];

	/* Filling out rest of the log message */
	va_start(list, format);
	vsnprintf(log_line + prefix_length, MAX_LOG_STRING - prefix_length, format, list);
	va_end(list);

	/* Multiplexing the created message into targets */
	for( temp = descriptor_list; temp; temp = temp->next )
	{
		if ( severity == ( severity & temp->apply_mask ) )
		{
			fputs(log_line, temp->fd);
		}
	}

	mupnp_mutex_unlock(print_mutex);
}