Beispiel #1
0
/**
 * get server info
 */
void rsp_info(WS_CONNINFO *pwsc, PRIVINFO *ppi) {
    XMLSTRUCT *pxml;
    char servername[256];
    int size;

    pi_log(E_DBG,"Starting rsp_info\n");
    pi_config_set_status(pwsc,0,"Getting server info");

    pxml = xml_init(pwsc,1);

    xml_push(pxml,"response");
    xml_push(pxml,"status");
    xml_output(pxml,"errorcode","0");
    xml_output(pxml,"errorstring","");
    xml_output(pxml,"records","0");
    xml_output(pxml,"totalrecords","0");
    xml_pop(pxml); /* status */

    /* info block */
    xml_push(pxml,"info");
    xml_output(pxml,"count","%d",pi_db_count_items(COUNT_SONGS));
    xml_output(pxml,"rsp-version","%s",RSP_VERSION);

    xml_output(pxml,"server-version","%s",pi_server_ver());

    size = sizeof(servername);
    pi_server_name(servername,&size);
    xml_output(pxml,"name","%s",servername);
    xml_pop(pxml); /* info */

    xml_pop(pxml); /* response */
    xml_deinit(pxml);
    pi_config_set_status(pwsc,0,NULL);
}
Beispiel #2
0
/**
 * /rsp/db
 *
 * dump details about all playlists
 */
