Exemple #1
0
/* Sets an integer attribute. */
SLPError SLPAttrSet_int(
		SLPAttributes attr_h,
		const char *tag,
		long val,
		SLPInsertionPolicy policy
) {
	struct xx_SLPAttributes *slp_attr = (struct xx_SLPAttributes *)attr_h;
	value_t *value;
	
	/***** Sanity check. *****/
	if ( is_valid_tag(tag) == SLP_FALSE ) {
		return SLP_TAG_BAD;
	}

	/***** Create new value. *****/
	value = value_new();
	if (value == NULL) {
		return SLP_MEMORY_ALLOC_FAILED;
	}
	
	/**** Set ****/
	value->data.va_int = val;
	value->escaped_len = count_digits(value->data.va_int);
	assert(value->escaped_len > 0);

	return generic_set_val(slp_attr, tag, value, policy, SLP_INTEGER);
}
Exemple #2
0
/* Sets a string attribute. */
SLPError SLPAttrSet_str(
		SLPAttributes attr_h,
		const char *tag,
		const char *val,
		SLPInsertionPolicy policy
) {
	struct xx_SLPAttributes *slp_attr = (struct xx_SLPAttributes *)attr_h;
	value_t *value;
	
	/***** Sanity check. *****/
	if ( is_valid_tag(tag) == SLP_FALSE ) {
		return SLP_TAG_BAD;
	}
	if ( val == NULL ) {
		return SLP_PARAMETER_BAD;
	}

	/***** Create new value. *****/
	value = value_new();
	assert(value);
	
	value->data.va_str = strdup(val);
	if (value->data.va_str == NULL) {
		value_free(value);
		return SLP_MEMORY_ALLOC_FAILED;
	}

	value->escaped_len = find_escaped_size(value->data.va_str, -1);
	
	return generic_set_val(slp_attr, tag, value, policy, SLP_STRING);
	return SLP_OK;
}
Exemple #3
0
/* Set a boolean attribute.  */
SLPError SLPAttrSet_bool(
		SLPAttributes attr_h,
		const char *tag,
		SLPBoolean val
) {
	struct xx_SLPAttributes *slp_attr = (struct xx_SLPAttributes *)attr_h;
	value_t *value = NULL;
	
	/***** Sanity check. *****/
	if (val != SLP_TRUE && val != SLP_FALSE) {
		return SLP_PARAMETER_BAD;
	}
	if ( is_valid_tag(tag) == SLP_FALSE ) {
		return SLP_TAG_BAD;
	}

	/***** Set the initial (and only) value. *****/
	/**** Create ****/
	value = value_new();

	assert(value);

	/*** Set escaped information. ***/
	if (val == SLP_TRUE) {
		value->escaped_len = BOOL_TRUE_STR_LEN;
	} 
	else {
		value->escaped_len = BOOL_FALSE_STR_LEN;
	}
	value->data.va_bool = val;

	/**** Set the value and return. ****/
	return generic_set_val(slp_attr, tag, value, SLP_REPLACE, SLP_BOOLEAN);
}
Exemple #4
0
/* Set an attribute of unknown type. 
 *
 * Note that the policy in this case is a special case: If the policy is 
 * SLP_REPLACE, we delete the current list and replace it with the passed 
 * value. If it's a multivalue list, we replace the current value with the 
 * ENTIRE passed list. 
 *
 * FIXME Should we "elide" whitespace?
 */
