| | 465 | static SmlBool _smlChalMetaParse(SmlXmlParser *parser, char **format, char **type, char **nonce, SmlError **error) |
|---|
| | 466 | { |
|---|
| | 467 | smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p, %p, %p)", __func__, parser, format, type, nonce, error); |
|---|
| | 468 | smlAssert(parser); |
|---|
| | 469 | |
|---|
| | 470 | while (1) { |
|---|
| | 471 | if (!_smlXmlParserStep(parser)) { |
|---|
| | 472 | smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); |
|---|
| | 473 | goto error; |
|---|
| | 474 | } |
|---|
| | 475 | |
|---|
| | 476 | if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META) && \ |
|---|
| | 477 | xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { |
|---|
| | 478 | break; |
|---|
| | 479 | } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { |
|---|
| | 480 | smlErrorSet(error, SML_ERROR_GENERIC, "Not a start node"); |
|---|
| | 481 | goto error; |
|---|
| | 482 | } |
|---|
| | 483 | |
|---|
| | 484 | if (type && !strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TYPE)) { |
|---|
| | 485 | if (!_smlXmlParserGetString(parser, type, SML_ELEMENT_TYPE, error)) |
|---|
| | 486 | goto error; |
|---|
| | 487 | } else if (format && !strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_FORMAT)) { |
|---|
| | 488 | if (!_smlXmlParserGetString(parser, format, SML_ELEMENT_FORMAT, error)) |
|---|
| | 489 | goto error; |
|---|
| | 490 | } else if (format && !strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_NEXTNONCE)) { |
|---|
| | 491 | if (!_smlXmlParserGetString(parser, nonce, SML_ELEMENT_NEXTNONCE, error)) |
|---|
| | 492 | goto error; |
|---|
| | 493 | } else { |
|---|
| | 494 | smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node: %s", xmlTextReaderConstName(parser->reader)); |
|---|
| | 495 | goto error; |
|---|
| | 496 | } |
|---|
| | 497 | } |
|---|
| | 498 | |
|---|
| | 499 | smlTrace(TRACE_EXIT, "%s", __func__); |
|---|
| | 500 | return TRUE; |
|---|
| | 501 | |
|---|
| | 502 | error: |
|---|
| | 503 | if (format) |
|---|
| | 504 | *format = NULL; |
|---|
| | 505 | if (nonce) |
|---|
| | 506 | *nonce = NULL; |
|---|
| | 507 | if (type) |
|---|
| | 508 | *type = NULL; |
|---|
| | 509 | |
|---|
| | 510 | smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); |
|---|
| | 511 | return FALSE; |
|---|
| | 512 | } |
|---|
| | 513 | |
|---|
| 465 | 514 | static SmlBool _smlCommandMetaParse(SmlXmlParser *parser, char **format, char **type, SmlAnchor **anchor, unsigned int *size, int *maxobjsize, SmlError **error) |
|---|
| 466 | 515 | { |
|---|
| 467 | 516 | smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p, %p, %p)", __func__, parser, format, type, anchor, size, maxobjsize, error); |
| | 812 | static SmlChal *_smlChalParse(SmlXmlParser *parser, SmlError **error) |
|---|
| | 813 | { |
|---|
| | 814 | smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, parser, error); |
|---|
| | 815 | smlAssert(parser); |
|---|
| | 816 | char *format = NULL; |
|---|
| | 817 | char *type = NULL; |
|---|
| | 818 | |
|---|
| | 819 | SmlChal *chal = smlTryMalloc0(sizeof(SmlChal), error); |
|---|
| | 820 | if (!chal) |
|---|
| | 821 | goto error; |
|---|
| | 822 | |
|---|
| | 823 | while (1) { |
|---|
| | 824 | if (!_smlXmlParserStep(parser)) { |
|---|
| | 825 | smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); |
|---|
| | 826 | goto error_free_chal; |
|---|
| | 827 | } |
|---|
| | 828 | |
|---|
| | 829 | if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CHAL) && \ |
|---|
| | 830 | xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { |
|---|
| | 831 | break; |
|---|
| | 832 | } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { |
|---|
| | 833 | smlErrorSet(error, SML_ERROR_GENERIC, "Not a start node"); |
|---|
| | 834 | goto error_free_chal; |
|---|
| | 835 | } |
|---|
| | 836 | |
|---|
| | 837 | if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { |
|---|
| | 838 | if (!_smlChalMetaParse(parser, &format, &type, &chal->nonce, error)) |
|---|
| | 839 | goto error_free_chal; |
|---|
| | 840 | } else { |
|---|
| | 841 | smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); |
|---|
| | 842 | goto error_free_chal; |
|---|
| | 843 | } |
|---|
| | 844 | } |
|---|
| | 845 | |
|---|
| | 846 | if (!format || !strcmp(format, SML_BASE64)) { |
|---|
| | 847 | chal->format = SML_FORMAT_TYPE_BASE64; |
|---|
| | 848 | } else { |
|---|
| | 849 | smlErrorSet(error, SML_ERROR_GENERIC, "Unknown format"); |
|---|
| | 850 | goto error_free_chal; |
|---|
| | 851 | } |
|---|
| | 852 | |
|---|
| | 853 | if (!type || !strcmp(type, SML_AUTH_BASIC)) { |
|---|
| | 854 | chal->type = SML_AUTH_TYPE_BASIC; |
|---|
| | 855 | } else if (!strcmp(type, SML_AUTH_MD5)) { |
|---|
| | 856 | chal->type = SML_AUTH_TYPE_MD5; |
|---|
| | 857 | } else { |
|---|
| | 858 | smlErrorSet(error, SML_ERROR_GENERIC, "Unknown type"); |
|---|
| | 859 | goto error_free_chal; |
|---|
| | 860 | } |
|---|
| | 861 | |
|---|
| | 862 | if (format) |
|---|
| | 863 | g_free(format); |
|---|
| | 864 | if (type) |
|---|
| | 865 | g_free(type); |
|---|
| | 866 | |
|---|
| | 867 | smlTrace(TRACE_EXIT, "%s: %p", __func__, chal); |
|---|
| | 868 | return chal; |
|---|
| | 869 | |
|---|
| | 870 | error_free_chal: |
|---|
| | 871 | smlChalFree(chal); |
|---|
| | 872 | error: |
|---|
| | 873 | if (format) |
|---|
| | 874 | g_free(format); |
|---|
| | 875 | if (type) |
|---|
| | 876 | g_free(type); |
|---|
| | 877 | smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); |
|---|
| | 878 | return NULL; |
|---|
| | 879 | } |
|---|
| | 880 | |
|---|