void rsp_db(WS_CONNINFO *pwsc, PRIVINFO *ppi) {
    XMLSTRUCT *pxml;
    char *pe;
    int err;
    char **row;
    int rowindex;

    ppi->dq.query_type = QUERY_TYPE_PLAYLISTS;

    if((err=pi_db_enum_start(&pe,&ppi->dq)) != 0) {
        rsp_error(pwsc, ppi, err | E_DB, pe);
        pi_db_enum_dispose(NULL,&ppi->dq);
        return;
    }

    pi_config_set_status(pwsc,0,"Fetching playlist info");
    pxml = xml_init(pwsc,1);

    xml_push(pxml,"response");
    xml_push(pxml,"status");
    xml_output(pxml,"errorcode","0");
    xml_output(pxml,"errorstring","");
    xml_output(pxml,"records","%d",ppi->dq.totalcount);
    xml_output(pxml,"totalrecords","%d",ppi->dq.totalcount);
    xml_pop(pxml); /* status */

    xml_push(pxml,"playlists");

    while((pi_db_enum_fetch_row(NULL,&row,&ppi->dq) == 0) && (row)) {
        xml_push(pxml,"playlist");
        rowindex=0;
        while(rsp_playlist_fields[rowindex].name) {
            if(rsp_playlist_fields[rowindex].flags & F_FULL) {
                xml_output(pxml,rsp_playlist_fields[rowindex].name,"%s",
                              row[rowindex]);
            }
            rowindex++;
        }
        xml_pop(pxml); /* playlist */
    }

    pi_db_enum_end(NULL);
    pi_db_enum_dispose(NULL,&ppi->dq);

    xml_pop(pxml); /* playlists */
    xml_pop(pxml); /* response */
    xml_deinit(pxml);
    pi_config_set_status(pwsc,0,NULL);
}
Beispiel #3
0
void rsp_error(WS_CONNINFO *pwsc, PRIVINFO *ppi, int eno, char *estr) {
    XMLSTRUCT *pxml;

    pxml = xml_init(pwsc, 1);
    xml_push(pxml,"response");
    xml_push(pxml,"status");
    xml_output(pxml,"errorcode","%d",eno);
    xml_output(pxml,"errorstring","%s",estr);
    xml_output(pxml,"records","0");
    xml_output(pxml,"totalrecords","0");
    xml_pop(pxml); /* status */
    xml_pop(pxml); /* response */
    xml_deinit(pxml);
    pi_ws_will_close(pwsc);
}
Beispiel #4
0
void verbose(void)
{
    register int i;

    if (!vflag)
	return xml_output();
    
	
	/* else */
    null_rules = (short *)MALLOC(nrules * sizeof(short));
    if (null_rules == 0)
	no_space();
    fprintf(verbose_file, "\f\n");
    for (i = 0; i < nstates; i++)
	print_state(i);
    FREE(null_rules);

    if (nunused)
	log_unused();
    if (SRtotal || RRtotal)
	log_conflicts();

    fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
	    nvars);
    fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates);
}
Beispiel #5
0
void test_output()
{
    xml_body_ptr body = NULL;
    xml_table_ptr table = NULL;
    xml_item_ptr item = NULL;
    xml_item_attr_ptr attr = NULL;
    xml_handel handel = NULL;
    char *buf;
    int len, i, t_cnt = 1;

    printf("\n*** test_output ***\n");

    /* new body with [t_cnt] tables */
    body = xml_body_new(t_cnt);
    for ( i = 0; i < t_cnt; i++ ) {
        /* init every table with 1 item, each item 1 attribute */
        xml_table_init(body->t_list + i, 1, 1);
    }

    /* init xml_body here */    
    body->unit_code = xml_strdup(body, "场所编码");

    table = xml_get_table(body, 0);
    /* init xml_table[0] here */
    table->name = xml_strdup(body, "记录集名称");
    
    item = xml_get_item(table, 0);    
    attr = xml_get_attr(item, 0);
    /* init xml_item[0].attr[0] */
    attr->name = xml_strdup(body, "item1");
    attr->value = xml_strdup(body, "值1");

    /* get xml buffer */
    handel = xml_output(body, &buf, &len);
    
    printf("%s", buf);
    
    /* clean xml buffer */
    xml_output_clean(handel);

    /* clean body */
    xml_body_clean(body);
    
}
Beispiel #6
0
void test_all()
{
    char *xml = "\n<Body UnitCode=\"场所编码\" Code=\"结果代码\" Description=\"结果附加说明\">table\n"
        "\n<Table Name=\"记录集名称\" Method=\"处理动作\" Range=\"数据范围\" CmdNo=\"命令号\" Description=\"附加说明\">\n"
        "\n<Item item1=\"值1\" item2=\"值2\" />item\n<Item item3=\"值3\" item4=\"值4\" />\n"
        "</Table>table\n</Body>\n\n"; 
    xml_body_ptr body = NULL;
    xml_handel handel = NULL;
    char *buf = NULL;
    int len;

    printf("\n*** test_all ***\n");
    
    printf("XML: %s\n", xml);

    body = xml_parse(xml);
    test_print(body);
    
    handel = xml_output(body, &buf, &len);
    printf("%s", buf);
    xml_output_clean(handel);

    xml_body_clean(body);
}
Beispiel #7
0
void rsp_browse(WS_CONNINFO *pwsc, PRIVINFO *ppi) {
    XMLSTRUCT *pxml;
    char *pe;
    int err;
    char **row;
    int returned;

    /* this might fail if an unsupported browse type */
    ppi->dq.query_type = QUERY_TYPE_DISTINCT;
    ppi->dq.distinct_field = ppi->uri_sections[3];
    ppi->dq.filter = pi_ws_getvar(pwsc,"query");
    ppi->dq.filter_type = FILTER_TYPE_FIREFLY;

    if(pi_ws_getvar(pwsc,"offset")) {
        ppi->dq.offset = atoi(pi_ws_getvar(pwsc,"offset"));
    }

    if(pi_ws_getvar(pwsc,"limit")) {
        ppi->dq.limit = atoi(pi_ws_getvar(pwsc,"limit"));
    }

    ppi->dq.playlist_id = atoi(ppi->uri_sections[2]);

    if((err=pi_db_enum_start(&pe,&ppi->dq)) != 0) {
        rsp_error(pwsc, ppi, err | E_DB, pe);
        pi_db_enum_dispose(NULL,&ppi->dq);
        return;
    }

    pi_config_set_status(pwsc,0,"Browsing");
    pxml = xml_init(pwsc,1);

    if(ppi->dq.offset > ppi->dq.totalcount) {
        returned = 0;
    } else {
        returned = ppi->dq.limit;
        if(returned > (ppi->dq.totalcount - ppi->dq.offset))
            returned = ppi->dq.totalcount - ppi->dq.offset;
    }

    xml_push(pxml,"response");
    xml_push(pxml,"status");
    xml_output(pxml,"errorcode","0");
    xml_output(pxml,"errorstring","");
    xml_output(pxml,"records","%d",returned);
    xml_output(pxml,"totalrecords","%d",ppi->dq.totalcount);
    xml_pop(pxml); /* status */

    xml_push(pxml,"items");

    while((pi_db_enum_fetch_row(NULL,&row,&ppi->dq) == 0) && (row)) {
        xml_output(pxml,"item","%s",row[0]);
    }

    pi_db_enum_end(NULL);
    pi_db_enum_dispose(NULL,&ppi->dq);

    xml_pop(pxml); /* items */
    xml_pop(pxml); /* response */
    xml_deinit(pxml);
    pi_config_set_status(pwsc,0,NULL);
}
Beispiel #8
0
/**
 * get all items under the playlist
 */
