Logo Search packages:      
Sourcecode: freetds version File versions

TDSCONNECTINFO* tds_alloc_connect ( TDSLOCALE *  locale  ) 

Allocate space for configure structure and initialize with default values

Parameters:
locale locale information (copied to configuration information)
Returns:
allocated structure or NULL if out of memory

Definition at line 495 of file mem.c.

References tds_alloc_connect().

Referenced by tds_alloc_connect(), and tds_read_config_info().

{
TDSCONNECTINFO *connect_info;
char hostname[30];
      
      TEST_MALLOC(connect_info,TDSCONNECTINFO);
      memset(connect_info, '\0', sizeof(TDSCONNECTINFO));
      tds_dstr_init(&connect_info->server_name);
      tds_dstr_init(&connect_info->language);
      tds_dstr_init(&connect_info->char_set);
      tds_dstr_init(&connect_info->host_name);
      tds_dstr_init(&connect_info->app_name);
      tds_dstr_init(&connect_info->user_name);
      tds_dstr_init(&connect_info->password);
      tds_dstr_init(&connect_info->library);
      tds_dstr_init(&connect_info->ip_addr);
      tds_dstr_init(&connect_info->database);
      tds_dstr_init(&connect_info->dump_file);
      tds_dstr_init(&connect_info->default_domain);
      tds_dstr_init(&connect_info->client_charset);

      /* fill in all hardcoded defaults */
      if (!tds_dstr_copy(&connect_info->server_name,TDS_DEF_SERVER))
            goto Cleanup;
      connect_info->major_version = TDS_DEF_MAJOR;
      connect_info->minor_version = TDS_DEF_MINOR;
      connect_info->port = TDS_DEF_PORT;
      connect_info->block_size = TDS_DEF_BLKSZ;
      if (locale) {
            if (locale->language) 
                  if (!tds_dstr_copy(&connect_info->language,locale->language))
                        goto Cleanup;
            if (locale->char_set) 
                  if (!tds_dstr_copy(&connect_info->char_set,locale->char_set))
                        goto Cleanup;
      }
      if (tds_dstr_isempty(&connect_info->language)) {
            if (!tds_dstr_copy(&connect_info->language,TDS_DEF_LANG))
                  goto Cleanup;
      }
      if (tds_dstr_isempty(&connect_info->char_set)) {
            if (!tds_dstr_copy(&connect_info->char_set,TDS_DEF_CHARSET))
                  goto Cleanup;
      }
      connect_info->try_server_login = 1;
      memset(hostname,'\0', sizeof(hostname));
      gethostname(hostname, sizeof(hostname));
      hostname[sizeof(hostname)-1]='\0'; /* make sure it's truncated */
      if (!tds_dstr_copy(&connect_info->host_name,hostname))
            goto Cleanup;
      
      memcpy(connect_info->capabilities,defaultcaps,TDS_MAX_CAPABILITY);
      return connect_info;
Cleanup:
      tds_free_connect(connect_info);
      return NULL;
}


Generated by  Doxygen 1.6.0   Back to index