Beispiel #1
0
message_t *				/* O - Pointer to message data */
add_message(const char *m)		/* I - Message text */
{
  message_t	*temp;			/* Pointer to message data */


  if ((temp = find_message(m)) != NULL)
    return (temp);

  temp = messages + num_messages;
  num_messages ++;

  memset(temp, 0, sizeof(message_t));

  temp->id = strdup(m);

  if (num_messages > 1)
  {
    qsort(messages, num_messages, sizeof(message_t), compare_messages);
    return (find_message(m));
  }
  else
    return (temp);
}
Beispiel #2
0
static int parse_input_file(const char *file_name, struct errors **top_error,
                            struct languages **top_lang)
{
    FILE *file;
    char *str, buff[1000];
    struct errors *current_error= 0, **tail_error= top_error;
    struct message current_message;
    int rcount= 0; /* Number of error codes in current section. */
    int ecount= 0; /* Number of error codes in total. */
    DBUG_ENTER("parse_input_file");

    *top_error= 0;
    *top_lang= 0;
    if (!(file= my_fopen(file_name, O_RDONLY | O_SHARE, MYF(MY_WME))))
        DBUG_RETURN(0);

    while ((str= fgets(buff, sizeof(buff), file)))
    {
        if (is_prefix(str, "language"))
        {
            if (!(*top_lang= parse_charset_string(str)))
            {
                fprintf(stderr, "Failed to parse the charset string!\n");
                DBUG_RETURN(0);
            }
            continue;
        }
        if (is_prefix(str, "start-error-number"))
        {
            if (!(er_offset= parse_error_offset(str)))
            {
                fprintf(stderr, "Failed to parse the error offset string!\n");
                DBUG_RETURN(0);
            }
            rcount= 0; /* Reset count if a fixed number is set. */
            continue;
        }
        if (is_prefix(str, "default-language"))
        {
            if (!(default_language= parse_default_language(str)))
            {
                DBUG_PRINT("info", ("default_slang: %s", default_language));
                fprintf(stderr,
                        "Failed to parse the default language line. Aborting\n");
                DBUG_RETURN(0);
            }
            continue;
        }

        if (*str == '\t' || *str == ' ')
        {
            /* New error message in another language for previous error */
            if (!current_error)
            {
                fprintf(stderr, "Error in the input file format\n");
                DBUG_RETURN(0);
            }
            if (!parse_message_string(&current_message, str))
            {
                fprintf(stderr, "Failed to parse message string for error '%s'",
                        current_error->er_name);
                DBUG_RETURN(0);
            }
            if (find_message(current_error, current_message.lang_short_name, TRUE))
            {
                fprintf(stderr, "Duplicate message string for error '%s'"
                        " in language '%s'\n",
                        current_error->er_name, current_message.lang_short_name);
                DBUG_RETURN(0);
            }
            if (check_message_format(current_error, current_message.text))
            {
                fprintf(stderr, "Wrong formatspecifier of error message string"
                        " for error '%s' in language '%s'\n",
                        current_error->er_name, current_message.lang_short_name);
                DBUG_RETURN(0);
            }
            if (insert_dynamic(&current_error->msg, &current_message))
                DBUG_RETURN(0);
            continue;
        }
        if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX))
        {
            if (!(current_error= parse_error_string(str, rcount)))
            {
                fprintf(stderr, "Failed to parse the error name string\n");
                DBUG_RETURN(0);
            }
            rcount++;
            ecount++;                         /* Count number of unique errors */

            /* add error to the list */
            *tail_error= current_error;
            tail_error= &current_error->next_error;
            continue;
        }
        if (*str == '#' || *str == '\n')
            continue;					/* skip comment or empty lines */

        fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str);
        DBUG_RETURN(0);
    }
    *tail_error= 0;				/* Mark end of list */

    my_fclose(file, MYF(0));
    DBUG_RETURN(ecount);
}
Beispiel #3
0
static int create_sys_files(struct languages *lang_head,
                            struct errors *error_head, uint row_count)
{
    FILE *to;
    uint csnum= 0, length, i, row_nr;
    uchar head[32];
    char outfile[FN_REFLEN], *outfile_end;
    long start_pos;
    struct message *tmp;
    struct languages *tmp_lang;
    struct errors *tmp_error;

