Back to index

openldap  2.4.31
Functions
fetch.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/socket.h>
#include <ac/time.h>
#include "lber_pvt.h"
#include "ldap_pvt.h"
#include "ldap_config.h"
#include "ldif.h"

Go to the source code of this file.

Functions

FILE * ldif_open_url (LDAP_CONST char *urlstr)
int ldif_fetch_url (LDAP_CONST char *urlstr, char **valuep, ber_len_t *vlenp)

Function Documentation

int ldif_fetch_url ( LDAP_CONST char *  urlstr,
char **  valuep,
ber_len_t vlenp 
)

Definition at line 83 of file fetch.c.

{
       FILE *url;
       char buffer[1024];
       char *p = NULL;
       size_t total;
       size_t bytes;

       *valuep = NULL;
       *vlenp = 0;

       url = ldif_open_url( urlstr );

       if( url == NULL ) {
              return -1;
       }

       total = 0;

       while( (bytes = fread( buffer, 1, sizeof(buffer), url )) != 0 ) {
              char *newp = ber_memrealloc( p, total + bytes + 1 );
              if( newp == NULL ) {
                     ber_memfree( p );
                     fclose( url );
                     return -1;
              }
              p = newp;
              AC_MEMCPY( &p[total], buffer, bytes );
              total += bytes;
       }

       fclose( url );

       if( total == 0 ) {
              char *newp = ber_memrealloc( p, 1 );
              if( newp == NULL ) {
                     ber_memfree( p );
                     return -1;
              }
              p = newp;
       }

       p[total] = '\0';
       *valuep = p;
       *vlenp = total;

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

FILE* ldif_open_url ( LDAP_CONST char *  urlstr)

Definition at line 41 of file fetch.c.

{
       FILE *url;

       if( strncasecmp( "file:", urlstr, sizeof("file:")-1 ) == 0 ) {
              char *p;
              urlstr += sizeof("file:")-1;

              /* we don't check for LDAP_DIRSEP since URLs should contain '/' */
              if ( urlstr[0] == '/' && urlstr[1] == '/' ) {
                     urlstr += 2;
                     /* path must be absolute if authority is present */
                     if ( urlstr[0] != '/' )
                            return NULL;
              }

              p = ber_strdup( urlstr );

              /* But we should convert to LDAP_DIRSEP before use */
              if ( LDAP_DIRSEP[0] != '/' ) {
                     char *s = p;
                     while (( s = strchr( s, '/' )))
                            *s++ = LDAP_DIRSEP[0];
              }

              ldap_pvt_hex_unescape( p );

              url = fopen( p, "rb" );

              ber_memfree( p );
       } else {
#ifdef HAVE_FETCH
              url = fetchGetURL( (char*) urlstr, "" );
#else
              url = NULL;
#endif
       }
       return url;
}

Here is the call graph for this function:

Here is the caller graph for this function: