int main(){ xmlnode point; xmlnode conf; conf=xmlnode_file("./test.xml"); point=conf; printf("\n"); printf("Tagname is %s.\n", xmlnode_get_name(point)); printf("Data is \"%s\"\n", xmlnode_get_data(point)); printf("Type is %d.\n", xmlnode_get_type(point)); point = xmlnode_get_firstchild(point); printf("\n"); printf("Tagname is %s.\n", xmlnode_get_name(point)); printf("Data is \"%s\"\n", xmlnode_get_data(point)); printf("Type is %d.\n", xmlnode_get_type(point)); point = xmlnode_get_nextsibling(point); printf("\n"); printf("Tagname is %s.\n", xmlnode_get_name(point)); printf("Data is %s.\n", xmlnode_get_data(point)); printf("Type is %d.\n", xmlnode_get_type(point)); point = xmlnode_get_nextsibling(point); printf("\n"); printf("Tagname is %s.\n", xmlnode_get_name(point)); printf("Data is %s.\n", xmlnode_get_data(point)); printf("Type is %d.\n", xmlnode_get_type(point)); point = xmlnode_get_nextsibling(point); printf("\n"); printf("Tagname is %s.\n", xmlnode_get_name(point)); printf("Data is %s.\n", xmlnode_get_data(point)); printf("Type is %d.\n", xmlnode_get_type(point)); point = xmlnode_get_nextsibling(point); /* point = xmlnode_get_nextsibling(point); point = xmlnode_get_firstchild(point); point = xmlnode_get_nextsibling(xmlnode_get_parent(point)); */ xmlnode_free(conf); } /* END MAIN */
/** * A replacement for xdb_set * returns 0 if the set succeeded, 1 if not */ xmlnode xdb_get(void *noop, jid fn, char *ns) { extern jcr_instance jcr; char buf[512]; xmlnode x, child; memset(buf, 0, 512); snprintf(buf, 511, "%s/%s.xml", jcr->spool_dir, fn->user); x = xmlnode_file(buf); if (x == NULL) return NULL; if (ns != NULL) { memset(buf, 0, 512); snprintf(buf, 511, "?xdbns=%s", ns); child = xmlnode_get_tag(x, buf); if (child == NULL) xmlnode_free(x); return child; } else { return x; } }
User *user_load(const char *jid){ char *fn,*njid; xmlnode xml,tag,t; char *uin,*ujid,*name,*password,*email,*locale; char *status; int last_sys_msg=0,invisible=0,friends_only=0,ignore_unknown=0; unsigned int file_format_version=0; SubscriptionType subscribe; User *u; GList *contacts; char *p; char *data; uin=ujid=name=password=email=NULL; debug(L_("Loading user '%s'"),jid); fn=jid_normalized(jid,0); if (fn==NULL){ g_warning(L_("Bad JID: %s"),jid); return NULL; } errno=0; xml=xmlnode_file(fn); if (xml==NULL){ debug(L_("Couldn't read or parse '%s': %s"),fn,errno?g_strerror(errno):N_("XML parse error")); g_free(fn); return NULL; } g_free(fn); tag=xmlnode_get_tag(xml,"version"); if (tag!=NULL) { p=xmlnode_get_attrib(tag,"file_format"); if (p!=NULL) file_format_version=(unsigned int)strtol(p,NULL,16); } tag=xmlnode_get_tag(xml,"jid"); if (tag!=NULL) { ujid=xmlnode_get_data(tag); subscribe=get_subscribe(tag, file_format_version); } if (ujid==NULL){ g_warning(L_("Couldn't find JID in %s's file"),jid); return NULL; } tag=xmlnode_get_tag(xml,"uin"); if (tag!=NULL) uin=xmlnode_get_data(tag); if (uin==NULL){ g_warning(L_("Couldn't find UIN in %s's file"),jid); return NULL; } tag=xmlnode_get_tag(xml,"password"); if (tag!=NULL) password=xmlnode_get_data(tag); if (password==NULL){ g_warning(L_("Couldn't find password in %s's file"),jid); return NULL; } tag=xmlnode_get_tag(xml,"email"); if (tag!=NULL) email=xmlnode_get_data(tag); tag=xmlnode_get_tag(xml,"name"); if (tag!=NULL) name=xmlnode_get_data(tag); tag=xmlnode_get_tag(xml,"last_sys_msg"); if (tag!=NULL){ data=xmlnode_get_data(tag); if (data!=NULL) last_sys_msg=atoi(data); } tag=xmlnode_get_tag(xml,"friendsonly"); if (tag!=NULL) friends_only=1; tag=xmlnode_get_tag(xml,"invisible"); if (tag!=NULL) invisible=1; tag=xmlnode_get_tag(xml,"ignore_unknown"); if (tag!=NULL) ignore_unknown=1; tag=xmlnode_get_tag(xml,"locale"); if (tag!=NULL) locale=xmlnode_get_data(tag); else locale=NULL; tag=xmlnode_get_tag(xml,"status"); if (tag!=NULL) { status=xmlnode_get_data(tag); if (status==NULL) status=""; } else status=NULL; tag=xmlnode_get_tag(xml,"userlist"); contacts=NULL; if (tag!=NULL){ Contact *c; for(t=xmlnode_get_firstchild(tag);t;t=xmlnode_get_nextsibling(t)){ char *node_name; node_name=xmlnode_get_name(t); if (!node_name) continue; if (!strcmp(node_name,"uin")){ char *d; int uin; d=xmlnode_get_data(t); if (d==NULL) continue; uin=atoi(d); if (uin<=0) continue; c=g_new0(Contact,1); c->status=-1; c->uin=uin; contacts=g_list_append(contacts,c); continue; } if (!strcmp(node_name,"contact")){ char *d; int uin; d=xmlnode_get_attrib(t,"uin"); if (d==NULL) continue; uin=atoi(d); if (uin<=0) continue; c=g_new0(Contact,1); c->status=-1; c->uin=uin; d=xmlnode_get_attrib(t,"ignored"); if (d!=NULL && d[0]!='\000') c->ignored=1; else c->ignored=0; d=xmlnode_get_attrib(t,"blocked"); if (d!=NULL && d[0]!='\000') c->blocked=1; else c->blocked=0; c->subscribe=get_subscribe(t, file_format_version); contacts=g_list_append(contacts,c); } } } u=g_new0(User,1); u->uin=atoi(uin); u->jid=g_strdup(jid); p=strchr(u->jid,'/'); if (p) *p=0; u->password=g_strdup(password); u->last_sys_msg=last_sys_msg; u->friends_only=friends_only; u->invisible=invisible; u->ignore_unknown=ignore_unknown; u->locale=g_strdup(locale); u->status=g_strdup(from_utf8(status)); u->contacts=contacts; xmlnode_free(xml); g_assert(users_jid!=NULL); njid=jid_normalized(u->jid,0); g_assert(njid!=NULL); g_hash_table_insert(users_jid,(gpointer)njid,(gpointer)u); u->confirmed=1; u->subscribe=subscribe; return u; }