    MY_STAT stat_info;
    DBUG_ENTER("create_sys_files");

    /*
       going over all languages and assembling corresponding error messages
    */
    for (tmp_lang= lang_head; tmp_lang; tmp_lang= tmp_lang->next_lang)
    {

        /* setting charset name */
        if (!(csnum= get_charset_number(tmp_lang->charset, MY_CS_PRIMARY)))
        {
            fprintf(stderr, "Unknown charset '%s' in '%s'\n", tmp_lang->charset,
                    TXTFILE);
            DBUG_RETURN(1);
        }

        outfile_end= strxmov(outfile, DATADIRECTORY,
                             tmp_lang->lang_long_name, NullS);
        if (!my_stat(outfile, &stat_info,MYF(0)))
        {
            if (my_mkdir(outfile, 0777,MYF(0)) < 0)
            {
                fprintf(stderr, "Can't create output directory for %s\n",
                        outfile);
                DBUG_RETURN(1);
            }
        }

        strxmov(outfile_end, FN_ROOTDIR, OUTFILE, NullS);

        if (!(to= my_fopen(outfile, O_WRONLY | FILE_BINARY, MYF(MY_WME))))
            DBUG_RETURN(1);

        /* 4 is for 4 bytes to store row position / error message */
        start_pos= (long) (HEADER_LENGTH + row_count * 4);
        fseek(to, start_pos, 0);
        row_nr= 0;
        for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
        {
            /* dealing with messages */
            tmp= find_message(tmp_error, tmp_lang->lang_short_name, FALSE);

            if (!tmp)
            {
                fprintf(stderr,
                        "Did not find message for %s neither in %s nor in default "
                        "language\n", tmp_error->er_name, tmp_lang->lang_short_name);
                goto err;
            }
            if (copy_rows(to, tmp->text, row_nr, start_pos))
            {
                fprintf(stderr, "Failed to copy rows to %s\n", outfile);
                goto err;
            }
            row_nr++;
        }

        /* continue with header of the errmsg.sys file */
        length= ftell(to) - HEADER_LENGTH - row_count * 4;
        memset(head, 0, HEADER_LENGTH);
        memmove(head, file_head, 4);
        head[4]= 1;
        int4store(head + 6, length);
        int4store(head + 10, row_count);
        head[30]= csnum;

        my_fseek(to, 0l, MY_SEEK_SET, MYF(0));
        if (my_fwrite(to, (uchar*) head, HEADER_LENGTH, MYF(MY_WME | MY_FNABP)))
            goto err;

        for (i= 0; i < row_count; i++)
        {
            int4store(head, file_pos[i]);
            if (my_fwrite(to, (uchar*) head, 4, MYF(MY_WME | MY_FNABP)))
                goto err;
        }
        my_fclose(to, MYF(0));
    }
    DBUG_RETURN(0);

err:
    my_fclose(to, MYF(0));
    DBUG_RETURN(1);
}
Beispiel #4
0
static int create_header_files(struct errors *error_head)
{
    FILE *er_definef, *sql_statef, *er_namef;
    struct errors *tmp_error;
    struct message *er_msg;
    const char *er_text;

    DBUG_ENTER("create_header_files");

    if (!(er_definef= my_fopen(HEADERFILE, O_WRONLY, MYF(MY_WME))))
    {
        DBUG_RETURN(1);
    }
    if (!(sql_statef= my_fopen(STATEFILE, O_WRONLY, MYF(MY_WME))))
    {
        my_fclose(er_definef, MYF(0));
        DBUG_RETURN(1);
    }
    if (!(er_namef= my_fopen(NAMEFILE, O_WRONLY, MYF(MY_WME))))
    {
        my_fclose(er_definef, MYF(0));
        my_fclose(sql_statef, MYF(0));
        DBUG_RETURN(1);
    }

    fprintf(er_definef, "/* Autogenerated file, please don't edit */\n\n");
    fprintf(sql_statef, "/* Autogenerated file, please don't edit */\n\n");
    fprintf(er_namef, "/* Autogenerated file, please don't edit */\n\n");

    fprintf(er_definef, "#ifndef MYSQLD_ERROR_INCLUDED\n");
    fprintf(er_definef, "#define MYSQLD_ERROR_INCLUDED\n\n");

    /*
      Find out how many sections of error messages we have, what the first
      number in each section is and the number of messages in each section.
    */
    {
        int error_code= error_head->d_code;
        int section_size[100]; /* Assume that 100 sections is enough. */
        int current_section= 0;
        int section_nr;
        section_size[0]= 0;
        fprintf(er_definef,
                "static const int errmsg_section_start[] = { %d", error_code);
        for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
        {
            if (tmp_error->d_code != error_code) /* Starting new section? */
            {
                fprintf(er_definef, ", %d", tmp_error->d_code);
                error_code= tmp_error->d_code;
                section_size[++current_section]= 0;
            }
            error_code++;
            section_size[current_section]++;
        }
        fprintf(er_definef, " };\n");

        fprintf(er_definef,
                "static const int errmsg_section_size[] = { %d", section_size[0]);
        for (section_nr= 1; section_nr <= current_section; section_nr++)
            fprintf(er_definef, ", %d", section_size[section_nr]);
        fprintf(er_definef, " };\n\n");
    }

    for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
    {
        /*
           generating mysqld_error.h
           fprintf() will automatically add \r on windows
        */
        fprintf(er_definef, "#define %s %d\n", tmp_error->er_name,
                tmp_error->d_code);

        /* generating sql_state.h file */
        if (tmp_error->sql_code1[0] || tmp_error->sql_code2[0])
            fprintf(sql_statef,
                    "{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name,
                    tmp_error->sql_code1, tmp_error->sql_code2);
        /*generating er_name file */
        er_msg= find_message(tmp_error, default_language, 0);
        er_text = (er_msg ? er_msg->text : "");
        fprintf(er_namef, "{ \"%s\", %d, \"", tmp_error->er_name,
                tmp_error->d_code);
        print_escaped_string(er_namef, er_text);
        fprintf(er_namef, "\" },\n");
    }
    /* finishing off with mysqld_error.h */
    fprintf(er_definef, "#endif\n");
    my_fclose(er_definef, MYF(0));
    my_fclose(sql_statef, MYF(0));
    my_fclose(er_namef, MYF(0));
    DBUG_RETURN(0);
}
Beispiel #5
0
static int create_header_files(struct errors *error_head)
{
  uint er_last= 0;
  FILE *er_definef, *sql_statef, *er_namef;
  struct errors *tmp_error;
  struct message *er_msg;
  const char *er_text;

  DBUG_ENTER("create_header_files");

  if (!(er_definef= my_fopen(HEADERFILE, O_WRONLY, MYF(MY_WME))))
  {
    DBUG_RETURN(1);
  }
  if (!(sql_statef= my_fopen(STATEFILE, O_WRONLY, MYF(MY_WME))))
  {
    my_fclose(er_definef, MYF(0));
    DBUG_RETURN(1);
  }
  if (!(er_namef= my_fopen(NAMEFILE, O_WRONLY, MYF(MY_WME))))
  {
    my_fclose(er_definef, MYF(0));
    my_fclose(sql_statef, MYF(0));
    DBUG_RETURN(1);
  }

  fprintf(er_definef, "/* Autogenerated file, please don't edit */\n\n");
  fprintf(sql_statef, "/* Autogenerated file, please don't edit */\n\n");
  fprintf(er_namef, "/* Autogenerated file, please don't edit */\n\n");

  fprintf(er_definef, "#define ER_ERROR_FIRST %d\n", error_head->d_code);

  for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
  {
    /*
       generating mysqld_error.h
       fprintf() will automatically add \r on windows
    */
    fprintf(er_definef, "#define %s %d\n", tmp_error->er_name,
	    tmp_error->d_code);
    er_last= tmp_error->d_code;

    /* generating sql_state.h file */
    if (tmp_error->sql_code1[0] || tmp_error->sql_code2[0])
      fprintf(sql_statef,
	      "{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name,
	      tmp_error->sql_code1, tmp_error->sql_code2);
    /*generating er_name file */
    er_msg= find_message(tmp_error, default_language, 0);
    er_text = (er_msg ? er_msg->text : "");
    fprintf(er_namef, "{ \"%s\", %d, \"", tmp_error->er_name,
            tmp_error->d_code);
    print_escaped_string(er_namef, er_text);
    fprintf(er_namef, "\" },\n");
  }
  /* finishing off with mysqld_error.h */
  fprintf(er_definef, "#define ER_ERROR_LAST %d\n", er_last);
  my_fclose(er_definef, MYF(0));
  my_fclose(sql_statef, MYF(0));
  my_fclose(er_namef, MYF(0));
  DBUG_RETURN(0);
}
Beispiel #6
0
void process()
{
    int retVal = 0;
    Message *current = NULL;
    char source[64];
    char cmd[64];
    char buf[512];              /* Longest legal IRC command line */
    char *s;
    int ac;                     /* Parameters for the command */
    char **av;
    Message *m;

    /* zero out the buffers before we do much else */
    *buf = '\0';
    *source = '\0';
    *cmd = '\0';

    /* If debugging, log the buffer */
    if (debug) {
        alog("debug: Received: %s", inbuf);
    }

    /* First make a copy of the buffer so we have the original in case we
     * crash - in that case, we want to know what we crashed on. */
    strscpy(buf, inbuf, sizeof(buf));

    doCleanBuffer((char *) buf);

    /* Split the buffer into pieces. */
    if (*buf == ':') {
        s = strpbrk(buf, " ");
        if (!s)
            return;
        *s = 0;
        while (isspace(*++s));
        strscpy(source, buf + 1, sizeof(source));
        memmove(buf, s, strlen(s) + 1);
    } else {
        *source = 0;
    }
    if (!*buf)
        return;
    s = strpbrk(buf, " ");
    if (s) {
        *s = 0;
        while (isspace(*++s));
    } else
        s = buf + strlen(buf);
    strscpy(cmd, buf, sizeof(cmd));
    ac = split_buf(s, &av, 1);
    if (protocoldebug) {
        protocol_debug(source, cmd, ac, av);
    }
    if (mod_current_buffer) {
        free(mod_current_buffer);
    }
    /* fix to moduleGetLastBuffer() bug 296 */
    /* old logic was that since its meant for PRIVMSG that we would get
       the NICK as AV[0] and the rest would be in av[1], however on Bahamut
       based systems when you do /cs it assumes we will translate the command
       to the NICK and thus AV[0] is the message. The new logic is to check
       av[0] to see if its a service nick if so assign mod_current_buffer the
       value from AV[1] else just assign av[0] - TSL */
    /* First check if the ircd proto module overrides this -GD */
    /* fix to moduleGetLastBuffer() bug 476:
       fixed in part by adding {} to nickIsServices()
       however if you have a pseudo they could not use moduleGetLastBuffer()
       cause they are not part of nickIsServices, even those the ac count is 2
       that was ignored and only the first param was passed on which is fine for
       Bahmut ircd aliases but not for pseudo clients on. So additional logic is
       that if the ac is greater then 1 copy av[1] else copy av[0] 
       I also changed from if statments, cause attempting to access a array member
       that is not set can lead to odd things - TSL (3/12/06) */
    if (!xanadu_set_mod_current_buffer(ac, av)) {
        if (ac >= 1) {
            if (nickIsServices(av[0], 1)) {
                mod_current_buffer =
                    (ac > 1 ? sstrdup(av[1]) : sstrdup(av[0]));
            } else {
                mod_current_buffer =
                    (ac > 1 ? sstrdup(av[1]) : sstrdup(av[0]));
            }
        } else {
            mod_current_buffer = NULL;
        }
    }
    /* Do something with the message. */
    m = find_message(cmd);
    if (m) {
        if (m->func) {
            mod_current_module_name = m->mod_name;
            retVal = m->func(source, ac, av);
            mod_current_module_name = NULL;
            if (retVal == MOD_CONT) {
                current = m->next;
                while (current && current->func && retVal == MOD_CONT) {
                    mod_current_module_name = current->mod_name;
                    retVal = current->func(source, ac, av);
                    mod_current_module_name = NULL;
                    current = current->next;
                }
            }
        }
    } else {
        if (debug)
            alog("debug: unknown message from server (%s)", inbuf);
    }

    /* Load/unload modules if needed */
    handleModuleOperationQueue();

    /* Free argument list we created */
    free(av);
}
Beispiel #7
0
static int parse_input_file(const char *file_name, struct errors **top_error,
			    struct languages **top_lang)
{
  FILE *file;
  char *str, buff[1000];
  struct errors *current_error= 0, **tail_error= top_error;
  struct message current_message;
  uint rcount= 0;
  my_bool er_offset_found= 0;
  DBUG_ENTER("parse_input_file");

