diff options
Diffstat (limited to 'src/util/common_logging.c')
-rw-r--r-- | src/util/common_logging.c | 183 |
1 files changed, 147 insertions, 36 deletions
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index ea5430191..be2e084b5 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2006-2013 GNUnet e.V. | 3 | Copyright (C) 2006-2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -628,6 +626,9 @@ parse_definitions (const char *constname, int force) | |||
628 | to_line = INT_MAX; | 626 | to_line = INT_MAX; |
629 | } | 627 | } |
630 | break; | 628 | break; |
629 | default: | ||
630 | fprintf(stderr, "ERROR: Unable to parse log defintion: Syntax error.\n"); | ||
631 | break; | ||
631 | } | 632 | } |
632 | start = p + 1; | 633 | start = p + 1; |
633 | state++; | 634 | state++; |
@@ -654,6 +655,7 @@ parse_definitions (const char *constname, int force) | |||
654 | start = p + 1; | 655 | start = p + 1; |
655 | break; | 656 | break; |
656 | default: | 657 | default: |
658 | fprintf(stderr, "ERROR: Unable to parse log defintion: Syntax error.\n"); | ||
657 | break; | 659 | break; |
658 | } | 660 | } |
659 | default: | 661 | default: |
@@ -815,32 +817,39 @@ output_message (enum GNUNET_ErrorType kind, | |||
815 | if ( (NULL != GNUNET_stderr) && | 817 | if ( (NULL != GNUNET_stderr) && |
816 | (NULL == loggers) ) | 818 | (NULL == loggers) ) |
817 | { | 819 | { |
818 | if (kind == GNUNET_ERROR_TYPE_MESSAGE) { | 820 | if (kind == GNUNET_ERROR_TYPE_MESSAGE) |
819 | /* The idea here is to produce "normal" output messages | 821 | { |
820 | * for end users while still having the power of the | 822 | /* The idea here is to produce "normal" output messages |
821 | * logging engine for developer needs. So ideally this | 823 | * for end users while still having the power of the |
822 | * is what it should look like when CLI tools are used | 824 | * logging engine for developer needs. So ideally this |
823 | * interactively, yet the same message shouldn't look | 825 | * is what it should look like when CLI tools are used |
824 | * this way if the output is going to logfiles or robots | 826 | * interactively, yet the same message shouldn't look |
825 | * instead. Is this the right place to do this? --lynX | 827 | * this way if the output is going to logfiles or robots |
826 | */ | 828 | * instead. |
827 | FPRINTF (GNUNET_stderr, | 829 | */ |
828 | "* %s", | 830 | FPRINTF (GNUNET_stderr, |
829 | msg); | 831 | "* %s", |
830 | } else { | 832 | msg); |
831 | FPRINTF (GNUNET_stderr, | 833 | } |
832 | "%s %s %s %s", | 834 | else |
833 | datestr, | 835 | { |
834 | comp, | 836 | FPRINTF (GNUNET_stderr, |
835 | GNUNET_error_type_to_string (kind), | 837 | "%s %s %s %s", |
836 | msg); | 838 | datestr, |
839 | comp, | ||
840 | GNUNET_error_type_to_string (kind), | ||
841 | msg); | ||
837 | } | 842 | } |
838 | fflush (GNUNET_stderr); | 843 | fflush (GNUNET_stderr); |
839 | } | 844 | } |
840 | pos = loggers; | 845 | pos = loggers; |
841 | while (pos != NULL) | 846 | while (NULL != pos) |
842 | { | 847 | { |
843 | pos->logger (pos->logger_cls, kind, comp, datestr, msg); | 848 | pos->logger (pos->logger_cls, |
849 | kind, | ||
850 | comp, | ||
851 | datestr, | ||
852 | msg); | ||
844 | pos = pos->next; | 853 | pos = pos->next; |
845 | } | 854 | } |
846 | #if WINDOWS | 855 | #if WINDOWS |
@@ -1192,6 +1201,106 @@ GNUNET_h2s2 (const struct GNUNET_HashCode * hc) | |||
1192 | 1201 | ||
1193 | /** | 1202 | /** |
1194 | * @ingroup logging | 1203 | * @ingroup logging |
1204 | * Convert a public key value to a string (for printing debug messages). | ||
1205 | * This is one of the very few calls in the entire API that is | ||
1206 | * NOT reentrant! | ||
1207 | * | ||
1208 | * @param hc the hash code | ||
1209 | * @return string | ||
1210 | */ | ||
1211 | const char * | ||
1212 | GNUNET_p2s (const struct GNUNET_CRYPTO_EddsaPublicKey *p) | ||
1213 | { | ||
1214 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | ||
1215 | struct GNUNET_HashCode hc; | ||
1216 | |||
1217 | GNUNET_CRYPTO_hash (p, | ||
1218 | sizeof (*p), | ||
1219 | &hc); | ||
1220 | GNUNET_CRYPTO_hash_to_enc (&hc, | ||
1221 | &ret); | ||
1222 | ret.encoding[6] = '\0'; | ||
1223 | return (const char *) ret.encoding; | ||
1224 | } | ||
1225 | |||
1226 | |||
1227 | /** | ||
1228 | * @ingroup logging | ||
1229 | * Convert a public key value to a string (for printing debug messages). | ||
1230 | * This is one of the very few calls in the entire API that is | ||
1231 | * NOT reentrant! | ||
1232 | * | ||
1233 | * @param hc the hash code | ||
1234 | * @return string | ||
1235 | */ | ||
1236 | const char * | ||
1237 | GNUNET_p2s2 (const struct GNUNET_CRYPTO_EddsaPublicKey *p) | ||
1238 | { | ||
1239 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | ||
1240 | struct GNUNET_HashCode hc; | ||
1241 | |||
1242 | GNUNET_CRYPTO_hash (p, | ||
1243 | sizeof (*p), | ||
1244 | &hc); | ||
1245 | GNUNET_CRYPTO_hash_to_enc (&hc, | ||
1246 | &ret); | ||
1247 | ret.encoding[6] = '\0'; | ||
1248 | return (const char *) ret.encoding; | ||
1249 | } | ||
1250 | |||
1251 | |||
1252 | /** | ||
1253 | * @ingroup logging | ||
1254 | * Convert a public key value to a string (for printing debug messages). | ||
1255 | * This is one of the very few calls in the entire API that is | ||
1256 | * NOT reentrant! | ||
1257 | * | ||
1258 | * @param hc the hash code | ||
1259 | * @return string | ||
1260 | */ | ||
1261 | const char * | ||
1262 | GNUNET_e2s (const struct GNUNET_CRYPTO_EcdhePublicKey *p) | ||
1263 | { | ||
1264 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | ||
1265 | struct GNUNET_HashCode hc; | ||
1266 | |||
1267 | GNUNET_CRYPTO_hash (p, | ||
1268 | sizeof (*p), | ||
1269 | &hc); | ||
1270 | GNUNET_CRYPTO_hash_to_enc (&hc, | ||
1271 | &ret); | ||
1272 | ret.encoding[6] = '\0'; | ||
1273 | return (const char *) ret.encoding; | ||
1274 | } | ||
1275 | |||
1276 | |||
1277 | /** | ||
1278 | * @ingroup logging | ||
1279 | * Convert a public key value to a string (for printing debug messages). | ||
1280 | * This is one of the very few calls in the entire API that is | ||
1281 | * NOT reentrant! | ||
1282 | * | ||
1283 | * @param hc the hash code | ||
1284 | * @return string | ||
1285 | */ | ||
1286 | const char * | ||
1287 | GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p) | ||
1288 | { | ||
1289 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | ||
1290 | struct GNUNET_HashCode hc; | ||
1291 | |||
1292 | GNUNET_CRYPTO_hash (p, | ||
1293 | sizeof (*p), | ||
1294 | &hc); | ||
1295 | GNUNET_CRYPTO_hash_to_enc (&hc, | ||
1296 | &ret); | ||
1297 | ret.encoding[6] = '\0'; | ||
1298 | return (const char *) ret.encoding; | ||
1299 | } | ||
1300 | |||
1301 | |||
1302 | /** | ||
1303 | * @ingroup logging | ||
1195 | * Convert a short hash value to a string (for printing debug messages). | 1304 | * Convert a short hash value to a string (for printing debug messages). |
1196 | * This is one of the very few calls in the entire API that is | 1305 | * This is one of the very few calls in the entire API that is |
1197 | * NOT reentrant! | 1306 | * NOT reentrant! |
@@ -1244,14 +1353,15 @@ GNUNET_h2s_full (const struct GNUNET_HashCode * hc) | |||
1244 | const char * | 1353 | const char * |
1245 | GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) | 1354 | GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) |
1246 | { | 1355 | { |
1247 | static char buf[256]; | 1356 | static char buf[5]; |
1248 | char *ret; | 1357 | char *ret; |
1249 | 1358 | ||
1250 | if (NULL == pid) | 1359 | if (NULL == pid) |
1251 | return "NULL"; | 1360 | return "NULL"; |
1252 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); | 1361 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1253 | strcpy (buf, | 1362 | strncpy (buf, |
1254 | ret); | 1363 | ret, |
1364 | sizeof (buf) - 1); | ||
1255 | GNUNET_free (ret); | 1365 | GNUNET_free (ret); |
1256 | buf[4] = '\0'; | 1366 | buf[4] = '\0'; |
1257 | return buf; | 1367 | return buf; |
@@ -1272,14 +1382,15 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) | |||
1272 | const char * | 1382 | const char * |
1273 | GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) | 1383 | GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) |
1274 | { | 1384 | { |
1275 | static char buf[256]; | 1385 | static char buf[5]; |
1276 | char *ret; | 1386 | char *ret; |
1277 | 1387 | ||
1278 | if (NULL == pid) | 1388 | if (NULL == pid) |
1279 | return "NULL"; | 1389 | return "NULL"; |
1280 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); | 1390 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1281 | strcpy (buf, | 1391 | strncpy (buf, |
1282 | ret); | 1392 | ret, |
1393 | sizeof (buf) - 1); | ||
1283 | GNUNET_free (ret); | 1394 | GNUNET_free (ret); |
1284 | buf[4] = '\0'; | 1395 | buf[4] = '\0'; |
1285 | return buf; | 1396 | return buf; |