void rsp_playlist(WS_CONNINFO *pwsc, PRIVINFO *ppi) {
    XMLSTRUCT *pxml;
    char *pe;
    int err;
    char **row;
    int rowindex;
    int returned;
    char *browse_type;
    int type;
    int transcode;
    unsigned int samplerate;
    int done = 0;

    ppi->dq.filter = pi_ws_getvar(pwsc,"query");
    ppi->dq.filter_type = FILTER_TYPE_FIREFLY;

    if(pi_ws_getvar(pwsc,"offset")) {
        ppi->dq.offset = atoi(pi_ws_getvar(pwsc,"offset"));
    }
    if(pi_ws_getvar(pwsc,"limit")) {
        ppi->dq.limit = atoi(pi_ws_getvar(pwsc,"limit"));
    }

    browse_type = pi_ws_getvar(pwsc,"type");
    type = F_FULL;

    if(browse_type) {
        if(strcasecmp(browse_type,"browse") == 0) {
            type = F_BROWSE;
        } else if(strcasecmp(browse_type,"id") == 0) {
            type = F_ID;
        } else if(strcasecmp(browse_type,"detailed") ==0) {
            type = F_DETAILED;
        }
    }

    ppi->dq.query_type = QUERY_TYPE_ITEMS;
    ppi->dq.playlist_id = atoi(ppi->uri_sections[2]);

    if((err=pi_db_enum_start(&pe,&ppi->dq)) != 0) {
        rsp_error(pwsc, ppi, err | E_DB, pe);
        pi_db_enum_dispose(NULL,&ppi->dq);
        free(pe);
        return;
    }

    pi_config_set_status(pwsc,0,"Fetching playlist items");
    pxml = xml_init(pwsc,1);

    if(ppi->dq.offset > ppi->dq.totalcount) {
        returned = 0;
    } else {
        returned = ppi->dq.limit;
        if(returned > (ppi->dq.totalcount - ppi->dq.offset))
            returned = ppi->dq.totalcount - ppi->dq.offset;
    }

    xml_push(pxml,"response");
    xml_push(pxml,"status");
    xml_output(pxml,"errorcode","0");
    xml_output(pxml,"errorstring","");
    xml_output(pxml,"records","%d",returned);
    xml_output(pxml,"totalrecords","%d",ppi->dq.totalcount);
    xml_pop(pxml); /* status */

    xml_push(pxml,"items");

    while((!done) && (pi_db_enum_fetch_row(NULL,&row,&ppi->dq) == 0) &&
          (row)) {
        xml_push(pxml,"item");
        rowindex=0;
        transcode = 0;

        transcode = pi_should_transcode(pwsc,row[37]);

        pi_log(E_DBG,"Transcode: %d, %s: %s\n",transcode,row[37],row[2]);

        while(rsp_fields[rowindex].name) {
            if((rsp_fields[rowindex].flags & type) &&
               (row[rowindex] && strlen(row[rowindex]))) {
                if(transcode) {
                    switch(rowindex) {
                    case 8:
                        xml_output(pxml,rsp_fields[rowindex].name,"%s","wav");
                        break;
                    case 29:
                        xml_output(pxml,rsp_fields[rowindex].name,"%s",
                                   "wav audio file");
                        break;
                    case 14: /* bitrate */
                        samplerate = atoi(row[15]);
                        if(samplerate) {
                            samplerate = (samplerate * 8) / 250;
                        } else {
                            samplerate = 1411;
                        }
                        xml_output(pxml,rsp_fields[rowindex].name,"%d",
                                   samplerate);
                        break;
                    case 37:
                        xml_output(pxml,rsp_fields[rowindex].name,"%s","wav");
                        xml_output(pxml,"original_codec","%s",row[37]);
                        break;
                    default:
                        xml_output(pxml,rsp_fields[rowindex].name,"%s",
                                   row[rowindex]);
                        break;
                    }
                } else {
                    /* check for pushing against closed socket */
                    if(xml_output(pxml,rsp_fields[rowindex].name,"%s",
                                  row[rowindex]) == -1)
                        done=1;
                }

            }
            rowindex++;
        }
        xml_pop(pxml); /* item */
    }

    pi_db_enum_end(NULL);

    xml_pop(pxml); /* items */
    xml_pop(pxml); /* response */
    xml_deinit(pxml);
    pi_config_set_status(pwsc,0,NULL);
}