  *top_error= 0;
  *top_lang= 0;
  if (!(file= my_fopen(file_name, O_RDONLY | O_SHARE, MYF(MY_WME))))
    DBUG_RETURN(0);

  while ((str= fgets(buff, sizeof(buff), file)))
  {
    if (is_prefix(str, "language"))
    {
      if (!(*top_lang= parse_charset_string(str)))
      {
	fprintf(stderr, "Failed to parse the charset string!\n");
	DBUG_RETURN(0);
      }
      continue;
    }
    if (is_prefix(str, "start-error-number"))
    {
      uint tmp_er_offset;
      if (!(tmp_er_offset= parse_error_offset(str)))
      {
	fprintf(stderr, "Failed to parse the error offset string!\n");
	DBUG_RETURN(0);
      }
      if (!er_offset_found)
      {
        er_offset_found= 1;
        er_offset= tmp_er_offset;
      }
      else
      {
        /* Create empty error messages between er_offset and tmp_err_offset */
        if (tmp_er_offset < er_offset + rcount)
        {
          fprintf(stderr, "new start-error-number %u is smaller than current error message: %u\n", tmp_er_offset, er_offset + rcount);
          DBUG_RETURN(0);
        }
        for ( ; er_offset + rcount < tmp_er_offset ; rcount++)
        {
          current_error= generate_empty_message(er_offset + rcount);
          *tail_error= current_error;
          tail_error= &current_error->next_error;
        }
      }
      continue;
    }
    if (is_prefix(str, "default-language"))
    {
      if (!(default_language= parse_default_language(str)))
      {
	DBUG_PRINT("info", ("default_slang: %s", default_language));
	fprintf(stderr,
		"Failed to parse the default language line. Aborting\n");
	DBUG_RETURN(0);
      }
      continue;
    }

    if (*str == '\t' || *str == ' ')
    {
      /* New error message in another language for previous error */
      if (!current_error)
      {
	fprintf(stderr, "Error in the input file format\n");
	DBUG_RETURN(0);
      }
      if (!parse_message_string(&current_message, str))
      {
	fprintf(stderr, "Failed to parse message string for error '%s'",
		current_error->er_name);
	DBUG_RETURN(0);
      }
      if (find_message(current_error, current_message.lang_short_name, TRUE))
      {
	fprintf(stderr, "Duplicate message string for error '%s'"
                        " in language '%s'\n",
		current_error->er_name, current_message.lang_short_name);
	DBUG_RETURN(0);
      }
      if (check_message_format(current_error, current_message.text))
      {
	fprintf(stderr, "Wrong formatspecifier of error message string"
                        " for error '%s' in language '%s'\n",
		current_error->er_name, current_message.lang_short_name);
	DBUG_RETURN(0);
      }
      if (insert_dynamic(&current_error->msg, (uchar *) & current_message))
	DBUG_RETURN(0);
      continue;
    }
    if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX) ||
        is_prefix(str, ER_PREFIX2))
    {
      if (!(current_error= parse_error_string(str, rcount)))
      {
	fprintf(stderr, "Failed to parse the error name string\n");
	DBUG_RETURN(0);
      }
      rcount++;                         /* Count number of unique errors */

      /* add error to the list */
      *tail_error= current_error;
      tail_error= &current_error->next_error;
      continue;
    }
    if (*str == '#' || *str == '\n')
      continue;                      	/* skip comment or empty lines */

    fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str);
    DBUG_RETURN(0);
  }
  *tail_error= 0;			/* Mark end of list */

  my_fclose(file, MYF(0));
  DBUG_RETURN(rcount);
}