annotate md5proto.c @ 6350:aea92c85d611 libavformat

Fix spelling in comment(s)
author siretart
date Sat, 07 Aug 2010 14:11:43 +0000
parents 287072e5227b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6275
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
1 /*
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
2 * Copyright (c) 2010 Mans Rullgard
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
3 *
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
4 * This file is part of FFmpeg.
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
5 *
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
10 *
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
14 * Lesser General Public License for more details.
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
15 *
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
19 */
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
20
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
21 #include <stdio.h>
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
22 #include "libavutil/avstring.h"
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
23 #include "libavutil/md5.h"
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
24 #include "libavutil/mem.h"
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
25 #include "libavutil/error.h"
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
26 #include "avformat.h"
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
27 #include "avio.h"
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
28
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
29 #define PRIV_SIZE 128
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
30
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
31 static int md5_open(URLContext *h, const char *filename, int flags)
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
32 {
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
33 if (PRIV_SIZE < av_md5_size) {
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
34 av_log(NULL, AV_LOG_ERROR, "Insuffient size for MD5 context\n");
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
35 return -1;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
36 }
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
37
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
38 if (flags != URL_WRONLY)
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
39 return AVERROR(EINVAL);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
40
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
41 av_md5_init(h->priv_data);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
42
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
43 return 0;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
44 }
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
45
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
46 static int md5_write(URLContext *h, const unsigned char *buf, int size)
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
47 {
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
48 av_md5_update(h->priv_data, buf, size);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
49 return size;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
50 }
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
51
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
52 static int md5_close(URLContext *h)
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
53 {
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
54 const char *filename = h->filename;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
55 uint8_t md5[16], buf[64];
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
56 URLContext *out;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
57 int i, err = 0;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
58
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
59 av_md5_final(h->priv_data, md5);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
60 for (i = 0; i < sizeof(md5); i++)
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
61 snprintf(buf + i*2, 3, "%02x", md5[i]);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
62 buf[i*2] = '\n';
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
63
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
64 av_strstart(filename, "md5:", &filename);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
65
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
66 if (*filename) {
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
67 err = url_open(&out, filename, URL_WRONLY);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
68 if (err)
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
69 return err;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
70 err = url_write(out, buf, i*2+1);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
71 url_close(out);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
72 } else {
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
73 if (fwrite(buf, 1, i*2+1, stdout) < i*2+1)
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
74 err = AVERROR(errno);
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
75 }
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
76
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
77 return err;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
78 }
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
79
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
80 static int md5_get_handle(URLContext *h)
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
81 {
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
82 return (intptr_t)h->priv_data;
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
83 }
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
84
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
85 URLProtocol md5_protocol = {
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
86 .name = "md5",
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
87 .url_open = md5_open,
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
88 .url_write = md5_write,
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
89 .url_close = md5_close,
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
90 .url_get_file_handle = md5_get_handle,
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
91 .priv_data_size = PRIV_SIZE,
287072e5227b Add MD5 protocol
mru
parents:
diff changeset
92 };