예제 #1
0
int
coap_delete_subscription(coap_context_t *context,
			 coap_key_t key,
			 struct sockaddr_in6 *subscriber) {
  coap_list_t *prev, *node;

  if (!context || !subscriber || key == COAP_INVALID_HASHKEY)
    return 0;

  for (prev = NULL, node = context->subscriptions; node;
       prev = node, node = node->next) {
    if (COAP_SUBSCRIPTION(node)->resource == key) {
      if (subscriber->sin6_port == COAP_SUBSCRIPTION(node)->subscriber.sin6_port
	  && memcmp(&subscriber->sin6_addr,
		    &COAP_SUBSCRIPTION(node)->subscriber.sin6_addr,
		    sizeof(struct in6_addr)) == 0) {

	if (!prev) {
	  context->subscriptions = node->next;
	  coap_free(COAP_SUBSCRIPTION(node)->token.s);
	  coap_delete(node);
	} else {
	  prev->next = node->next;
	  coap_free(COAP_SUBSCRIPTION(node)->token.s);
	  coap_delete(node);
	}
	return 1;
      }
    }
  }
  return 0;
}
예제 #2
0
void
coap_check_subscriptions(coap_context_t *context) {
  time_t now;
  coap_list_t *node;
#ifndef NDEBUG
  char addr[INET6_ADDRSTRLEN];
#endif

  if ( !context )
    return;

  time(&now);

  node = context->subscriptions;
  while ( node && COAP_SUBSCRIPTION(node)->expires < now ) {
#ifndef NDEBUG
    if ( inet_ntop(AF_INET6, &(COAP_SUBSCRIPTION(node)->subscriber.sin6_addr), addr, INET6_ADDRSTRLEN) ) {

      debug("** removed expired subscription from [%s]:%d\n", addr, ntohs(COAP_SUBSCRIPTION(node)->subscriber.sin6_port));
    }
#endif
#if 0
    notify(context,
	   coap_get_resource_from_key(context, COAP_SUBSCRIPTION(node)->resource),
	   COAP_SUBSCRIPTION(node),
	   0, COAP_RESPONSE_400);
#endif
    context->subscriptions = node->next;
    coap_delete(node);
    node = context->subscriptions;
  }
}
예제 #3
0
void coap_delete_list(coap_list_t *queue)
{
    if (!queue)
        return;

    coap_delete_list(queue->next);
    coap_delete(queue);
}
예제 #4
0
void
coap_delete_list(coap_list_t *queue) {
  coap_list_t *elt, *tmp;

  if (!queue)
    return;

  LL_FOREACH_SAFE(queue, elt, tmp) {
    coap_delete(elt);
  }
예제 #5
0
/**
 * Deletes the resource that is identified by key. Returns 1 if the resource was
 * removed, 0 on error (e.g. if no such resource exists).
 */
int
coap_delete_resource(coap_context_t *context, coap_key_t key) {
  coap_list_t *prev, *node;

  if (!context || key == COAP_INVALID_HASHKEY)
    return 0;

  for (prev = NULL, node = context->resources; node;
       prev = node, node = node->next) {
    if (coap_uri_hash(COAP_RESOURCE(node)->uri) == key) {
      debug("removed key %lu (%s)\n",key,COAP_RESOURCE(node)->uri->path.s);
      if (!prev)
	context->resources = node->next;
      else
	prev->next = node->next;

      coap_delete(node);
      return 1;
    }
  }
  return 0;
}
예제 #6
0
CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t *info, coap_list_t **optlist)
{
    (void)code;
    OIC_LOG(DEBUG, TAG, "IN");
    VERIFY_NON_NULL_RET(info, TAG, "info is NULL", CA_STATUS_INVALID_PARAM);

    OIC_LOG_V(DEBUG, TAG, "parse Head Opt: %d", info->numOptions);

    if (!optlist)
    {
        OIC_LOG(ERROR, TAG, "optlist is null");
        return CA_STATUS_INVALID_PARAM;
    }

    for (uint32_t i = 0; i < info->numOptions; i++)
    {
        if(!(info->options + i))
        {
            OIC_LOG(ERROR, TAG, "options is not available");
            return CA_STATUS_FAILED;
        }

        uint32_t id = (info->options + i)->optionID;
        if (COAP_OPTION_URI_PATH == id || COAP_OPTION_URI_QUERY == id)
        {
            OIC_LOG_V(DEBUG, TAG, "not Header Opt: %d", id);
        }
        else
        {
            if ((info->options + i)->optionData && (info->options + i)->optionLength > 0)
            {
                OIC_LOG_V(DEBUG, TAG, "Head opt ID: %d", id);
                OIC_LOG_V(DEBUG, TAG, "Head opt data: %s", (info->options + i)->optionData);
                OIC_LOG_V(DEBUG, TAG, "Head opt length: %d", (info->options + i)->optionLength);
                int ret = coap_insert(optlist,
                                      CACreateNewOptionNode(id, (info->options + i)->optionLength,
                                              (info->options + i)->optionData),
                                      CAOrderOpts);
                if (ret <= 0)
                {
                    return CA_STATUS_INVALID_PARAM;
                }
            }
        }
    }

    // insert one extra header with the payload format if applicable.
    if (CA_FORMAT_UNDEFINED != info->payloadFormat)
    {
        coap_list_t* node = NULL;
        uint8_t buf[3] = {0};
        switch (info->payloadFormat) {
        case CA_FORMAT_CBOR:
            node = CACreateNewOptionNode(
                       COAP_OPTION_CONTENT_FORMAT,
                       coap_encode_var_bytes(buf, (uint16_t)COAP_MEDIATYPE_APPLICATION_CBOR),
                       (char *)buf);
            break;
        default:
            OIC_LOG_V(ERROR, TAG, "format option:[%d] not supported", info->payloadFormat);
        }
        if (!node)
        {
            OIC_LOG(ERROR, TAG, "format option not created");
            return CA_STATUS_INVALID_PARAM;
        }
        int ret = coap_insert(optlist, node, CAOrderOpts);
        if (ret <= 0)
        {
            coap_delete(node);
            OIC_LOG(ERROR, TAG, "format option not inserted in header");
            return CA_STATUS_INVALID_PARAM;
        }
    }

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}