Logo Search packages:      
Sourcecode: libical version File versions  Download package

icalcomponent* icalparser_parse ( icalparser *  parser,
char *(*)(char *s, size_t size, void *d)  line_gen_func 
)

Message oriented parsing. icalparser_parse takes a string that holds the text ( in RFC 2445 format ) and returns a pointer to an icalcomponent. The caller owns the memory. line_gen_func is a pointer to a function that returns one content line per invocation

Definition at line 575 of file icalparser.c.

{

    char* line; 
    icalcomponent *c=0; 
    icalcomponent *root=0;
    icalerrorstate es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR);
      int cont;

    icalerror_check_arg_rz((parser !=0),"parser");

    icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL);

    do{
          line = icalparser_get_line(parser, line_gen_func);

      if ((c = icalparser_add_line(parser,line)) != 0){

          if(icalcomponent_get_parent(c) !=0){
            /* This is bad news... assert? */
          }     
          
          assert(parser->root_component == 0);
          assert(pvl_count(parser->components) ==0);

          if (root == 0){
            /* Just one component */
            root = c;
          } else if(icalcomponent_isa(root) != ICAL_XROOT_COMPONENT) {
            /*Got a second component, so move the two components under
              an XROOT container */
            icalcomponent *tempc = icalcomponent_new(ICAL_XROOT_COMPONENT);
            icalcomponent_add_component(tempc, root);
            icalcomponent_add_component(tempc, c);
            root = tempc;
          } else if(icalcomponent_isa(root) == ICAL_XROOT_COMPONENT) {
            /* Already have an XROOT container, so add the component
               to it*/
            icalcomponent_add_component(root, c);
            
          } else {
            /* Badness */
            assert(0);
          }

          c = 0;

        }
      cont = 0;
      if(line != 0){
          icalmemory_free_buffer(line);
            cont = 1;
      }
    } while ( cont );

    icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es);

    return root;

}


Generated by  Doxygen 1.6.0   Back to index