SLPError SLPAttrSet_guess(
		SLPAttributes attr_h,
		const char *tag,
		const char *val,
		SLPInsertionPolicy policy
) {
	SLPError err;
	size_t len;
	const char *cur, *end;
	
	/***** Sanity check. *****/
	if ( is_valid_tag(tag) == SLP_FALSE ) {
		return SLP_TAG_BAD;
	}
	if ( val == NULL ) {
		return SLP_PARAMETER_BAD;
	}

	/***** 
	 * If we have a replace policy and we're inserting a multivalued list, 
	 * the values will clobber each other. Therefore if we have a replace, we 
	 * delete the current list, and use an add policy.
	 *****/
	if (policy == SLP_REPLACE) {
		var_t *var;
		var = attr_val_find_str((struct xx_SLPAttributes *)attr_h, tag);
		if (var) {
			var_list_destroy(var);
		}
	}
	
	/***** Check for multivalue list. *****/
	cur = val;
	do {
		end = strstr(cur, VAR_SEPARATOR);
		if (end == NULL) {
			len = strlen(cur);
		} else {
			/*** It's multivalue. ***/
			len = end - cur;
		}

		err = SLPAttrStore((struct xx_SLPAttributes *)attr_h, tag, cur, len, SLP_ADD);
		if (err != SLP_OK) {
			/* FIXME Ummm. Should we return or ignore? */
			return err;
		}
		cur = end + VAR_SEPARATOR_LEN;
	} while(end);

	/***** Return *****/
	return SLP_OK;
}
Exemple #5
0
/* Sets a keyword attribute. */
SLPError SLPAttrSet_keyw(
		SLPAttributes attr_h,
		const char *tag
) {
	struct xx_SLPAttributes *slp_attr = (struct xx_SLPAttributes *)attr_h;
	
	/***** Sanity check. *****/
	if ( is_valid_tag(tag) == SLP_FALSE ) {
		return SLP_TAG_BAD;
	}

	return generic_set_val(slp_attr, tag, NULL, SLP_REPLACE, SLP_KEYWORD);
}
Exemple #6
0
gboolean
kms_sdp_sdes_ext_create_key_detailed (guint tag, const gchar * key,
    SrtpCryptoSuite crypto, const gchar * lifetime, const guint * mki,
    const guint * length, GValue * val, GError ** error)
{
  const gchar *err_msg;
  GstStructure *str;

  if (!is_valid_tag (tag)) {
    err_msg = "tag can not be greater than 999999999";
    goto error;
  }

  if (key == NULL) {
    err_msg = "key attribute can not be NULL";
    goto error;
  }

  if ((mki != NULL && length == NULL) || (mki == NULL && length != NULL)) {
    err_msg = "MKI and length must be either both NULL or neither of them";
    goto error;
  }

  str = gst_structure_new ("sdp-crypto", KMS_SDES_TAG_FIELD, G_TYPE_UINT, tag,
      KMS_SDES_KEY_FIELD, G_TYPE_STRING, key, KMS_SDES_CRYPTO, G_TYPE_UINT,
      crypto, NULL);

  if (lifetime != NULL) {
    gst_structure_set (str, KMS_SDES_LIFETIME, G_TYPE_STRING, lifetime, NULL);
  }

  if (mki != NULL) {
    gst_structure_set (str, KMS_SDES_MKI, G_TYPE_UINT, *mki,
        KMS_SDES_LENGTH, G_TYPE_UINT, *length, NULL);
  }

  g_value_init (val, GST_TYPE_STRUCTURE);
  gst_value_set_structure (val, str);
  gst_structure_free (str);

  return TRUE;

error:
  g_set_error_literal (error, KMS_SDP_AGENT_ERROR,
      SDP_AGENT_INVALID_PARAMETER, err_msg);

  return FALSE;
}
Exemple #7
0
/* Set an opaque attribute. */
SLPError SLPAttrSet_opaque(
		SLPAttributes attr_h,
		const char *tag,
		const char *val,
		const unsigned int len, 
		SLPInsertionPolicy policy
) {
	struct xx_SLPAttributes *slp_attr = (struct xx_SLPAttributes *)attr_h;
	value_t *value;
	
	/***** Sanity check. *****/
	if ( is_valid_tag(tag) == SLP_FALSE ) {
		return SLP_TAG_BAD;
	}
	if ( val == NULL ) {
		return SLP_PARAMETER_BAD;
	}

	/***** Create a new attribute. *****/
	value = value_new();
	if (value == NULL) {
		return SLP_MEMORY_ALLOC_FAILED;
	}
	
	value->data.va_str = (char *)malloc( len );
	
	if (value->data.va_str == NULL) {
		free(value->data.va_str);
		return SLP_MEMORY_ALLOC_FAILED;
	}
	
	memcpy((void *)value->data.va_str, val, len);
	value->unescaped_len = len;
	value->escaped_len = (len * ESCAPED_LEN) + OPAQUE_PREFIX_LEN;

	return generic_set_val(slp_attr, tag, value, policy, SLP_OPAQUE);
}