src/mn-masterd/main.c
int
nol_m_reconfigure()
{
    int  x, a;
    int  n;
    char tq[64+64+CREATE_TBL_LEN+DEFAULT_LAYOUT_LEN+1];
    char *name;
    int  len;
    lmc_parser_t *lmc;

    /* the lmc parser is created with 0 as root, since
     * our object-functions will modify the static 'srv'
     * directly */
    if (!(lmc = lmc_create(0)))
        return -1;

    lmc_add_class(lmc, &nol_m_filetype_class);
    lmc_add_class(lmc, &nol_m_crawler_class);
    if (lmc_parse_file(lmc, opt_vals.config_file) != M_OK) {
        fprintf(stderr, "%s", lmc->last_error);
        return -1;
    }

    for (n=0; n<srv.num_filetypes; n++) {
        name = srv.filetypes[n]->name;
        len = strlen(name);

        /** 
         * Make sure the name does not contain any weird
         * characters. Convert them to '_'.
         **/
        for (x=0; x<len; x++)
            if (!isalnum(*(name+x)) && *(name+x) != '_')
                *(name+x) = '_';

        len = sprintf(tq, "%sft_%.60s%s", 
                            CREATE_TBL,
                            name,
                            DEFAULT_LAYOUT
                );

        mysql_real_query(srv.mysql, tq, len);

        /* add this filetype as a counter column in the session table,
         * this query might fail but it doesnt matter, because then
         * the column probably exists already */
        len = sprintf(tq,
                "ALTER TABLE `nol_session` "
                "ADD COLUMN count_%.60s INT UNSIGNED",
                name);
        mysql_real_query(srv.mysql, tq, len);

        /** 
         * Now add all the columns. Many of these queries will probably
         * fail because the column already exists, but this is expected
         * behaviour.
         **/
        for (a=0; a<srv.filetypes[n]->num_attributes; a++) {
            char *attr = srv.filetypes[n]->attributes[a];
            char *type = strchr(attr, ' ');
            int type_n;

            if (!type || !strlen(type+1)) {
                syslog(LOG_ERR, "no type given for attribute '%s'", attr);
                continue;
            }
            type++;
            type_n = ATTR_TYPE_UNKNOWN;
            if (strcasecmp(type, "INT") == 0)
                type_n = ATTR_TYPE_INT;
            else if (strcasecmp(type, "TEXT") == 0)
                type_n = ATTR_TYPE_TEXT;
            else if (strcasecmp(type, "BLOB") == 0)
                type_n = ATTR_TYPE_BLOB;

            if (type_n == ATTR_TYPE_UNKNOWN) {
                syslog(LOG_ERR, "unknown attribute type '%s'", type);
                continue;
            }

            len = sprintf(tq, "ALTER TABLE ft_%.60s ADD COLUMN %.60s",
                    name, attr);
            if (mysql_real_query(srv.mysql, tq, len) == 0) {
                if (type_n == ATTR_TYPE_TEXT) {
                    *(type-1) = '\0';
                    sprintf(tq, "ALTER TABLE ft_%.60s ADD FULLTEXT (%.60s)",
                            name, attr);
                    mysql_real_query(srv.mysql, tq, len);
                }
            }

        }
    }

    lmc_destroy(lmc);

    return 0;
}
/** 
 * nol_m_reconfigure()
 * Create filetype tables.
 *
 * When a filetype is created, it will contain only one column
 * at first, and then ALTER TABLE is used to add the filetype's
 * attributes one by one. The benefit of adding the columns one,
 * by one is that whenever a filetype has been changed in the
 * configuration file, its new attributes will be added as new 
 * columns, while the existing columns will be untouched, thus
 * the system can easily reconfigure itself while retaining
 * already existing columns and data.
 *
 * No columns will be removed from filetype tables, since 
 * they might contain important data. It is up to the system
 * admin to remove unused columns.
 **/
nol_m_reconfigure()
Create filetype tables.

When a filetype is created, it will contain only one column
at first, and then ALTER TABLE is used to add the filetype's
attributes one by one. The benefit of adding the columns one,
by one is that whenever a filetype has been changed in the
configuration file, its new attributes will be added as new
columns, while the existing columns will be untouched, thus
the system can easily reconfigure itself while retaining
already existing columns and data.

