Beispiel #1
0
int
oggz_comment_add_byname (OGGZ * oggz, long serialno,
                         const char * name, const char * value)
{
    oggz_stream_t * stream;
    OggzComment * new_comment;

    if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;

    stream = oggz_get_stream (oggz, serialno);
    if (stream == NULL) stream = oggz_add_stream (oggz, serialno);

    if (oggz->flags & OGGZ_WRITE) {
        if (OGGZ_CONFIG_WRITE) {

            if (!oggz_comment_validate_byname (name, value))
                return OGGZ_ERR_COMMENT_INVALID;

            new_comment = oggz_comment_new (name, value);

            _oggz_comment_add (stream, new_comment);

            return 0;
        } else {
            return OGGZ_ERR_DISABLED;
        }
    } else {
        return OGGZ_ERR_INVALID;
    }
}
Beispiel #2
0
const OggzComment *
oggz_comment_first_byname (OGGZ * oggz, long serialno, char * name)
{
    oggz_stream_t * stream;
    OggzComment * comment;
    int i;

    if (oggz == NULL) return NULL;

    stream = oggz_get_stream (oggz, serialno);
    if (stream == NULL) return NULL;

    if (name == NULL) return oggz_vector_nth_p (stream->comments, 0);

    if (!oggz_comment_validate_byname (name, ""))
        return NULL;

    for (i = 0; i < oggz_vector_size (stream->comments); i++) {
        comment = (OggzComment *) oggz_vector_nth_p (stream->comments, i);
        if (comment->name && !strcasecmp (name, comment->name))
            return comment;
    }

    return NULL;
}
int
oggz_comment_add (OGGZ * oggz, long serialno, const OggzComment * comment)
{
  oggz_stream_t * stream;
  OggzComment * new_comment;

  if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;

  stream = oggz_get_stream (oggz, serialno);
  if (stream == NULL)
    stream = oggz_add_stream (oggz, serialno);
  if (stream == NULL)
    return OGGZ_ERR_OUT_OF_MEMORY;

  if (oggz->flags & OGGZ_WRITE) {
    if (OGGZ_CONFIG_WRITE) {

      if (!oggz_comment_validate_byname (comment->name))
        return OGGZ_ERR_COMMENT_INVALID;

      if (_oggz_comment_add_byname (stream, comment->name, comment->value) == NULL)
        return OGGZ_ERR_OUT_OF_MEMORY;

      return 0;
    } else {
      return OGGZ_ERR_DISABLED;
    }
  } else {
    return OGGZ_ERR_INVALID;
  }
}
static OggzComment *
oggz_comment_new (const char * name, const char * value)
{
  OggzComment * comment;

  if (!oggz_comment_validate_byname (name)) return NULL;
  /* Ensures that name != NULL and contains only valid characters */

  comment = oggz_malloc (sizeof (OggzComment));
  if (comment == NULL) return NULL;

  comment->name = oggz_strdup (name);
  if (comment->name == NULL) {
    oggz_free (comment);
    return NULL;
  }

  if (value) {
    comment->value = oggz_strdup (value);
    if (comment->value == NULL) {
      oggz_free (comment->name);
      oggz_free (comment);
      return NULL;
    }
  } else {
    comment->value = NULL;
  }

  return comment;
}
Beispiel #5
0
static OggzComment *
oggz_comment_new (const char * name, const char * value)
{
    OggzComment * comment;

    if (!oggz_comment_validate_byname (name, value)) return NULL;

    comment = oggz_malloc (sizeof (OggzComment));
    comment->name = oggz_strdup (name);
    comment->value = oggz_strdup (value);

    return comment;
}