Esempio n. 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;
    }
}
static OggzComment *
_oggz_comment_add_byname (oggz_stream_t * stream, const char * name, const char * value)
{
  OggzComment * comment, * new_comment;
  int i;

  /* Check that the same name=value pair is not already present */
  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)) {
      if (comment->value == NULL) {
        if (value == NULL) return comment;
      } else if ((value && !strcmp (value, comment->value)) || 
                 (value == NULL && comment->value == NULL)) {
        return comment;
      }
    }
  }

  /* Allocate new comment and insert it */
  if ((new_comment = oggz_comment_new (name, value)) == NULL)
    return NULL;

  return oggz_vector_insert_p (stream->comments, new_comment);
}
Esempio n. 3
0
int
oggz_comments_decode (OGGZ * oggz, long serialno,
                      unsigned char * comments, long length)
{
    oggz_stream_t * stream;
    char *c= (char *)comments;
    int len, i, nb_fields, n;
    char *end;
    char * name, * value, * nvalue = NULL;
    OggzComment * comment;

    if (length<8)
        return -1;

    end = c+length;
    len=readint(c, 0);

    c+=4;
    if (c+len>end) return -1;

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

    /* Vendor */
    nvalue = oggz_strdup_len (c, len);
    if (!nvalue) return -1;
    _oggz_comment_set_vendor (oggz, serialno, nvalue);
    if (nvalue) oggz_free (nvalue);
#ifdef DEBUG
    fwrite(c, 1, len, stderr);
    fputc ('\n', stderr);
#endif
    c+=len;

    if (c+4>end) return -1;

    nb_fields=readint(c, 0);
    c+=4;
    for (i=0; i<nb_fields; i++) {
        if (c+4>end) return -1;

        len=readint(c, 0);

        c+=4;
        if (c+len>end) return -1;

        name = c;
        value = oggz_index_len (c, '=', len);
        if (value) {
            *value = '\0';
            value++;

            n = c+len - value;
            nvalue = oggz_strdup_len (value, n);
#ifdef DEBUG
            printf ("oggz_comments_decode: %s -> %s (length %d)\n",
                    name, nvalue, n);
#endif
            comment = oggz_comment_new (name, nvalue);
            _oggz_comment_add (stream, comment);
            oggz_free (nvalue);
        } else {
            nvalue = oggz_strdup_len (name, len);
            comment = oggz_comment_new (nvalue, NULL);
            _oggz_comment_add (stream, comment);
            oggz_free (nvalue);
        }

        c+=len;
    }

#ifdef DEBUG
    printf ("oggz_comments_decode: done\n");
#endif

    return 0;
}