Mercurial > hg > xmms-sid
annotate src/xs_support.c @ 989:5b68f771d262
Update automake file.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 Oct 2013 13:47:37 +0300 |
parents | 0233c5fd7d5e |
children | 0cd6bcc9ef80 |
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" |
894
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
28 #ifndef __AUDACIOUS_NEWVFS__ |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
29 #include <sys/types.h> |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
30 #include <sys/stat.h> |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
31 #endif |
879
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
32 |
953
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
33 |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
34 gboolean xs_fread_str(XSFile *f, void *buf, const size_t len) |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
35 { |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
36 return xs_fread(buf, len, 1, f) == 1; |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
37 } |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
38 |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
39 |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
40 gboolean xs_fread_byte(XSFile *f, guint8 *val) |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
41 { |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
42 gint tmp = xs_fgetc(f); |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
43 *val = tmp; |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
44 return tmp != EOF; |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
45 } |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
46 |
b2caef664524
Add new helper functions xs_fread_str() and xs_fread_byte().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
47 |
879
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
48 /* Error messages |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
49 */ |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
50 void xs_error(const char *fmt, ...) |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
51 { |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
52 va_list ap; |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
53 fprintf(stderr, "XMMS-SID: "); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
54 va_start(ap, fmt); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
55 vfprintf(stderr, fmt, ap); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
56 va_end(ap); |
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 |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
59 #ifndef DEBUG_NP |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
60 void XSDEBUG(const char *fmt, ...) |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
61 { |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
62 #ifdef DEBUG |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
63 va_list ap; |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
64 fprintf(stderr, "XSDEBUG: "); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
65 va_start(ap, fmt); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
66 vfprintf(stderr, fmt, ap); |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
67 va_end(ap); |
887 | 68 #else |
69 (void) fmt; | |
879
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
70 #endif |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
71 } |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
72 #endif |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
73 |
2a50d36215c3
Move error printing function to xs_support.
Matti Hamalainen <ccr@tnsp.org>
parents:
877
diff
changeset
|
74 |
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
|
75 #ifndef __AUDACIOUS_NEWVFS__ |
866
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
76 off_t xs_fsize(XSFile *f) |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
77 { |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
78 off_t pos; |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
79 if (fseeko(f, 0, SEEK_END) < 0) |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
80 return -1; |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
81 |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
82 pos = ftello(f); |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
83 |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
84 if (fseeko(f, 0, SEEK_SET) < 0) |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
85 return -1; |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
86 |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
87 return pos; |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
88 } |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
89 #endif |
6b47d9813067
Add xs_fsize() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
792
diff
changeset
|
90 |
226
858c09f59011
Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents:
224
diff
changeset
|
91 |
893
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
92 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
|
93 { |
894
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
94 #ifndef __AUDACIOUS_NEWVFS__ |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
95 struct stat sb; |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
96 if (stat(path, &sb) < 0) |
893
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
97 return FALSE; |
894
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
98 |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
99 return (S_ISDIR(sb.st_mode)); |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
100 #else |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
101 // XXX |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
102 #endif |
893
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
103 } |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
104 |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
105 |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
106 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
|
107 { |
894
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
108 #ifndef __AUDACIOUS_NEWVFS__ |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
109 if (!xs_is_dir_path(path)) |
893
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
110 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
|
111 else |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
112 return g_strdup(path); |
894
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
113 #else |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
114 // XXX |
4697c5bd7025
Improve the path helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
893
diff
changeset
|
115 #endif |
893
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
116 } |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
117 |
c835aa129e3b
Add two new utility functions for checking whether a given path is a
Matti Hamalainen <ccr@tnsp.org>
parents:
889
diff
changeset
|
118 |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
119 gboolean xs_fread_be16(XSFile *f, guint16 *val) |
516
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
120 { |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
121 guint16 result; |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
122 if (xs_fread(&result, sizeof(result), 1, f) != 1) |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
123 return FALSE; |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
124 *val = GUINT16_FROM_BE(result); |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
125 return TRUE; |
516
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
126 } |
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
127 |
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
128 |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
129 gboolean xs_fread_be32(XSFile *f, guint32 *val) |
516
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
130 { |
955
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
131 guint32 result; |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
132 if (xs_fread(&result, sizeof(result), 1, f) != 1) |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
133 return FALSE; |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
134 *val = GUINT32_FROM_BE(result); |
3c2efa18c422
Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str()
Matti Hamalainen <ccr@tnsp.org>
parents:
953
diff
changeset
|
135 return TRUE; |
516
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
136 } |
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
137 |
c192468eb8ce
Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
138 |
527
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
139 /* 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
|
140 */ |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
141 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
|
142 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
|
143 { |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
144 XSFile *fp = NULL; |
888
1779967c472a
Silence possibly uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
887
diff
changeset
|
145 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
|
146 gboolean res = FALSE; |
763
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
147 |
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
148 if (filename == NULL) |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
149 return FALSE; |
763
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
150 |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
151 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
|
152 { |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
153 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
|
154 goto error; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
155 } |
527
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
156 |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
157 fileSize = xs_fsize(fp); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
158 if (failMaxSize && fileSize > maxSize) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
159 { |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
160 xs_error("File '%s' size %d exceeds maxSize %d.\n", |
911
b928b8a9c5bf
Oops, fix some error print arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
895
diff
changeset
|
161 filename, fileSize, maxSize); |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
162 goto error; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
163 } |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
164 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
165 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
|
166 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
167 if ((*pbuf = (guint8 *) g_malloc(readSize * sizeof(guint8))) == NULL) |
763
61a527ac3baa
Cleanups, remove useless function.
Matti Hamalainen <ccr@tnsp.org>
parents:
751
diff
changeset
|
168 { |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
169 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
|
170 readSize, filename); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
171 goto error; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
172 } |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
173 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
174 *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
|
175 res = (readSize == *bufSize); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
176 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
177 error: |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
178 if (fp != NULL) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
179 xs_fclose(fp); |
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 if (!res) |
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 xs_error("File '%s', expected %d bytes, read %d bytes.\n", |
911
b928b8a9c5bf
Oops, fix some error print arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
895
diff
changeset
|
184 filename, readSize, *bufSize); |
867
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 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
187 return res; |
527
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
188 } |
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
189 |
fe8b41abd923
Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
190 |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
191 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
|
192 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
|
193 { |
889 | 194 gchar *filename, *pseparator; |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
195 gboolean res; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
196 |
889 | 197 if (pfilename == NULL) |
198 return FALSE; | |
199 | |
200 pseparator = ppath != NULL ? ((ppath[strlen(ppath)] != '/') ? "/" : "") : ""; | |
201 filename = g_strdup_printf("%s%s%s", ppath, pseparator, pfilename); | |
202 | |
867
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
203 if (filename == NULL) |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
204 return FALSE; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
205 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
206 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
|
207 |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
208 g_free(filename); |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
209 return res; |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
210 } |
051ef70d0123
Improve xs_fload_buffer() and add xs_fload_buffer_path().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
211 |
889 | 212 |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
213 /* |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
214 * 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
|
215 * 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
|
216 * |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
217 * 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
|
218 * 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
|
219 * 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
|
220 * 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
|
221 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
222 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
223 #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
772 | 224 # define xs_md5_bytereverse(buf, len) /* Nothing */ |
225 #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
|
226 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
|
227 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
228 guint32 t; |
868 | 229 do |
230 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
231 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
|
232 *(guint32 *) buf = t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
233 buf += sizeof(guint32); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
234 } while (--l); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
235 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
236 #else |
772 | 237 # error Unsupported endianess! |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
238 #endif |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
239 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
240 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
241 /* 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
|
242 * initialization constants. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
243 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
244 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
|
245 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
246 ctx->buf[0] = 0x67452301; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
247 ctx->buf[1] = 0xefcdab89; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
248 ctx->buf[2] = 0x98badcfe; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
249 ctx->buf[3] = 0x10325476; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
250 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
251 ctx->bits[0] = 0; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
252 ctx->bits[1] = 0; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
253 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
254 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
255 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
256 /* 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
|
257 * 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
|
258 * 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
|
259 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
260 #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
|
261 #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
|
262 #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
|
263 #define F4(x, y, z) (y ^ (x | ~z)) |
868 | 264 #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
|
265 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
266 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
|
267 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
268 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
|
269 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
270 a = buf[0]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
271 b = buf[1]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
272 c = buf[2]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
273 d = buf[3]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
274 |
772 | 275 MD5STEP(F1, a, b, c, d, in[ 0] + 0xd76aa478, 7); |
276 MD5STEP(F1, d, a, b, c, in[ 1] + 0xe8c7b756, 12); | |
277 MD5STEP(F1, c, d, a, b, in[ 2] + 0x242070db, 17); | |
278 MD5STEP(F1, b, c, d, a, in[ 3] + 0xc1bdceee, 22); | |
279 MD5STEP(F1, a, b, c, d, in[ 4] + 0xf57c0faf, 7); | |
280 MD5STEP(F1, d, a, b, c, in[ 5] + 0x4787c62a, 12); | |
281 MD5STEP(F1, c, d, a, b, in[ 6] + 0xa8304613, 17); | |
282 MD5STEP(F1, b, c, d, a, in[ 7] + 0xfd469501, 22); | |
283 MD5STEP(F1, a, b, c, d, in[ 8] + 0x698098d8, 7); | |
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 |
772 | 292 MD5STEP(F2, a, b, c, d, in[ 1] + 0xf61e2562, 5); |
293 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
|
294 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); |
772 | 295 MD5STEP(F2, b, c, d, a, in[ 0] + 0xe9b6c7aa, 20); |
296 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
|
297 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
|
298 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); |
772 | 299 MD5STEP(F2, b, c, d, a, in[ 4] + 0xe7d3fbc8, 20); |
300 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
|
301 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); |
772 | 302 MD5STEP(F2, c, d, a, b, in[ 3] + 0xf4d50d87, 14); |
303 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
|
304 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); |
772 | 305 MD5STEP(F2, d, a, b, c, in[ 2] + 0xfcefa3f8, 9); |
306 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
|
307 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
|
308 |
772 | 309 MD5STEP(F3, a, b, c, d, in[ 5] + 0xfffa3942, 4); |
310 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
|
311 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
|
312 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); |
772 | 313 MD5STEP(F3, a, b, c, d, in[ 1] + 0xa4beea44, 4); |
314 MD5STEP(F3, d, a, b, c, in[ 4] + 0x4bdecfa9, 11); | |
315 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
|
316 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
|
317 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); |
772 | 318 MD5STEP(F3, d, a, b, c, in[ 0] + 0xeaa127fa, 11); |
319 MD5STEP(F3, c, d, a, b, in[ 3] + 0xd4ef3085, 16); | |
320 MD5STEP(F3, b, c, d, a, in[ 6] + 0x04881d05, 23); | |
321 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
|
322 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
|
323 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); |
772 | 324 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
|
325 |
772 | 326 MD5STEP(F4, a, b, c, d, in[ 0] + 0xf4292244, 6); |
327 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
|
328 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); |
772 | 329 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
|
330 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); |
772 | 331 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
|
332 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); |
772 | 333 MD5STEP(F4, b, c, d, a, in[ 1] + 0x85845dd1, 21); |
334 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
|
335 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); |
772 | 336 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
|
337 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); |
772 | 338 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
|
339 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); |
772 | 340 MD5STEP(F4, c, d, a, b, in[ 2] + 0x2ad7d2bb, 15); |
341 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
|
342 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
343 buf[0] += a; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
344 buf[1] += b; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
345 buf[2] += c; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
346 buf[3] += d; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
347 } |
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 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
350 /* 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
|
351 * of bytes. |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
352 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
353 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
|
354 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
355 guint32 t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
356 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
357 /* Update bitcount */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
358 t = ctx->bits[0]; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
359 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
|
360 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
|
361 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
|
362 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
363 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
|
364 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
365 /* Handle any leading odd-sized chunks */ |
868 | 366 if (t) |
367 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
368 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
|
369 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
370 t = 64 - t; |
868 | 371 if (len < t) |
372 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
373 memcpy(p, buf, len); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
374 return; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
375 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
376 memcpy(p, buf, t); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
377 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
|
378 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
|
379 buf += t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
380 len -= t; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
381 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
382 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
383 /* Process data in 64-byte chunks */ |
868 | 384 while (len >= 64) |
385 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
386 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
|
387 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
|
388 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
|
389 buf += 64; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
390 len -= 64; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
391 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
392 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
393 /* 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
|
394 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
|
395 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
396 |
868 | 397 |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
398 /* 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
|
399 * 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
|
400 */ |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
401 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
|
402 { |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
403 guint count; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
404 guint8 *p; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
405 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
406 /* 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
|
407 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
|
408 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
409 /* 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
|
410 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
|
411 p = ctx->in + count; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
412 *p++ = 0x80; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
413 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
414 /* 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
|
415 count = 64 - 1 - count; |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
416 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
417 /* Pad out to 56 mod 64 */ |
868 | 418 if (count < 8) |
419 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
420 /* 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
|
421 memset(p, 0, count); |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
422 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
|
423 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
|
424 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
425 /* 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
|
426 memset(ctx->in, 0, 56); |
868 | 427 } |
428 else | |
429 { | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
430 /* 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
|
431 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
|
432 } |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
433 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
|
434 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
435 /* Append length in bits and transform */ |
792
bee1f36efc16
Fix potential aliasing issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
772
diff
changeset
|
436 memcpy(((guint32 *) ctx->in) + 14, &ctx->bits[0], sizeof(guint32)); |
bee1f36efc16
Fix potential aliasing issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
772
diff
changeset
|
437 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
|
438 |
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
439 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
|
440 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
|
441 memcpy(digest, ctx->buf, 16); |
937
b31d420b7fee
Actually clear the whole xs_md5state_t structure, instead of incorrectly
Matti Hamalainen <ccr@tnsp.org>
parents:
911
diff
changeset
|
442 memset(ctx, 0, sizeof(*ctx)); |
895 | 443 } |
444 | |
445 | |
446 /* Copy a given string over in *result. | |
447 */ | |
448 gint xs_pstrcpy(gchar **result, const gchar *str) | |
449 { | |
450 /* Check the string pointers */ | |
451 if (!result || !str) | |
452 return -1; | |
453 | |
454 /* Allocate memory for destination */ | |
455 g_free(*result); | |
456 | |
457 *result = (gchar *) g_malloc(strlen(str) + 1); | |
458 if (!*result) | |
459 return -2; | |
460 | |
461 /* Copy to the destination */ | |
462 strcpy(*result, str); | |
463 | |
464 return 0; | |
465 } | |
466 | |
467 | |
468 /* Concatenates a given string into string pointed by *result. | |
469 */ | |
470 gint xs_pstrcat(gchar **result, const gchar *str) | |
471 { | |
472 /* Check the string pointers */ | |
473 if (!result || !str) | |
474 return -1; | |
475 | |
476 if (*result != NULL) | |
477 { | |
478 *result = (gchar *) g_realloc(*result, strlen(*result) + strlen(str) + 1); | |
479 if (*result == NULL) | |
480 return -1; | |
481 strcat(*result, str); | |
482 } | |
483 else | |
484 { | |
485 *result = (gchar *) g_malloc(strlen(str) + 1); | |
486 if (*result == NULL) | |
487 return -1; | |
488 strcpy(*result, str); | |
489 } | |
490 | |
491 return 0; | |
771
469b341734b2
Move MD5 implementation into xs_support, and some related Audacious
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
492 } |
895 | 493 |
494 | |
495 /* Concatenate a given string up to given dest size or \n. | |
496 * If size max is reached, change the end to "..." | |
497 */ | |
498 void xs_pnstrcat(gchar *dest, const size_t size, const gchar *str) | |
499 { | |
500 size_t i, n; | |
501 const gchar *s; | |
502 gchar *d; | |
503 | |
504 for (d = dest, i = 0; *d && i < size; i++, d++); | |
505 | |
506 s = str; | |
507 while (*s && *s != '\n' && i < size) | |
508 { | |
509 *d = *s; | |
510 d++; | |
511 s++; | |
512 i++; | |
513 } | |
514 | |
515 *d = 0; | |
516 | |
517 if (i >= size) | |
518 { | |
519 i--; | |
520 d--; | |
521 for (n = 3; i > 0 && n > 0; d--, i--, n--) | |
522 *d = '.'; | |
523 } | |
524 } | |
525 | |
526 | |
527 /* Locate character in string | |
528 */ | |
529 void xs_findnext(const gchar *str, size_t *pos) | |
530 { | |
531 while (str[*pos] && isspace(str[*pos])) | |
532 (*pos)++; | |
533 } | |
534 | |
535 | |
536 void xs_findeol(const gchar *str, size_t *pos) | |
537 { | |
538 while (str[*pos] && (str[*pos] != '\n') && (str[*pos] != '\r')) | |
539 (*pos)++; | |
540 } | |
541 | |
542 | |
543 void xs_findnum(const gchar *str, size_t *pos) | |
544 { | |
545 while (str[*pos] && isdigit(str[*pos])) | |
546 (*pos)++; | |
547 } | |
548 | |
549 | |
967
0233c5fd7d5e
Add separate function for printing MD5 hashes.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
550 void xs_md5_print(FILE *fp, xs_md5hash_t digest) |
0233c5fd7d5e
Add separate function for printing MD5 hashes.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
551 { |
0233c5fd7d5e
Add separate function for printing MD5 hashes.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
552 gint i; |
0233c5fd7d5e
Add separate function for printing MD5 hashes.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
553 for (i = 0; i < XS_MD5HASH_LENGTH; i++) |
0233c5fd7d5e
Add separate function for printing MD5 hashes.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
554 fprintf(fp, "%02x", digest[i]); |
0233c5fd7d5e
Add separate function for printing MD5 hashes.
Matti Hamalainen <ccr@tnsp.org>
parents:
955
diff
changeset
|
555 } |