ava.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* ava.c - routines for dealing with attribute value assertions */
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <sys/types.h>
  16. #include <sys/socket.h>
  17. #include "slap.h"
  18. int
  19. get_ava(
  20. BerElement *ber,
  21. struct ava *ava
  22. )
  23. {
  24. char *type = NULL;
  25. if ( ber_scanf( ber, "{ao}", &type, &ava->ava_value )
  26. == LBER_ERROR ) {
  27. slapi_ch_free_string( &type );
  28. ava_done(ava);
  29. LDAPDebug( LDAP_DEBUG_ANY, " get_ava ber_scanf\n", 0, 0, 0 );
  30. return( LDAP_PROTOCOL_ERROR );
  31. }
  32. ava->ava_type = slapi_attr_syntax_normalize(type);
  33. slapi_ch_free_string( &type );
  34. ava->ava_private = NULL;
  35. return( 0 );
  36. }
  37. void
  38. ava_done(
  39. struct ava *ava
  40. )
  41. {
  42. slapi_ch_free( (void**)&(ava->ava_type) );
  43. slapi_ch_free( (void**)&(ava->ava_value.bv_val) );
  44. }
  45. int
  46. rdn2ava(
  47. char *rdn,
  48. struct ava *ava
  49. )
  50. {
  51. char *s;
  52. if ( (s = strchr( rdn, '=' )) == NULL ) {
  53. return( -1 );
  54. }
  55. *s++ = '\0';
  56. ava->ava_type = rdn;
  57. strcpy_unescape_value( s, s );
  58. ava->ava_value.bv_val = s;
  59. ava->ava_value.bv_len = strlen( s );
  60. ava->ava_private = NULL;
  61. return( 0 );
  62. }