// public API, inits stream instance; a particular namespace is to be // used with Jabber, see the constant defined in the public header // // note that interestingly, the mainline version allocates both an // iksparser and stream_data, but returns the parser rather than // stream_data -- perhaps the idea is to provide the parsing interface // regardless of what the data source is, just creating a different // kind of parser ikss_Stream * ikss_Stream_new (char *name_space, void *user_data, iksStreamHook *streamHook, ikss_NotifyFunc* notifyFunc) { ikss_Stream *self; ikstack *s; s = iks_stack_new (DEFAULT_STREAM_CHUNK_SIZE, 0); if (NULL == s) return NULL; self = iks_stack_alloc (s, sizeof (ikss_Stream)); if (!self) { iks_stack_delete(s); return NULL; } memset (self, 0, sizeof (ikss_Stream)); self->s = s; // This creates the parser, placing the object into "s" memory. Note // that self->prs now takes ownership of "s", and iks_parser_delete // will delete it. self->prs = iks_sax_extend (s, self, (iksTagHook *)tagHook, (iksCDataHook *)cdataHook, (iksDeleteHook *)deleteHook); if (!self->prs) { iks_stack_delete(s); return NULL; } self->name_space = name_space; self->user_data = user_data; self->streamHook = streamHook; self->notifyFunc = notifyFunc; return self; }
iksparser * iks_stream_new (char *name_space, void *user_data, iksStreamHook *streamHook) { ikstack *s; struct stream_data *data; s = iks_stack_new (DEFAULT_STREAM_CHUNK_SIZE, 0); if (NULL == s) return NULL; data = iks_stack_alloc (s, sizeof (struct stream_data)); memset (data, 0, sizeof (struct stream_data)); data->s = s; data->prs = iks_sax_extend (s, data, (iksTagHook *)tagHook, (iksCDataHook *)cdataHook, (iksDeleteHook *)deleteHook); data->name_space = name_space; data->user_data = user_data; data->streamHook = streamHook; return data->prs; }