Ejemplo n.º 1
0
my_bool
my_parse_charset_xml(MY_CHARSET_LOADER *loader, const char *buf, size_t len)
{
  MY_XML_PARSER p;
  struct my_cs_file_info info;
  my_bool rc;
  
  my_charset_file_init(&info);
  my_xml_parser_create(&p);
  my_xml_set_enter_handler(&p,cs_enter);
  my_xml_set_value_handler(&p,cs_value);
  my_xml_set_leave_handler(&p,cs_leave);
  info.loader= loader;
  my_xml_set_user_data(&p, (void *) &info);
  rc= (my_xml_parse(&p,buf,len) == MY_XML_OK) ? FALSE : TRUE;
  my_xml_parser_free(&p);
  my_charset_file_free(&info);
  if (rc != MY_XML_OK)
  {
    const char *errstr= my_xml_error_string(&p);
    if (sizeof(loader->error) > 32 + strlen(errstr))
    {
      /* We cannot use my_snprintf() here. See previous comment. */
      sprintf(loader->error, "at line %d pos %d: %s",
                my_xml_error_lineno(&p)+1,
                (int) my_xml_error_pos(&p),
                my_xml_error_string(&p));
    }
  }
  return rc;
}
Ejemplo n.º 2
0
static int my_read_charset_file(const char *filename)
{
  char buf[MAX_BUF];
  int  fd;
  uint len;
  
  if ((fd=open(filename,O_RDONLY)) < 0)
  {
    fprintf(stderr,"Can't open '%s'\n",filename);
    return 1;
  }
  
  len=read(fd,buf,MAX_BUF);
  DBUG_ASSERT(len < MAX_BUF);
  close(fd);
  
  if (my_parse_charset_xml(buf,len,add_collation))
  {
#if 0
    printf("ERROR at line %d pos %d '%s'\n",
	   my_xml_error_lineno(&p)+1,
	   my_xml_error_pos(&p),
	   my_xml_error_string(&p));
#endif
  }
  
  return FALSE;
}
Ejemplo n.º 3
0
int main(int ac, char **av)
{
  char str[1024*64]="";
  const char *fn;
  int  f;
  uint len;
  MY_XML_PARSER p;
  
  if (ac<2)
  {
    usage(av[0]);
    return 0;
  }
  
  fn=av[1]?av[1]:"test.xml";
  if ((f=open(fn,O_RDONLY))<0)
  {
    fprintf(stderr,"Err '%s'\n",fn);
    return 1;
  }
  
  len=read(f,str,sizeof(str)-1);
  str[len]='\0';
  
  my_xml_parser_create(&p);
  
  my_xml_set_enter_handler(&p,bstr);
  my_xml_set_value_handler(&p,dstr);
  my_xml_set_leave_handler(&p,estr);
  
  if (MY_XML_OK!=(f=my_xml_parse(&p,str,len)))
  {
    printf("ERROR at line %d pos %d '%s'\n",
      my_xml_error_lineno(&p)+1,
      my_xml_error_pos(&p),
      my_xml_error_string(&p));
  }
  
  my_xml_parser_free(&p);
  
  return 0;
}
Ejemplo n.º 4
0
static my_bool my_read_charset_file(const char *filename, myf myflags)
{
  uchar *buf;
  int  fd;
  size_t len, tmp_len;
  MY_STAT stat_info;

  if (!my_stat(filename, &stat_info, MYF(myflags)) ||
       ((len= (uint)stat_info.st_size) > MY_MAX_ALLOWED_BUF) ||
       !(buf= (uchar*) my_malloc(len,myflags)))
    return TRUE;

  if ((fd= mysql_file_open(key_file_charset, filename, O_RDONLY, myflags)) < 0)
    goto error;
  tmp_len= mysql_file_read(fd, buf, len, myflags);
  mysql_file_close(fd, myflags);
  if (tmp_len != len)
    goto error;

  if (my_parse_charset_xml((char*) buf,len,add_collation))
  {
#ifdef NOT_YET
    printf("ERROR at line %d pos %d '%s'\n",
	   my_xml_error_lineno(&p)+1,
	   my_xml_error_pos(&p),
	   my_xml_error_string(&p));
#endif
  }

  my_free(buf);
  return FALSE;

error:
  my_free(buf);
  return TRUE;
}