comparison mcabber/libjabber/jutil.c @ 594:f791f5f0cfce

libjabber: remove some useless/deprecated functions
author Mikael Berthe <mikael@lilotux.net>
date Tue, 13 Dec 2005 18:33:04 +0100
parents c3ae9251c197
children
comparison
equal deleted inserted replaced
593:29d9a54ac69f 594:f791f5f0cfce
392 392
393 jutil_tofrom(x); 393 jutil_tofrom(x);
394 } 394 }
395 395
396 /** 396 /**
397 * wrapper around jutil_error_xmpp for compatibility with modules for jabberd up to version 1.4.3
398 *
399 * @deprecated use jutil_error_xmpp instead!
400 *
401 * @param x the xmlnode that should become an stanza error message
402 * @param E the strucutre that holds the error information
403 */
404 void jutil_error(xmlnode x, terror E)
405 {
406 xterror xE;
407 jutil_error_map(E, &xE);
408 jutil_error_xmpp(x, xE);
409 }
410
411 /**
412 * add a delayed delivery (JEP-0091) element to a message using the 397 * add a delayed delivery (JEP-0091) element to a message using the
413 * present timestamp. 398 * present timestamp.
414 * If a reason is given, this reason will be added as CDATA to the 399 * If a reason is given, this reason will be added as CDATA to the
415 * inserted element 400 * inserted element
416 * 401 *
426 xmlnode_put_attrib(delay,"from",xmlnode_get_attrib(msg,"to")); 411 xmlnode_put_attrib(delay,"from",xmlnode_get_attrib(msg,"to"));
427 xmlnode_put_attrib(delay,"stamp",jutil_timestamp()); 412 xmlnode_put_attrib(delay,"stamp",jutil_timestamp());
428 if(reason != NULL) 413 if(reason != NULL)
429 xmlnode_insert_cdata(delay,reason,strlen(reason)); 414 xmlnode_insert_cdata(delay,reason,strlen(reason));
430 } 415 }
431
432 #define KEYBUF 100
433
434 /**
435 * create or validate a key value for stone-age jabber protocols
436 *
437 * Before dialback had been introduced for s2s (and therefore only in jabberd 1.0),
438 * Jabber used these keys to protect some iq requests. A client first had to
439 * request a key with a IQ get and use it inside the IQ set request. By being able
440 * to receive the key in the IQ get response, the client (more or less) proved to be
441 * who he claimed to be.
442 *
443 * The implementation of this function uses a static array with KEYBUF entries (default
444 * value of KEYBUF is 100). Therefore a key gets invalid at the 100th key that is created
445 * afterwards. It is also invalidated after it has been validated once.
446 *
447 * @deprecated This function is not really used anymore. jabberd14 does not check any
448 * keys anymore and only creates them in the jsm's mod_register.c for compatibility. This
449 * function is also used in mod_groups.c and the key is even checked there, but I do not
450 * know if mod_groups.c still works at all.
451 *
452 * @param key for validation the key the client sent, for generation of a new key NULL
453 * @param seed the seed for generating the key, must stay the same for the same user
454 * @return the new key when created, the key if the key has been validated, NULL if the key is invalid
455 */
456 char *jutil_regkey(char *key, char *seed)
457 {
458 static char keydb[KEYBUF][41];
459 static char seeddb[KEYBUF][41];
460 static int last = -1;
461 char *str, strint[32];
462 int i;
463
464 /* blanket the keydb first time */
465 if(last == -1)
466 {
467 last = 0;
468 memset(&keydb,0,KEYBUF*41);
469 memset(&seeddb,0,KEYBUF*41);
470 srand(time(NULL));
471 }
472
473 /* creation phase */
474 if(key == NULL && seed != NULL)
475 {
476 /* create a random key hash and store it */
477 sprintf(strint,"%d",rand());
478 strcpy(keydb[last],shahash(strint));
479
480 /* store a hash for the seed associated w/ this key */
481 strcpy(seeddb[last],shahash(seed));
482
483 /* return it all */
484 str = keydb[last];
485 last++;
486 if(last == KEYBUF) last = 0;
487 return str;
488 }
489
490 /* validation phase */
491 str = shahash(seed);
492 for(i=0;i<KEYBUF;i++)
493 if(j_strcmp(keydb[i],key) == 0 && j_strcmp(seeddb[i],str) == 0)
494 {
495 seeddb[i][0] = '\0'; /* invalidate this key */
496 return keydb[i];
497 }
498
499 return NULL;
500 }
501