DBJsonBase.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Copyright (C) 2009 Stig Brautaset. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. * Redistributions of source code must retain the above copyright notice, this
  6. list of conditions and the following disclaimer.
  7. * Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. * Neither the name of the author nor the names of its contributors may be used
  11. to endorse or promote products derived from this software without specific
  12. prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  17. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  21. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  22. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #import <Foundation/Foundation.h>
  25. extern NSString * DBJSONErrorDomain;
  26. enum {
  27. EUNSUPPORTED = 1,
  28. EPARSENUM,
  29. EPARSE,
  30. EFRAGMENT,
  31. ECTRL,
  32. EUNICODE,
  33. EDEPTH,
  34. EESCAPE,
  35. ETRAILCOMMA,
  36. ETRAILGARBAGE,
  37. EEOF,
  38. EINPUT
  39. };
  40. /**
  41. @brief Common base class for parsing & writing.
  42. This class contains the common error-handling code and option between the parser/writer.
  43. */
  44. @interface DBJsonBase : NSObject {
  45. NSMutableArray *errorTrace;
  46. @protected
  47. NSUInteger depth, maxDepth;
  48. }
  49. /**
  50. @brief The maximum recursing depth.
  51. Defaults to 512. If the input is nested deeper than this the input will be deemed to be
  52. malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can
  53. turn off this security feature by setting the maxDepth value to 0.
  54. */
  55. @property NSUInteger maxDepth;
  56. /**
  57. @brief Return an error trace, or nil if there was no errors.
  58. Note that this method returns the trace of the last method that failed.
  59. You need to check the return value of the call you're making to figure out
  60. if the call actually failed, before you know call this method.
  61. */
  62. @property(copy,readonly) NSArray* errorTrace;
  63. /// @internal for use in subclasses to add errors to the stack trace
  64. - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str;
  65. /// @internal for use in subclasess to clear the error before a new parsing attempt
  66. - (void)clearErrorTrace;
  67. @end