| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
#include "ggtrans.h" |
|---|
| 21 |
#include "jabber.h" |
|---|
| 22 |
#include "register.h" |
|---|
| 23 |
#include "iq.h" |
|---|
| 24 |
#include "users.h" |
|---|
| 25 |
#include "sessions.h" |
|---|
| 26 |
#include "presence.h" |
|---|
| 27 |
#include "users.h" |
|---|
| 28 |
#include "requests.h" |
|---|
| 29 |
#include "encoding.h" |
|---|
| 30 |
#include "forms.h" |
|---|
| 31 |
#include "jid.h" |
|---|
| 32 |
#include "debug.h" |
|---|
| 33 |
|
|---|
| 34 |
char *register_instructions; |
|---|
| 35 |
|
|---|
| 36 |
static struct { |
|---|
| 37 |
char *lang_name; |
|---|
| 38 |
char *locale; |
|---|
| 39 |
} locale_mapping[]={ |
|---|
| 40 |
{ "Polski", "pl_PL"}, |
|---|
| 41 |
{ "Nederlands", "nl_NL"}, |
|---|
| 42 |
{ "English", "C" }, |
|---|
| 43 |
{ NULL, NULL} |
|---|
| 44 |
}; |
|---|
| 45 |
|
|---|
| 46 |
xmlnode register_form(xmlnode parent,User *u){ |
|---|
| 47 |
xmlnode form,field; |
|---|
| 48 |
int i; |
|---|
| 49 |
char *tmp; |
|---|
| 50 |
|
|---|
| 51 |
form=form_new(parent,_("Jabber GG transport registration form"), |
|---|
| 52 |
_("Fill in this form to regiser in the transport.\n" |
|---|
| 53 |
"You may use registration later to change your settings," |
|---|
| 54 |
" public directory information or to unregister.")); |
|---|
| 55 |
|
|---|
| 56 |
form_add_field(form,"text-single","uin",_("GG number"),NULL,1); |
|---|
| 57 |
form_add_field(form,"text-private","password",_("Password"),NULL,1); |
|---|
| 58 |
|
|---|
| 59 |
field=form_add_field(form,"list-single","userlist",_("Userlist on GG server"),"get",0); |
|---|
| 60 |
form_add_option(field,_("ignore"),"ignore"); |
|---|
| 61 |
form_add_option(field,_("retrieve"),"get"); |
|---|
| 62 |
|
|---|
| 63 |
if (default_user_locale && default_user_locale[0]) tmp=default_user_locale; |
|---|
| 64 |
else tmp="_default_"; |
|---|
| 65 |
|
|---|
| 66 |
field=form_add_field(form,"list-single","locale",_("Language"),tmp,0); |
|---|
| 67 |
form_add_option(field,_("-default-"),"_default_"); |
|---|
| 68 |
for(i=0;locale_mapping[i].locale!=NULL;i++) |
|---|
| 69 |
form_add_option(field,locale_mapping[i].lang_name,locale_mapping[i].locale); |
|---|
| 70 |
|
|---|
| 71 |
form_add_field(form,"boolean","friends_only",_("Friends only"),"1",1); |
|---|
| 72 |
form_add_field(form,"boolean","invisible",_("Invisible"),"0",1); |
|---|
| 73 |
|
|---|
| 74 |
return form; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
xmlnode register_change_form(xmlnode parent,User *u){ |
|---|
| 79 |
xmlnode form,field; |
|---|
| 80 |
int i; |
|---|
| 81 |
|
|---|
| 82 |
form=form_new(parent,_("Registration change form"), |
|---|
| 83 |
_("You may use this form to change account" |
|---|
| 84 |
" information, change personal information" |
|---|
| 85 |
" in the public directory or unregister from" |
|---|
| 86 |
" the transport.")); |
|---|
| 87 |
|
|---|
| 88 |
field=form_add_field(form,"list-single","action",_("Action"),"options",1); |
|---|
| 89 |
form_add_option(field,_("Change account options"),"options"); |
|---|
| 90 |
|
|---|
| 91 |
form_add_option(field,_("Change public directory information"),"pubdir"); |
|---|
| 92 |
form_add_option(field,_("Unregister"),"unregister"); |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
form_add_fixed(form,_("Fill out this part only when changing account options:")); |
|---|
| 96 |
field=form_add_field(form,"list-single","locale",_("Language"), |
|---|
| 97 |
(u->locale&&u->locale[0])?u->locale:"_default_",0); |
|---|
| 98 |
form_add_option(field,_("-default-"),"_default_"); |
|---|
| 99 |
for(i=0;locale_mapping[i].locale!=NULL;i++) |
|---|
| 100 |
form_add_option(field,locale_mapping[i].lang_name,locale_mapping[i].locale); |
|---|
| 101 |
form_add_field(form,"boolean","friends_only",_("Friends only"), |
|---|
| 102 |
u->friends_only?"1":"0",0); |
|---|
| 103 |
form_add_field(form,"boolean","invisible",_("Invisible"), |
|---|
| 104 |
u->invisible?"1":"0",0); |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
form_add_fixed(form,_("Fill out this part only when changing public directory info:")); |
|---|
| 113 |
form_add_field(form,"text-single","firstname",_("First name"),NULL,0); |
|---|
| 114 |
form_add_field(form,"text-single","lastname",_("Last name"),NULL,0); |
|---|
| 115 |
form_add_field(form,"text-single","nick",_("Nick"),NULL,0); |
|---|
| 116 |
form_add_field(form,"text-single","birthyear",_("Birth year"),NULL,0); |
|---|
| 117 |
form_add_field(form,"text-single","city",_("City"),NULL,0); |
|---|
| 118 |
field=form_add_field(form,"list-single","gender",_("Sex"),"_none_",0); |
|---|
| 119 |
form_add_option(field,"-","_none_"); |
|---|
| 120 |
form_add_option(field,_("female"),GG_PUBDIR50_GENDER_FEMALE); |
|---|
| 121 |
form_add_option(field,_("male"),GG_PUBDIR50_GENDER_MALE); |
|---|
| 122 |
form_add_field(form,"text-single","familyname",_("Family name"),NULL,0); |
|---|
| 123 |
form_add_field(form,"text-single","familycity",_("Family city"),NULL,0); |
|---|
| 124 |
|
|---|
| 125 |
return form; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
int register_process_options_form(Stream *s,const char *from,const char *to, |
|---|
| 129 |
const char *id,User *u,xmlnode form){ |
|---|
| 130 |
xmlnode field,value; |
|---|
| 131 |
char *locale=NULL,*invisible=NULL,*friends_only=NULL; |
|---|
| 132 |
Session *session; |
|---|
| 133 |
|
|---|
| 134 |
field=xmlnode_get_tag(form,"field?var=locale"); |
|---|
| 135 |
if (field!=NULL){ |
|---|
| 136 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 137 |
if (value!=NULL) locale=xmlnode_get_data(value); |
|---|
| 138 |
} |
|---|
| 139 |
if (locale && !strcmp(locale,"_default_")) locale=""; |
|---|
| 140 |
|
|---|
| 141 |
field=xmlnode_get_tag(form,"field?var=invisible"); |
|---|
| 142 |
if (field!=NULL){ |
|---|
| 143 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 144 |
if (value!=NULL) invisible=xmlnode_get_data(value); |
|---|
| 145 |
} |
|---|
| 146 |
field=xmlnode_get_tag(form,"field?var=friends_only"); |
|---|
| 147 |
if (field!=NULL){ |
|---|
| 148 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 149 |
if (value!=NULL) friends_only=xmlnode_get_data(value); |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
if (u->locale!=NULL) g_free(u->locale); |
|---|
| 153 |
u->locale=g_strdup(locale); |
|---|
| 154 |
if (invisible && (!strcmp(invisible,"1")||!strcmp(invisible,"yes"))) |
|---|
| 155 |
u->invisible=1; |
|---|
| 156 |
else |
|---|
| 157 |
u->invisible=0; |
|---|
| 158 |
if (friends_only && (!strcmp(friends_only,"1")||!strcmp(friends_only,"yes"))) |
|---|
| 159 |
u->friends_only=1; |
|---|
| 160 |
else |
|---|
| 161 |
u->friends_only=0; |
|---|
| 162 |
session=session_get_by_jid(u->jid,NULL,0); |
|---|
| 163 |
if (session!=NULL) session_send_status(session); |
|---|
| 164 |
user_save(u); |
|---|
| 165 |
|
|---|
| 166 |
return 0; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
#if 0 |
|---|
| 170 |
|
|---|
| 171 |
int register_process_passwd_form(Stream *s,const char *from,const char *to, |
|---|
| 172 |
const char *id,User *u,xmlnode form){ |
|---|
| 173 |
xmlnode field,value; |
|---|
| 174 |
char *newpasswd=NULL,*newpasswdW,*newpasswd2=NULL,*question=NULL,*answer=NULL,*qa,*qaW; |
|---|
| 175 |
struct gg_http *gghttp; |
|---|
| 176 |
Request *r; |
|---|
| 177 |
|
|---|
| 178 |
field=xmlnode_get_tag(form,"field?var=newpassword"); |
|---|
| 179 |
if (field!=NULL){ |
|---|
| 180 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 181 |
if (value!=NULL) newpasswd=xmlnode_get_data(value); |
|---|
| 182 |
} |
|---|
| 183 |
if (newpasswd==NULL){ |
|---|
| 184 |
jabber_iq_send_error(s,from,to,id,406,_("No new password given")); |
|---|
| 185 |
return -1; |
|---|
| 186 |
} |
|---|
| 187 |
field=xmlnode_get_tag(form,"field?var=newpassword2"); |
|---|
| 188 |
if (field!=NULL){ |
|---|
| 189 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 190 |
if (value!=NULL) newpasswd2=xmlnode_get_data(value); |
|---|
| 191 |
} |
|---|
| 192 |
if (newpasswd2==NULL || strcmp(newpasswd,newpasswd2)!=0){ |
|---|
| 193 |
jabber_iq_send_error(s,from,to,id,406,_("Passwords do not match")); |
|---|
| 194 |
return -1; |
|---|
| 195 |
} |
|---|
| 196 |
if (strcmp(newpasswd,u->password)==0){ |
|---|
| 197 |
jabber_iq_send_error(s,from,to,id,406,_("New password is the same as the old one.")); |
|---|
| 198 |
return -1; |
|---|
| 199 |
} |
|---|
| 200 |
field=xmlnode_get_tag(form,"field?var=question"); |
|---|
| 201 |
if (field!=NULL){ |
|---|
| 202 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 203 |
if (value!=NULL) question=xmlnode_get_data(value); |
|---|
| 204 |
} |
|---|
| 205 |
if (question==NULL) question=""; |
|---|
| 206 |
else if (strchr(question,'~')){ |
|---|
| 207 |
jabber_iq_send_error(s,from,to,id,406,_("Question contains illegal characters.")); |
|---|
| 208 |
return -1; |
|---|
| 209 |
} |
|---|
| 210 |
field=xmlnode_get_tag(form,"field?var=answer"); |
|---|
| 211 |
if (field!=NULL){ |
|---|
| 212 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 213 |
if (value!=NULL) answer=xmlnode_get_data(value); |
|---|
| 214 |
} |
|---|
| 215 |
if (answer==NULL) answer=""; |
|---|
| 216 |
else if (strchr(answer,'~')){ |
|---|
| 217 |
jabber_iq_send_error(s,from,to,id,406,_("Answer contains illegal characters.")); |
|---|
| 218 |
return -1; |
|---|
| 219 |
} |
|---|
| 220 |
qa=g_strdup_printf("%s~%s",question,answer); |
|---|
| 221 |
qaW=g_strdup(from_utf8(qa)); |
|---|
| 222 |
g_free(qa); |
|---|
| 223 |
newpasswdW=g_strdup(from_utf8(newpasswd)); |
|---|
| 224 |
gghttp=gg_change_passwd3(u->uin,from_utf8(u->password),newpasswdW,qaW,1); |
|---|
| 225 |
g_free(newpasswdW); |
|---|
| 226 |
g_free(qaW); |
|---|
| 227 |
if (gghttp!=NULL) { |
|---|
| 228 |
r=add_request(RT_PASSWD,from,to,id,form,gghttp,s); |
|---|
| 229 |
r->data=g_strdup(newpasswd); |
|---|
| 230 |
} |
|---|
| 231 |
return 0; |
|---|
| 232 |
} |
|---|
| 233 |
#endif |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
#define FIELD_TO_PUBDIR(fieldname,symbol) \ |
|---|
| 237 |
val=0; \ |
|---|
| 238 |
field=xmlnode_get_tag(form,"field?var=" fieldname); \ |
|---|
| 239 |
if (field!=NULL){ \ |
|---|
| 240 |
value=xmlnode_get_tag(field,"value"); \ |
|---|
| 241 |
if (value!=NULL) val=xmlnode_get_data(value); \ |
|---|
| 242 |
} \ |
|---|
| 243 |
if (val!=NULL && val[0]) \ |
|---|
| 244 |
gg_pubdir50_add(change, symbol, from_utf8(val)); |
|---|
| 245 |
|
|---|
| 246 |
int register_process_pubdir_form(Stream *s,const char *from,const char *to, |
|---|
| 247 |
const char *id,User *u,xmlnode form,xmlnode q){ |
|---|
| 248 |
xmlnode field,value; |
|---|
| 249 |
char *val=NULL; |
|---|
| 250 |
Request *r; |
|---|
| 251 |
Session *session=NULL; |
|---|
| 252 |
gg_pubdir50_t change; |
|---|
| 253 |
|
|---|
| 254 |
session=session_get_by_jid(from,s,0); |
|---|
| 255 |
if (session==NULL){ |
|---|
| 256 |
jabber_iq_send_error(s,from,to,id,500,_("Not logged in?")); |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
change=gg_pubdir50_new(GG_PUBDIR50_WRITE); |
|---|
| 260 |
|
|---|
| 261 |
FIELD_TO_PUBDIR("firstname",GG_PUBDIR50_FIRSTNAME); |
|---|
| 262 |
FIELD_TO_PUBDIR("lastname",GG_PUBDIR50_LASTNAME); |
|---|
| 263 |
FIELD_TO_PUBDIR("nick",GG_PUBDIR50_NICKNAME); |
|---|
| 264 |
FIELD_TO_PUBDIR("city",GG_PUBDIR50_CITY); |
|---|
| 265 |
|
|---|
| 266 |
field=xmlnode_get_tag(form,"field?var=gender"); |
|---|
| 267 |
if (field!=NULL){ |
|---|
| 268 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 269 |
if (value!=NULL) val=xmlnode_get_data(value); |
|---|
| 270 |
} |
|---|
| 271 |
if (val!=NULL && val[0] && ( !strcmp(val,GG_PUBDIR50_GENDER_FEMALE) |
|---|
| 272 |
|| !strcmp(val,GG_PUBDIR50_GENDER_FEMALE)) ) |
|---|
| 273 |
gg_pubdir50_add(change, GG_PUBDIR50_GENDER, val); |
|---|
| 274 |
|
|---|
| 275 |
val=NULL; |
|---|
| 276 |
field=xmlnode_get_tag(form,"field?var=birthyear"); |
|---|
| 277 |
if (field!=NULL){ |
|---|
| 278 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 279 |
if (value!=NULL) val=xmlnode_get_data(value); |
|---|
| 280 |
} |
|---|
| 281 |
if (val!=NULL && val[0]){ |
|---|
| 282 |
val=g_strdup_printf("%i",atoi(val)); |
|---|
| 283 |
gg_pubdir50_add(change, GG_PUBDIR50_BIRTHYEAR, val); |
|---|
| 284 |
g_free(val); |
|---|
| 285 |
} |
|---|
| 286 |
FIELD_TO_PUBDIR("familyname",GG_PUBDIR50_FAMILYNAME); |
|---|
| 287 |
FIELD_TO_PUBDIR("familycity",GG_PUBDIR50_FAMILYCITY); |
|---|
| 288 |
|
|---|
| 289 |
r=add_request(RT_CHANGE,from,to,id,q,change,s); |
|---|
| 290 |
gg_pubdir50_free(change); |
|---|
| 291 |
if (!r){ |
|---|
| 292 |
session_remove(session); |
|---|
| 293 |
jabber_iq_send_error(s,from,to,id,500,_("Internal Server Error")); |
|---|
| 294 |
return -1; |
|---|
| 295 |
} |
|---|
| 296 |
return 0; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
int register_process_change_form(Stream *s,const char *from,const char *to, |
|---|
| 301 |
const char *id,User *u,xmlnode form,xmlnode q){ |
|---|
| 302 |
xmlnode field,value; |
|---|
| 303 |
char *action; |
|---|
| 304 |
|
|---|
| 305 |
field=xmlnode_get_tag(form,"field?var=action"); |
|---|
| 306 |
if (field==NULL){ |
|---|
| 307 |
jabber_iq_send_error(s,from,to,id,406,_("No action field present")); |
|---|
| 308 |
return -1; |
|---|
| 309 |
} |
|---|
| 310 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 311 |
if (field==NULL){ |
|---|
| 312 |
jabber_iq_send_error(s,from,to,id,406,_("No action value defined")); |
|---|
| 313 |
return -1; |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|
| 316 |
action=xmlnode_get_data(value); |
|---|
| 317 |
if (action==NULL){ |
|---|
| 318 |
jabber_iq_send_error(s,from,to,id,406,_("No action value defined")); |
|---|
| 319 |
return -1; |
|---|
| 320 |
} |
|---|
| 321 |
else if (!strcmp(action,"options")){ |
|---|
| 322 |
if (register_process_options_form(s,from,to,id,u,form)) |
|---|
| 323 |
return -1; |
|---|
| 324 |
} |
|---|
| 325 |
#if 0 |
|---|
| 326 |
else if (!strcmp(action,"passwd")){ |
|---|
| 327 |
if (register_process_passwd_form(s,from,to,id,u,form)) |
|---|
| 328 |
return -1; |
|---|
| 329 |
} |
|---|
| 330 |
#endif |
|---|
| 331 |
else if (!strcmp(action,"pubdir")){ |
|---|
| 332 |
if (register_process_pubdir_form(s,from,to,id,u,form,q)) |
|---|
| 333 |
return -1; |
|---|
| 334 |
return 0; |
|---|
| 335 |
} |
|---|
| 336 |
else if (!strcmp(action,"unregister")){ |
|---|
| 337 |
if (unregister(s,from,to,id,0)) |
|---|
| 338 |
return -1; |
|---|
| 339 |
return 0; |
|---|
| 340 |
} |
|---|
| 341 |
else{ |
|---|
| 342 |
jabber_iq_send_error(s,from,to,id,406,_("Bad action given")); |
|---|
| 343 |
return -1; |
|---|
| 344 |
} |
|---|
| 345 |
jabber_iq_send_result(s,from,to,id,NULL); |
|---|
| 346 |
return 0; |
|---|
| 347 |
} |
|---|
| 348 |
|
|---|
| 349 |
int register_process_form(Stream *s,const char *from,const char *to, |
|---|
| 350 |
const char *id,xmlnode form,xmlnode q){ |
|---|
| 351 |
xmlnode field,value; |
|---|
| 352 |
char *password,*tmp; |
|---|
| 353 |
unsigned uin; |
|---|
| 354 |
int get_roster=0; |
|---|
| 355 |
User *user; |
|---|
| 356 |
Session *session; |
|---|
| 357 |
|
|---|
| 358 |
field=xmlnode_get_tag(form,"field?var=uin"); |
|---|
| 359 |
if (field==NULL){ |
|---|
| 360 |
jabber_iq_send_error(s,from,to,id,406,_("No uin field present")); |
|---|
| 361 |
return -1; |
|---|
| 362 |
} |
|---|
| 363 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 364 |
if (value==NULL){ |
|---|
| 365 |
jabber_iq_send_error(s,from,to,id,406,_("No uin value defined")); |
|---|
| 366 |
return -1; |
|---|
| 367 |
} |
|---|
| 368 |
tmp=xmlnode_get_data(value); |
|---|
| 369 |
if (tmp==NULL){ |
|---|
| 370 |
jabber_iq_send_error(s,from,to,id,406,_("No uin value defined")); |
|---|
| 371 |
return -1; |
|---|
| 372 |
} |
|---|
| 373 |
uin=(unsigned)atol(tmp); |
|---|
| 374 |
if (uin<=0){ |
|---|
| 375 |
jabber_iq_send_error(s,from,to,id,406,_("Bad uin value defined")); |
|---|
| 376 |
return -1; |
|---|
| 377 |
} |
|---|
| 378 |
|
|---|
| 379 |
field=xmlnode_get_tag(form,"field?var=password"); |
|---|
| 380 |
if (field==NULL){ |
|---|
| 381 |
jabber_iq_send_error(s,from,to,id,406,_("No password field present")); |
|---|
| 382 |
return -1; |
|---|
| 383 |
} |
|---|
| 384 |
value=xmlnode_get_tag(field,"value"); |
|---|
| 385 |
if (value==NULL){ |
|---|
| 386 |
jabber_iq_send_error(s,from,to,id,406,_("No password value defined")); |
|---|
| 387 |
return -1; |
|---|
| 388 |
} |
|---|
| 389 |
password=xmlnode_get_data(value); |
|---|
| 390 |
if (password==NULL){ |
|---|
| 391 |
jabber_iq_send_error(s,from,to,id,406,_("No password value defined")); |
|---|
| 392 |
return -1; |
|---|
| 393 |
} |
|---|
| 394 |
|
|---|
| 395 |
field=xmlnode_get_tag(form,"field?var=userlist"); |
|---|
| 396 |
if (field!=NULL) value=xmlnode_get_tag(field,"value"); |
|---|
| 397 |
else value=NULL; |
|---|
| 398 |
if (value!=NULL){ |
|---|
| 399 |
tmp=xmlnode_get_data(value); |
|---|
| 400 |
if (!strcmp(tmp,"get")) get_roster=1; |
|---|
| 401 |
} |
|---|
| 402 |
|
|---|
| 403 |
user=user_create(from,uin,password); |
|---|
| 404 |
if (!user){ |
|---|
| 405 |
g_warning(N_("Couldn't create user %s"),from); |
|---|
| 406 |
jabber_iq_send_error(s,from,to,id,500,_("Internal Server Error")); |
|---|
| 407 |
return -1; |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
session=session_create(user,from,id,q,s,0); |
|---|
| 411 |
if (!session){ |
|---|
| 412 |
g_warning(N_("Couldn't create session for %s"),from); |
|---|
| 413 |
jabber_iq_send_error(s,from,to,id,500,_("Internal Server Error")); |
|---|
| 414 |
return -1; |
|---|
| 415 |
} |
|---|
| 416 |
|
|---|
| 417 |
presence_send_subscribe(s,NULL,from); |
|---|
| 418 |
|
|---|
| 419 |
if (get_roster) session->get_roster=get_roster; |
|---|
| 420 |
|
|---|
| 421 |
register_process_options_form(s,from,to,id,user,form); |
|---|
| 422 |
return 0; |
|---|
| 423 |
} |
|---|
| 424 |
|
|---|
| 425 |
int change_password_error(struct request_s *r){ |
|---|
| 426 |
|
|---|
| 427 |
g_message(L_("Password change error for user '%s'"),r->from); |
|---|
| 428 |
jabber_iq_send_error(r->stream,r->from,r->to,r->id,500,_("Internal Server Error")); |
|---|
| 429 |
return 0; |
|---|
| 430 |
} |
|---|
| 431 |
|
|---|
| 432 |
int change_password_done(struct request_s *r){ |
|---|
| 433 |
User *u; |
|---|
| 434 |
|
|---|
| 435 |
u=user_get_by_jid(r->from); |
|---|
| 436 |
if (u==NULL){ |
|---|
| 437 |
jabber_iq_send_error(r->stream,r->from,r->to,r->id,500,_("Couldn't find the user.")); |
|---|
| 438 |
return -1; |
|---|
| 439 |
} |
|---|
| 440 |
|
|---|
| 441 |
g_message(L_("Password changed for user '%s'"),r->from); |
|---|
| 442 |
if (r->data){ |
|---|
| 443 |
g_free(u->password); |
|---|
| 444 |
u->password=(char *)r->data; |
|---|
| 445 |
user_save(u); |
|---|
| 446 |
} |
|---|
| 447 |
jabber_iq_send_result(r->stream,r->from,r->to,r->id,NULL); |
|---|
| 448 |
return 0; |
|---|
| 449 |
} |
|---|
| 450 |
|
|---|
| 451 |
void jabber_iq_get_register(Stream *s,const char *from,const char *to,const char *id,xmlnode q){ |
|---|
| 452 |
xmlnode node; |
|---|
| 453 |
xmlnode iq; |
|---|
| 454 |
xmlnode query; |
|---|
| 455 |
xmlnode username; |
|---|
| 456 |
xmlnode instr; |
|---|
| 457 |
User *user; |
|---|
| 458 |
GString *usernamestr; |
|---|
| 459 |
|
|---|
| 460 |
node=xmlnode_get_firstchild(q); |
|---|
| 461 |
if (node){ |
|---|
| 462 |
g_warning("Get for jabber:iq:register not empty!: %s",xmlnode2str(q)); |
|---|
| 463 |
jabber_iq_send_error(s,from,to,id,406,_("Not Acceptable")); |
|---|
| 464 |
return; |
|---|
| 465 |
} |
|---|
| 466 |
|
|---|
| 467 |
user=user_get_by_jid(from); |
|---|
| 468 |
if (user && user->deleted) { |
|---|
| 469 |
jabber_iq_send_error(s,from,to,id,503,_("User still in use, try later.")); |
|---|
| 470 |
return; |
|---|
| 471 |
} |
|---|
| 472 |
|
|---|
| 473 |
iq=xmlnode_new_tag("iq"); |
|---|
| 474 |
xmlnode_put_attrib(iq,"type","result"); |
|---|
| 475 |
if (id) xmlnode_put_attrib(iq,"id",id); |
|---|
| 476 |
xmlnode_put_attrib(iq,"to",from); |
|---|
| 477 |
xmlnode_put_attrib(iq,"from",my_name); |
|---|
| 478 |
query=xmlnode_insert_tag(iq,"query"); |
|---|
| 479 |
xmlnode_put_attrib(query,"xmlns","jabber:iq:register"); |
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
username = xmlnode_insert_tag(query,"username"); |
|---|
| 483 |
xmlnode_insert_tag(query,"password"); |
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
xmlnode_insert_tag(query,"first"); |
|---|
| 491 |
xmlnode_insert_tag(query,"last"); |
|---|
| 492 |
xmlnode_insert_tag(query,"nick"); |
|---|
| 493 |
xmlnode_insert_tag(query,"city"); |
|---|
| 494 |
|
|---|
| 495 |
instr=xmlnode_insert_tag(query,"instructions"); |
|---|
| 496 |
xmlnode_insert_cdata(instr,register_instructions,-1); |
|---|
| 497 |
|
|---|
| 498 |
if (user==NULL) |
|---|
| 499 |
register_form(query,user); |
|---|
| 500 |
else { |
|---|
| 501 |
usernamestr=g_string_new(""); |
|---|
| 502 |
g_string_printf(usernamestr,"%d",user->uin); |
|---|
| 503 |
xmlnode_insert_cdata(username,usernamestr->str,-1); |
|---|
| 504 |
g_string_free(usernamestr,TRUE); |
|---|
| 505 |
xmlnode_insert_tag(query,"registered"); |
|---|
| 506 |
register_change_form(query,user); |
|---|
| 507 |
} |
|---|
| 508 |
|
|---|
| 509 |
stream_write(s,iq); |
|---|
| 510 |
xmlnode_free(iq); |
|---|
| 511 |
} |
|---|
| 512 |
|
|---|
| 513 |
int unregister(Stream *s,const char *from,const char *to,const char *id,int presence_used){ |
|---|
| 514 |
Session *ses; |
|---|
| 515 |
User *u; |
|---|
| 516 |
char *jid; |
|---|
| 517 |
|
|---|
| 518 |
debug(L_("Unregistering '%s'"),from); |
|---|
| 519 |
ses=session_get_by_jid(from,NULL,0); |
|---|
| 520 |
if (ses) |
|---|
| 521 |
if (session_remove(ses)){ |
|---|
| 522 |
g_warning(N_("'%s' unregistration failed"),from); |
|---|
| 523 |
jabber_iq_send_error(s,from,to,id,500,_("Internal Server Error")); |
|---|
| 524 |
return -1; |
|---|
| 525 |
} |
|---|
| 526 |
|
|---|
| 527 |
u=user_get_by_jid(from); |
|---|
| 528 |
if (!u){ |
|---|
| 529 |
g_warning(N_("Tried to unregister '%s' who was never registered"),from); |
|---|
| 530 |
jabber_iq_send_error(s,from,to,id,404,_("Not Found")); |
|---|
| 531 |
return -1; |
|---|
| 532 |
} |
|---|
| 533 |
|
|---|
| 534 |
if (u->contacts){ |
|---|
| 535 |
GList *it; |
|---|
| 536 |
Contact *c; |
|---|
| 537 |
char *ujid; |
|---|
| 538 |
for(it=g_list_first(u->contacts);it;it=it->next){ |
|---|
| 539 |
c=(Contact *)it->data; |
|---|
| 540 |
ujid=jid_build(c->uin); |
|---|
| 541 |
presence_send_unsubscribed(s,ujid,u->jid); |
|---|
| 542 |
presence_send_unsubscribe(s,ujid,u->jid); |
|---|
| 543 |
g_free(ujid); |
|---|
| 544 |
} |
|---|
| 545 |
} |
|---|
| 546 |
|
|---|
| 547 |
jid=g_strdup(u->jid); |
|---|
| 548 |
if (user_delete(u)){ |
|---|
| 549 |
g_warning(N_("'%s' unregistration failed"),from); |
|---|
| 550 |
jabber_iq_send_error(s,from,to,id,500,_("Internal Server Error")); |
|---|
| 551 |
return -1; |
|---|
| 552 |
} |
|---|
| 553 |
|
|---|
| 554 |
if (!presence_used){ |
|---|
| 555 |
jabber_iq_send_result(s,from,to,id,NULL); |
|---|
| 556 |
presence_send_unsubscribe(s,NULL,jid); |
|---|
| 557 |
} |
|---|
| 558 |
presence_send_unsubscribed(s,NULL,jid); |
|---|
| 559 |
g_message(L_("User '%s' unregistered"),from); |
|---|
| 560 |
g_free(jid); |
|---|
| 561 |
return 0; |
|---|
| 562 |
} |
|---|
| 563 |
|
|---|
| 564 |
void jabber_iq_set_register(Stream *s,const char *from,const char *to,const char *id,xmlnode q){ |
|---|
| 565 |
xmlnode node; |
|---|
| 566 |
char *username,*password,*first,*last,*nick,*city,*sex,*born,*ftype; |
|---|
| 567 |
uin_t uin; |
|---|
| 568 |
User *user; |
|---|
| 569 |
Session *session=NULL; |
|---|
| 570 |
gg_pubdir50_t change; |
|---|
| 571 |
Request *r; |
|---|
| 572 |
|
|---|
| 573 |
username=password=first=last=nick=city=sex=born=NULL; |
|---|
| 574 |
|
|---|
| 575 |
user=user_get_by_jid(from); |
|---|
| 576 |
if (user && user->deleted) { |
|---|
| 577 |
jabber_iq_send_error(s,from,to,id,503,_("User still in use, try later.")); |
|---|
| 578 |
return; |
|---|
| 579 |
} |
|---|
| 580 |
|
|---|
| 581 |
node=xmlnode_get_firstchild(q); |
|---|
| 582 |
if (!node){ |
|---|
| 583 |
debug(L_("Set query for jabber:iq:register empty: %s"),xmlnode2str(q)); |
|---|
| 584 |
unregister(s,from,to,id,0); |
|---|
| 585 |
return; |
|---|
| 586 |
} |
|---|
| 587 |
|
|---|
| 588 |
node=xmlnode_get_tag(q,"x?xmlns=jabber:x:data"); |
|---|
| 589 |
if (node){ |
|---|
| 590 |
ftype=xmlnode_get_attrib(node,"type"); |
|---|
| 591 |
if (ftype==NULL){ |
|---|
| 592 |
jabber_iq_send_error(s,from,to,id,406,_("Form returned with no type defined")); |
|---|
| 593 |
} |
|---|
| 594 |
else if (!strcmp(ftype,"submit")){ |
|---|
| 595 |
if (user!=NULL) |
|---|
| 596 |
register_process_change_form(s,from,to,id,user,node,q); |
|---|
| 597 |
else |
|---|
| 598 |
register_process_form(s,from,to,id,node,q); |
|---|
| 599 |
} |
|---|
| 600 |
else if (!strcmp(ftype,"cancel")){ |
|---|
| 601 |
jabber_iq_send_error(s,from,to,id,406,_("Cancelled")); |
|---|
| 602 |
} |
|---|
| 603 |
else jabber_iq_send_error(s,from,to,id,406,_("Bad form type")); |
|---|
| 604 |
return; |
|---|
| 605 |
} |
|---|
| 606 |
|
|---|
| 607 |
node=xmlnode_get_tag(q,"remove"); |
|---|
| 608 |
if (node){ |
|---|
| 609 |
debug(L_("<remove/> in jabber:iq:register set: %s"),xmlnode2str(q)); |
|---|
| 610 |
unregister(s,from,to,id,0); |
|---|
| 611 |
return; |
|---|
| 612 |
} |
|---|
| 613 |
|
|---|
| 614 |
node=xmlnode_get_tag(q,"username"); |
|---|
| 615 |
if (node) username=xmlnode_get_data(node); |
|---|
| 616 |
if (!node || !username) uin=0; |
|---|
| 617 |
else uin=atoi(username); |
|---|
| 618 |
|
|---|
| 619 |
node=xmlnode_get_tag(q,"password"); |
|---|
| 620 |
if (node) password=xmlnode_get_data(node); |
|---|
| 621 |
|
|---|
| 622 |
if (!user && (!uin || !password)){ |
|---|
| 623 |
g_warning(N_("User '%s' doesn't exist and not enough info to add him"),from); |
|---|
| 624 |
jabber_iq_send_error(s,from,to,id,406,_("Not Acceptable")); |
|---|
| 625 |
return; |
|---|
| 626 |
} |
|---|
| 627 |
|
|---|
| 628 |
if (!user){ |
|---|
| 629 |
user=user_create(from,uin,password); |
|---|
| 630 |
if (!user){ |
|---|
| 631 |
g_warning(N_("Couldn't create user %s"),from); |
|---|
| 632 |
jabber_iq_send_error(s,from,to,id,500,_("Internal Server Error")); |
|---|
| 633 |
return; |
|---|
| 634 |
} |
|---|
| 635 |
|
|---|
| 636 |
session=session_create(user,from,id,q,s,0); |
|---|
| 637 |
if (!session){ |
|---|
| 638 |
g_warning(N_("Couldn't create session for %s"),from); |
|---|
| 639 |
jabber_iq_send_error(s,from,to,id,500,_("Internal Server Error")); |
|---|
| 640 |
return; |
|---|
| 641 |
} |
|---|
| 642 |
} |
|---|
| 643 |
else session=session_get_by_jid(from,s,0); |
|---|
| 644 |
|
|---|
| 645 |
node=xmlnode_get_tag(q,"first"); |
|---|
| 646 |
if (node) first=xmlnode_get_data(node); |
|---|
| 647 |
|
|---|
| 648 |
node=xmlnode_get_tag(q,"last"); |
|---|
| 649 |
if (node) last=xmlnode_get_data(node); |
|---|
| 650 |
|
|---|
| 651 |
node=xmlnode_get_tag(q,"nick"); |
|---|
| 652 |
if (node) nick=xmlnode_get_data(node); |
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
node=xmlnode_get_tag(q,"city"); |
|---|
| 658 |
if (node) city=xmlnode_get_data(node); |
|---|
| 659 |
|
|---|
| 660 |
if (!first && !last && !nick && !city && !born && !sex){ |
|---|
| 661 |
if (!uin && !password){ |
|---|
| 662 |
debug(L_("Set query for jabber:iq:register empty: %s"),xmlnode2str(q)); |
|---|
| 663 |
unregister(s,from,to,id,0); |
|---|
| 664 |
return; |
|---|
| 665 |
} |
|---|
| 666 |
if (!uin || !password){ |
|---|
| 667 |
g_warning(N_("Nothing to change")); |
|---|
| 668 |
session_remove(session); |
|---|
| 669 |
jabber_iq_send_error(s,from,to,id,406,_("Not Acceptable")); |
|---|
| 670 |
return; |
|---|
| 671 |
} |
|---|
| 672 |
presence_send_subscribe(s,NULL,from); |
|---|
| 673 |
return; |
|---|
| 674 |
} |
|---|
| 675 |
|
|---|
| 676 |
if (!user && (!password ||!uin)){ |
|---|
| 677 |
g_warning(N_("Not registered, and no password given for public directory change.")); |
|---|
| 678 |
session_remove(session); |
|---|
| 679 |
jabber_iq_send_error(s,from,to,id,406,_("Not Acceptable")); |
|---|
| 680 |
return; |
|---|
| 681 |
} |
|---|
| 682 |
if (!password) password=user->password; |
|---|
| 683 |
if (!uin) uin=user->uin; |
|---|
| 684 |
|
|---|
| 685 |
change=gg_pubdir50_new(GG_PUBDIR50_WRITE); |
|---|
| 686 |
if (first) gg_pubdir50_add(change, GG_PUBDIR50_FIRSTNAME, from_utf8(first)); |
|---|
| 687 |
if (last) gg_pubdir50_add(change, GG_PUBDIR50_LASTNAME, from_utf8(last)); |
|---|
| 688 |
if (nick) gg_pubdir50_add(change, GG_PUBDIR50_NICKNAME, from_utf8(nick)); |
|---|
| 689 |
if (city) gg_pubdir50_add(change, GG_PUBDIR50_CITY, from_utf8(city)); |
|---|
| 690 |
if (sex && (sex[0]=='k' || sex[0]=='f' || sex[0]=='K' || sex[0]=='F')) |
|---|
| 691 |
gg_pubdir50_add(change, GG_PUBDIR50_GENDER, |
|---|
| 692 |
GG_PUBDIR50_GENDER_FEMALE); |
|---|
| 693 |
else if (sex!=NULL && sex[0]!='\000') |
|---|
| 694 |
gg_pubdir50_add(change, GG_PUBDIR50_GENDER, |
|---|
| 695 |
GG_PUBDIR50_GENDER_MALE); |
|---|
| 696 |
if (born){ |
|---|
| 697 |
born=g_strdup_printf("%i",atoi(born)); |
|---|
| 698 |
gg_pubdir50_add(change, GG_PUBDIR50_BIRTHYEAR, born); |
|---|
| 699 |
g_free(born); |
|---|
| 700 |
} |
|---|
| 701 |
|
|---|
| 702 |
if (session->connected){ |
|---|
| 703 |
r=add_request(RT_CHANGE,from,to,id,NULL,change,s); |
|---|
| 704 |
gg_pubdir50_free(change); |
|---|
| 705 |
} |
|---|
| 706 |
else{ |
|---|
| 707 |
session->pubdir_change=change; |
|---|
| 708 |
} |
|---|
| 709 |
} |
|---|
| 710 |
|
|---|
| 711 |
int register_error(Request *r){ |
|---|
| 712 |
|
|---|
| 713 |
jabber_iq_send_error(r->stream,r->from,r->to,r->id,502,_("Remote Server Error")); |
|---|
| 714 |
return 0; |
|---|
| 715 |
} |
|---|
| 716 |
|
|---|
| 717 |
int register_done(struct request_s *r){ |
|---|
| 718 |
|
|---|
| 719 |
jabber_iq_send_result(r->stream,r->from,r->to,r->id,NULL); |
|---|
| 720 |
return 0; |
|---|
| 721 |
} |
|---|
| 722 |
|
|---|
| 723 |
|
|---|