Mercurial > hg > xmms-sid
annotate src/xs_support.c @ 893:c835aa129e3b
Add two new utility functions for checking whether a given path is a
directory or not.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 09 Nov 2012 07:47:05 +0200 |
parents | 7bde71a1ea91 |
children | 4697c5bd7025 |
rev | line source |
---|---|
4 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Miscellaneous support functions | |
5 | |
324 | 6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
723 | 7 (C) Copyright 1999-2009 Tecnic Software productions (TNSP) |
4 | 8 |
9 This program is free software; you can redistribute it and/or modify | |
10 it under the terms of the GNU General Public License as published by | |
11 the Free Software Foundation; either version 2 of the License, or | |
12 (at your option) any later version. | |
13 | |
14 This program is distributed in the hope that it will be useful, | |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 GNU General Public License for more details. | |
18 | |
412
7f694e5a1493
Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
19 You should have received a copy of the GNU General Public License along |
7f694e5a1493
Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
20 with this program; if not, write to the Free Software Foundation, Inc., |
7f694e5a1493
Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
772 | 22 |
23 -- | |
24 Except for the MD5 related functionality at the end of this file. | |
25 -- | |
4 | 26 */ |
49
3518ca5c8b0f
Support for compile-time big/little-endian optimizations in audio output
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
27 #include "xs_support.h" |
879
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
28 #include <stdarg.h> |
224
df4cb5115322
Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
29 #include <ctype.h> |
202 | 30 |
879
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
31 |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
32 /* Error messages |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
33 */ |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
34 void xs_error(const char *fmt, ...) |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
35 { |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
36 va_list ap; |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
37 fprintf(stderr, "XMMS-SID: "); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
38 va_start(ap, fmt); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
39 vfprintf(stderr, fmt, ap); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
40 va_end(ap); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
41 } |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
42 |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
43 #ifndef DEBUG_NP |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
44 void XSDEBUG(const char *fmt, ...) |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
45 { |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
46 #ifdef DEBUG |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
47 va_list ap; |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
48 fprintf(stderr, "XSDEBUG: "); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
49 va_start(ap, fmt); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
50 vfprintf(stderr, fmt, ap); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
51 va_end(ap); |
887 | 52 #else |
53 (void) fmt; | |
879
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
54 #endif |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
55 } |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
56 #endif |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
57 |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
58 |
877
5e33075ed9dd
Oops, a #ifdef was reversed, causing the xs_fsize() function not to be compiled.
Matti Hamalainen <ccr@tnsp.org>
parents:
868
diff
changeset
|
59 #ifndef __AUDACIOUS_NEWVFS__ |
866
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
60 off_t xs_fsize(XSFile *f) |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
61 { |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
62 off_t pos; |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
63 if (fseeko(f, 0, SEEK_END) < 0) |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
64 return -1; |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
65 |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
66 pos = ftello(f); |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
67 |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
68 if (fseeko(f, 0, SEEK_SET) < 0) |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
69 return -1; |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
70 |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
71 return pos; |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
72 } |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
73 #endif |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
74 |
226
858c09f59011
Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
75 |
893
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
76 gboolean xs_is_dir_path(const gchar *path) |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
77 { |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
78 XSFile *fp = xs_fopen(path, "rb"); |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
79 if (fp != NULL) |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
80 { |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
81 xs_fclose(fp); |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
82 return FALSE; |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
83 } |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
84 else |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
85 return TRUE; |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
86 } |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
87 |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
88 |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
89 gchar *xs_get_dir_path(const gchar *path) |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
90 { |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
91 if (xs_is_dir_path(path)) |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
92 return g_dirname(path); |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
93 else |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
94 return g_strdup(path); |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
95 } |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
96 |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
97 |
751 | 98 guint16 xs_fread_be16(XSFile *f) |
516
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
99 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
100 return (((guint16) xs_fgetc(f)) << 8) | ((guint16) xs_fgetc(f)); |
516
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
101 } |
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
102 |
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
103 |
751 | 104 guint32 xs_fread_be32(XSFile *f) |
516
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
105 { |
763
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
106 return |
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
107 (((guint32) xs_fgetc(f)) << 24) | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
108 (((guint32) xs_fgetc(f)) << 16) | |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
109 (((guint32) xs_fgetc(f)) << 8) | |
763
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
110 ((guint32) xs_fgetc(f)); |
516
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
111 } |
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
112 |
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
113 |
527
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
114 /* Load a file to a buffer, return 0 on success, negative value on error |
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
115 */ |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
116 gboolean xs_fload_buffer(const gchar *filename, |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
117 guint8 **pbuf, size_t *bufSize, const size_t maxSize, gboolean failMaxSize) |
527
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
118 { |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
119 XSFile *fp = NULL; |
888
1779967c472a
Silence possibly uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
887
diff
changeset
|
120 size_t readSize = 0, fileSize = 0; |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
121 gboolean res = FALSE; |
763
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
122 |
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
123 if (filename == NULL) |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
124 return FALSE; |
763
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
125 |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
126 if ((fp = xs_fopen(filename, "rb")) == NULL) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
127 { |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
128 xs_error("Could not open '%s' for reading.\n", filename); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
129 goto error; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
130 } |
527
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
131 |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
132 fileSize = xs_fsize(fp); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
133 if (failMaxSize && fileSize > maxSize) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
134 { |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
135 xs_error("File '%s' size %d exceeds maxSize %d.\n", |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
136 fileSize, maxSize); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
137 goto error; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
138 } |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
139 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
140 readSize = fileSize < maxSize ? fileSize : maxSize; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
141 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
142 if ((*pbuf = (guint8 *) g_malloc(readSize * sizeof(guint8))) == NULL) |
763
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
143 { |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
144 xs_error("Could not allocate %d bytes for filebuffer '%s'.\n", |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
145 readSize, filename); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
146 goto error; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
147 } |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
148 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
149 *bufSize = xs_fread(*pbuf, sizeof(guint8), readSize, fp); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
150 res = (readSize == *bufSize); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
151 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
152 error: |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
153 if (fp != NULL) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
154 xs_fclose(fp); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
155 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
156 if (!res) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
157 { |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
158 xs_error("File '%s', expected %d bytes, read %d bytes.\n", |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
159 readSize, *bufSize); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
160 } |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
161 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
162 return res; |
527
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
163 } |
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
164 |
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
165 |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
166 gboolean xs_fload_buffer_path(const gchar *ppath, const gchar *pfilename, |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
167 guint8 **pbuf, size_t *bufSize, const size_t maxSize, gboolean failMaxSize) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
168 { |
889 | 169 gchar *filename, *pseparator; |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
170 gboolean res; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
171 |
889 | 172 if (pfilename == NULL) |
173 return FALSE; | |
174 | |
175 pseparator = ppath != NULL ? ((ppath[strlen(ppath)] != '/') ? "/" : "") : ""; | |
176 filename = g_strdup_printf("%s%s%s", ppath, pseparator, pfilename); | |
177 | |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
178 if (filename == NULL) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
179 return FALSE; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
180 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
181 res = xs_fload_buffer(filename, pbuf, bufSize, maxSize, failMaxSize); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
182 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
183 g_free(filename); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
184 return res; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
185 } |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
186 |
889 | 187 |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
188 /* Copy a given string over in *result. |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
189 */ |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
190 gint xs_pstrcpy(gchar **result, const gchar *str) |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
191 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
192 /* Check the string pointers */ |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
193 if (!result || !str) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
194 return -1; |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
195 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
196 /* Allocate memory for destination */ |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
197 g_free(*result); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
198 |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
199 *result = (gchar *) g_malloc(strlen(str) + 1); |
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
200 if (!*result) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
201 return -2; |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
202 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
203 /* Copy to the destination */ |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
204 strcpy(*result, str); |
4 | 205 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
206 return 0; |
4 | 207 } |
208 | |
209 | |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
210 /* Concatenates a given string into string pointed by *result. |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
211 */ |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
212 gint xs_pstrcat(gchar **result, const gchar *str) |
4 | 213 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
214 /* Check the string pointers */ |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
215 if (!result || !str) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
216 return -1; |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
217 |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
218 if (*result != NULL) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
219 { |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
220 *result = (gchar *) g_realloc(*result, strlen(*result) + strlen(str) + 1); |
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
221 if (*result == NULL) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
222 return -1; |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
223 strcat(*result, str); |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
224 } |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
225 else |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
226 { |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
227 *result = (gchar *) g_malloc(strlen(str) + 1); |
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
228 if (*result == NULL) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
229 return -1; |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
230 strcpy(*result, str); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
231 } |
4 | 232 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
233 return 0; |
4 | 234 } |
235 | |
236 | |
239
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
237 /* Concatenate a given string up to given dest size or \n. |
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
238 * If size max is reached, change the end to "..." |
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
239 */ |
868 | 240 void xs_pnstrcat(gchar *dest, const size_t size, const gchar *str) |
239
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
241 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
242 size_t i, n; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
243 const gchar *s; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
244 gchar *d; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
245 |
868 | 246 for (d = dest, i = 0; *d && i < size; i++, d++); |
239
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
247 |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
248 s = str; |
868 | 249 while (*s && *s != '\n' && i < size) |
250 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
251 *d = *s; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
252 d++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
253 s++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
254 i++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
255 } |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
256 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
257 *d = 0; |
239
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
258 |
868 | 259 if (i >= size) |
260 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
261 i--; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
262 d--; |
868 | 263 for (n = 3; i > 0 && n > 0; d--, i--, n--) |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
264 *d = '.'; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
265 } |
239
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
266 } |
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
267 |
7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
268 |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
269 /* Locate character in string |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
270 */ |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
271 void xs_findnext(const gchar *str, size_t *pos) |
4 | 272 { |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
273 while (str[*pos] && isspace(str[*pos])) |
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
274 (*pos)++; |
4 | 275 } |
276 | |
277 | |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
278 void xs_findeol(const gchar *str, size_t *pos) |
4 | 279 { |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
280 while (str[*pos] && (str[*pos] != '\n') && (str[*pos] != '\r')) |
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
281 (*pos)++; |
4 | 282 } |
283 | |
284 | |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
285 void xs_findnum(const gchar *str, size_t *pos) |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
286 { |
663
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
287 while (str[*pos] && isdigit(str[*pos])) |
180d7a0250d8
More cosmetic variable name changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
288 (*pos)++; |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
289 } |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
290 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
291 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
292 /* |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
293 * MD5 implementation, modified for XMMS-SID from |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
294 * Colin Plumb's implementation by Matti 'ccr' Hämäläinen. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
295 * |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
296 * This code implements the MD5 message-digest algorithm. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
297 * The algorithm is due to Ron Rivest. This code was |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
298 * written by Colin Plumb in 1993, no copyright is claimed. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
299 * This code is in the public domain; do with it what you wish. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
300 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
301 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
302 #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
772 | 303 # define xs_md5_bytereverse(buf, len) /* Nothing */ |
304 #elif G_BYTE_ORDER == G_BIG_ENDIAN | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
305 static void xs_md5_bytereverse(guint8 *buf, guint l) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
306 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
307 guint32 t; |
868 | 308 do |
309 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
310 t = (guint32) ((guint) buf[3] << 8 | buf[2]) << 16 | ((guint) buf[1] << 8 | buf[0]); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
311 *(guint32 *) buf = t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
312 buf += sizeof(guint32); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
313 } while (--l); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
314 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
315 #else |
772 | 316 # error Unsupported endianess! |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
317 #endif |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
318 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
319 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
320 /* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
321 * initialization constants. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
322 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
323 void xs_md5_init(xs_md5state_t *ctx) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
324 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
325 ctx->buf[0] = 0x67452301; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
326 ctx->buf[1] = 0xefcdab89; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
327 ctx->buf[2] = 0x98badcfe; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
328 ctx->buf[3] = 0x10325476; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
329 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
330 ctx->bits[0] = 0; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
331 ctx->bits[1] = 0; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
332 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
333 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
334 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
335 /* The core of the MD5 algorithm, this alters an existing MD5 hash to |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
336 * reflect the addition of 16 longwords of new data. xs_md5_update blocks |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
337 * the data and converts bytes into longwords for this routine. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
338 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
339 #define F1(x, y, z) (z ^ (x & (y ^ z))) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
340 #define F2(x, y, z) F1(z, x, y) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
341 #define F3(x, y, z) (x ^ y ^ z) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
342 #define F4(x, y, z) (y ^ (x | ~z)) |
868 | 343 #define MD5STEP(f, w, x, y, z, data, s) ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
344 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
345 static void xs_md5_transform(guint32 buf[4], guint32 const in[16]) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
346 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
347 register guint32 a, b, c, d; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
348 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
349 a = buf[0]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
350 b = buf[1]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
351 c = buf[2]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
352 d = buf[3]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
353 |
772 | 354 MD5STEP(F1, a, b, c, d, in[ 0] + 0xd76aa478, 7); |
355 MD5STEP(F1, d, a, b, c, in[ 1] + 0xe8c7b756, 12); | |
356 MD5STEP(F1, c, d, a, b, in[ 2] + 0x242070db, 17); | |
357 MD5STEP(F1, b, c, d, a, in[ 3] + 0xc1bdceee, 22); | |
358 MD5STEP(F1, a, b, c, d, in[ 4] + 0xf57c0faf, 7); | |
359 MD5STEP(F1, d, a, b, c, in[ 5] + 0x4787c62a, 12); | |
360 MD5STEP(F1, c, d, a, b, in[ 6] + 0xa8304613, 17); | |
361 MD5STEP(F1, b, c, d, a, in[ 7] + 0xfd469501, 22); | |
362 MD5STEP(F1, a, b, c, d, in[ 8] + 0x698098d8, 7); | |
363 MD5STEP(F1, d, a, b, c, in[ 9] + 0x8b44f7af, 12); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
364 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
365 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
366 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
367 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
368 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
369 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
370 |
772 | 371 MD5STEP(F2, a, b, c, d, in[ 1] + 0xf61e2562, 5); |
372 MD5STEP(F2, d, a, b, c, in[ 6] + 0xc040b340, 9); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
373 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); |
772 | 374 MD5STEP(F2, b, c, d, a, in[ 0] + 0xe9b6c7aa, 20); |
375 MD5STEP(F2, a, b, c, d, in[ 5] + 0xd62f105d, 5); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
376 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
377 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); |
772 | 378 MD5STEP(F2, b, c, d, a, in[ 4] + 0xe7d3fbc8, 20); |
379 MD5STEP(F2, a, b, c, d, in[ 9] + 0x21e1cde6, 5); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
380 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); |
772 | 381 MD5STEP(F2, c, d, a, b, in[ 3] + 0xf4d50d87, 14); |
382 MD5STEP(F2, b, c, d, a, in[ 8] + 0x455a14ed, 20); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
383 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); |
772 | 384 MD5STEP(F2, d, a, b, c, in[ 2] + 0xfcefa3f8, 9); |
385 MD5STEP(F2, c, d, a, b, in[ 7] + 0x676f02d9, 14); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
386 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
387 |
772 | 388 MD5STEP(F3, a, b, c, d, in[ 5] + 0xfffa3942, 4); |
389 MD5STEP(F3, d, a, b, c, in[ 8] + 0x8771f681, 11); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
390 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
391 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); |
772 | 392 MD5STEP(F3, a, b, c, d, in[ 1] + 0xa4beea44, 4); |
393 MD5STEP(F3, d, a, b, c, in[ 4] + 0x4bdecfa9, 11); | |
394 MD5STEP(F3, c, d, a, b, in[ 7] + 0xf6bb4b60, 16); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
395 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
396 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); |
772 | 397 MD5STEP(F3, d, a, b, c, in[ 0] + 0xeaa127fa, 11); |
398 MD5STEP(F3, c, d, a, b, in[ 3] + 0xd4ef3085, 16); | |
399 MD5STEP(F3, b, c, d, a, in[ 6] + 0x04881d05, 23); | |
400 MD5STEP(F3, a, b, c, d, in[ 9] + 0xd9d4d039, 4); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
401 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
402 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); |
772 | 403 MD5STEP(F3, b, c, d, a, in[ 2] + 0xc4ac5665, 23); |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
404 |
772 | 405 MD5STEP(F4, a, b, c, d, in[ 0] + 0xf4292244, 6); |
406 MD5STEP(F4, d, a, b, c, in[ 7] + 0x432aff97, 10); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
407 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); |
772 | 408 MD5STEP(F4, b, c, d, a, in[ 5] + 0xfc93a039, 21); |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
409 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); |
772 | 410 MD5STEP(F4, d, a, b, c, in[ 3] + 0x8f0ccc92, 10); |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
411 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); |
772 | 412 MD5STEP(F4, b, c, d, a, in[ 1] + 0x85845dd1, 21); |
413 MD5STEP(F4, a, b, c, d, in[ 8] + 0x6fa87e4f, 6); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
414 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); |
772 | 415 MD5STEP(F4, c, d, a, b, in[ 6] + 0xa3014314, 15); |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
416 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); |
772 | 417 MD5STEP(F4, a, b, c, d, in[ 4] + 0xf7537e82, 6); |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
418 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); |
772 | 419 MD5STEP(F4, c, d, a, b, in[ 2] + 0x2ad7d2bb, 15); |
420 MD5STEP(F4, b, c, d, a, in[ 9] + 0xeb86d391, 21); | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
421 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
422 buf[0] += a; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
423 buf[1] += b; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
424 buf[2] += c; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
425 buf[3] += d; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
426 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
427 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
428 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
429 /* Update context to reflect the concatenation of another buffer full |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
430 * of bytes. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
431 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
432 void xs_md5_append(xs_md5state_t *ctx, const guint8 *buf, guint len) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
433 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
434 guint32 t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
435 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
436 /* Update bitcount */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
437 t = ctx->bits[0]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
438 if ((ctx->bits[0] = t + ((guint32) len << 3)) < t) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
439 ctx->bits[1]++; /* Carry from low to high */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
440 ctx->bits[1] += len >> 29; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
441 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
442 t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
443 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
444 /* Handle any leading odd-sized chunks */ |
868 | 445 if (t) |
446 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
447 guint8 *p = (guint8 *) ctx->in + t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
448 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
449 t = 64 - t; |
868 | 450 if (len < t) |
451 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
452 memcpy(p, buf, len); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
453 return; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
454 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
455 memcpy(p, buf, t); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
456 xs_md5_bytereverse(ctx->in, 16); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
457 xs_md5_transform(ctx->buf, (guint32 *) ctx->in); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
458 buf += t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
459 len -= t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
460 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
461 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
462 /* Process data in 64-byte chunks */ |
868 | 463 while (len >= 64) |
464 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
465 memcpy(ctx->in, buf, 64); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
466 xs_md5_bytereverse(ctx->in, 16); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
467 xs_md5_transform(ctx->buf, (guint32 *) ctx->in); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
468 buf += 64; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
469 len -= 64; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
470 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
471 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
472 /* Handle any remaining bytes of data. */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
473 memcpy(ctx->in, buf, len); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
474 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
475 |
868 | 476 |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
477 /* Final wrapup - pad to 64-byte boundary with the bit pattern |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
478 * 1 0* (64-bit count of bits processed, MSB-first) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
479 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
480 void xs_md5_finish(xs_md5state_t *ctx, xs_md5hash_t digest) |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
481 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
482 guint count; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
483 guint8 *p; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
484 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
485 /* Compute number of bytes mod 64 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
486 count = (ctx->bits[0] >> 3) & 0x3F; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
487 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
488 /* Set the first char of padding to 0x80. This is safe since there is |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
489 always at least one byte free */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
490 p = ctx->in + count; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
491 *p++ = 0x80; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
492 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
493 /* Bytes of padding needed to make 64 bytes */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
494 count = 64 - 1 - count; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
495 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
496 /* Pad out to 56 mod 64 */ |
868 | 497 if (count < 8) |
498 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
499 /* Two lots of padding: Pad the first block to 64 bytes */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
500 memset(p, 0, count); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
501 xs_md5_bytereverse(ctx->in, 16); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
502 xs_md5_transform(ctx->buf, (guint32 *) ctx->in); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
503 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
504 /* Now fill the next block with 56 bytes */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
505 memset(ctx->in, 0, 56); |
868 | 506 } |
507 else | |
508 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
509 /* Pad block to 56 bytes */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
510 memset(p, 0, count - 8); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
511 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
512 xs_md5_bytereverse(ctx->in, 14); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
513 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
514 /* Append length in bits and transform */ |
792
bee1f36efc16
Fix potential aliasing issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
772
diff
changeset
|
515 memcpy(((guint32 *) ctx->in) + 14, &ctx->bits[0], sizeof(guint32)); |
bee1f36efc16
Fix potential aliasing issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
772
diff
changeset
|
516 memcpy(((guint32 *) ctx->in) + 15, &ctx->bits[1], sizeof(guint32)); |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
517 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
518 xs_md5_transform(ctx->buf, (guint32 *) ctx->in); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
519 xs_md5_bytereverse((guint8 *) ctx->buf, 4); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
520 memcpy(digest, ctx->buf, 16); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
521 memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
522 } |