No columns will be removed from filetype tables, since
they might contain important data. It is up to the system
admin to remove unused columns.
nol_m_reconfigure () Create filetype tables . When a filetype is created it will contain only one column at first and then ALTER TABLE is used to add the filetype ' s attributes one by one . The benefit of adding the columns one by one is that whenever a filetype has been changed in the configuration file its new attributes will be added as new columns while the existing columns will be untouched thus the system can easily reconfigure itself while retaining already existing columns and data . No columns will be removed from filetype tables since they might contain important data . It is up to the system admin to remove unused columns .
int
nol_m_reconfigure()
{
    int  x, a;
    int  n;
    char tq[64+64+CREATE_TBL_LEN+DEFAULT_LAYOUT_LEN+1];
    char *name;
    int  len;
    lmc_parser_t *lmc;
    if (!(lmc = lmc_create(0)))
        return -1;
    lmc_add_class(lmc, &nol_m_filetype_class);
    lmc_add_class(lmc, &nol_m_crawler_class);
    if (lmc_parse_file(lmc, opt_vals.config_file) != M_OK) {
        fprintf(stderr, "%s", lmc->last_error);
        return -1;
    }
    for (n=0; n<srv.num_filetypes; n++) {
        name = srv.filetypes[n]->name;
        len = strlen(name);
        for (x=0; x<len; x++)
            if (!isalnum(*(name+x)) && *(name+x) != '_')
                *(name+x) = '_';
        len = sprintf(tq, "%sft_%.60s%s", 
                            CREATE_TBL,
                            name,
                            DEFAULT_LAYOUT
                );
        mysql_real_query(srv.mysql, tq, len);
        len = sprintf(tq,
                "ALTER TABLE `nol_session` "
                "ADD COLUMN count_%.60s INT UNSIGNED",
                name);
        mysql_real_query(srv.mysql, tq, len);
        for (a=0; a<srv.filetypes[n]->num_attributes; a++) {
            char *attr = srv.filetypes[n]->attributes[a];
            char *type = strchr(attr, ' ');
            int type_n;
            if (!type || !strlen(type+1)) {
                syslog(LOG_ERR, "no type given for attribute '%s'", attr);
                continue;
            }
            type++;
            type_n = ATTR_TYPE_UNKNOWN;
            if (strcasecmp(type, "INT") == 0)
                type_n = ATTR_TYPE_INT;
            else if (strcasecmp(type, "TEXT") == 0)
                type_n = ATTR_TYPE_TEXT;
            else if (strcasecmp(type, "BLOB") == 0)
                type_n = ATTR_TYPE_BLOB;
            if (type_n == ATTR_TYPE_UNKNOWN) {
                syslog(LOG_ERR, "unknown attribute type '%s'", type);
                continue;
            }
            len = sprintf(tq, "ALTER TABLE ft_%.60s ADD COLUMN %.60s",
                    name, attr);
            if (mysql_real_query(srv.mysql, tq, len) == 0) {
                if (type_n == ATTR_TYPE_TEXT) {
                    *(type-1) = '\0';
                    sprintf(tq, "ALTER TABLE ft_%.60s ADD FULLTEXT (%.60s)",
                            name, attr);
                    mysql_real_query(srv.mysql, tq, len);
                }
            }
        }
    }
    lmc_destroy(lmc);
    return 0;
}
int nol_m_reconfigure ( ) { int x , a ; int n ; char tq [ 64 + 64 + CREATE_TBL_LEN + DEFAULT_LAYOUT_LEN + 1 ] ; char * name ; int len ; lmc_parser_t * lmc ; if ( ! ( lmc = lmc_create ( 0 ) ) ) return -1 ; lmc_add_class ( lmc , & nol_m_filetype_class ) ; lmc_add_class ( lmc , & nol_m_crawler_class ) ; if ( lmc_parse_file ( lmc , opt_vals . config_file ) != M_OK ) { fprintf ( stderr , " " , lmc -> last_error ) ; return -1 ; } for ( n = 0 ; n < srv . num_filetypes ; n ++ ) { name = srv . filetypes [ n ] -> name ; len = strlen ( name ) ; for ( x = 0 ; x < len ; x ++ ) if ( ! isalnum ( * ( name + x ) ) && * ( name + x ) != ' ' ) * ( name + x ) = ' ' ; len = sprintf ( tq , " " , CREATE_TBL , name , DEFAULT_LAYOUT ) ; mysql_real_query ( srv . mysql , tq , len ) ; len = sprintf ( tq , " " " " , name ) ; mysql_real_query ( srv . mysql , tq , len ) ; for ( a = 0 ; a < srv . filetypes [ n ] -> num_attributes ; a ++ ) { char * attr = srv . filetypes [ n ] -> attributes [ a ] ; char * type = strchr ( attr , ' ' ) ; int type_n ; if ( ! type || ! strlen ( type + 1 ) ) { syslog ( LOG_ERR , " " , attr ) ; continue ; } type ++ ; type_n = ATTR_TYPE_UNKNOWN ; if ( strcasecmp ( type , " " ) == 0 ) type_n = ATTR_TYPE_INT ; else if ( strcasecmp ( type , " " ) == 0 ) type_n = ATTR_TYPE_TEXT ; else if ( strcasecmp ( type , " " ) == 0 ) type_n = ATTR_TYPE_BLOB ; if ( type_n == ATTR_TYPE_UNKNOWN ) { syslog ( LOG_ERR , " " , type ) ; continue ; } len = sprintf ( tq , " " , name , attr ) ; if ( mysql_real_query ( srv . mysql , tq , len ) == 0 ) { if ( type_n == ATTR_TYPE_TEXT ) { * ( type - 1 ) = ' \0 ' ; sprintf ( tq , " " , name , attr ) ; mysql_real_query ( srv . mysql , tq , len ) ; } } } } lmc_destroy ( lmc ) ; return 0 ; }
nol_m_reconfigure()
 Create filetype tables.
nol_m_reconfigure () Create filetype tables .
/* the lmc parser is created with 0 as root, since
     * our object-functions will modify the static 'srv'
     * directly */ /** 
         * Make sure the name does not contain any weird
         * characters. Convert them to '_'.
         **/ /* add this filetype as a counter column in the session table,
         * this query might fail but it doesnt matter, because then
         * the column probably exists already */ /** 
         * Now add all the columns. Many of these queries will probably
         * fail because the column already exists, but this is expected
         * behaviour.
         **/