// TODO: this will need converting to an idnode system static int api_channel_list ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { channel_t *ch; htsmsg_t *l; int cfg = api_channel_is_all(perm, args); char buf[128], ubuf[UUID_HEX_SIZE]; l = htsmsg_create_list(); pthread_mutex_lock(&global_lock); CHANNEL_FOREACH(ch) { if (!cfg && !channel_access(ch, perm, 0)) continue; if (!ch->ch_enabled) { snprintf(buf, sizeof(buf), "{%s}", channel_get_name(ch)); api_channel_key_val(l, idnode_uuid_as_str(&ch->ch_id, ubuf), buf); } else { api_channel_key_val(l, idnode_uuid_as_str(&ch->ch_id, ubuf), channel_get_name(ch)); } } pthread_mutex_unlock(&global_lock); *resp = htsmsg_create_map(); htsmsg_add_msg(*resp, "entries", l); return 0; }
static int _handle_list_command(t_connection * conn, int numparams, char ** params, char * text) { char temp[MAX_IRC_MESSAGE_LEN]; irc_send(conn,RPL_LISTSTART,"Channel :Users Names"); /* backward compatibility */ if (numparams==0) { t_elem const * curr; LIST_TRAVERSE_CONST(channellist(),curr) { t_channel const * channel = (const t_channel*)elem_get_data(curr); char const * tempname; char * topic = channel_get_topic(channel_get_name(channel)); tempname = irc_convert_channel(channel,conn); /* FIXME: AARON: only list channels like in /channels command */ if (topic) { if (std::strlen(tempname)+1+20+1+1+std::strlen(topic)<MAX_IRC_MESSAGE_LEN) snprintf(temp, sizeof(temp), "%s %u :%s",tempname,channel_get_length(channel),topic); else eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded"); } else { if (std::strlen(tempname)+1+20+1+1<MAX_IRC_MESSAGE_LEN) snprintf(temp, sizeof(temp), "%s %u :",tempname,channel_get_length(channel)); else eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded"); } irc_send(conn,RPL_LIST,temp); }
/** * \brief Store metadata information */ void Storage::storeMetadata(metadata* mdata) { std::stringstream ss; /* Geolocation info */ ss << "\"srcAS\": \"" << mdata->srcAS << "\", "; ss << "\"dstAS\": \"" << mdata->dstAS << "\", "; ss << "\"srcCountry\": \"" << mdata->srcCountry << "\", "; ss << "\"dstCountry\": \"" << mdata->dstCountry << "\", "; ss << "\"srcName\": \"" << mdata->srcName << "\", "; ss << "\"dstName\": \"" << mdata->dstName << "\", "; record += ss.str(); /* Profiles */ if (mdata->channels) { record += "\"profiles\": ["; for (int i = 0; mdata->channels[i] != 0; ++i) { if (i > 0) { record += ", "; } record += "{\"profile\": \""; record += channel_get_name(mdata->channels[i]); record += "\", \"channel\": \""; record += profile_get_name(channel_get_profile(mdata->channels[i])); record += "\"}"; } record += "]"; } }
void dvr_rec_subscribe(dvr_entry_t *de) { char buf[100]; int weight; profile_t *pro; profile_chain_t *prch; assert(de->de_s == NULL); assert(de->de_chain == NULL); if(de->de_pri < ARRAY_SIZE(prio2weight)) weight = prio2weight[de->de_pri]; else weight = 300; snprintf(buf, sizeof(buf), "DVR: %s", lang_str_get(de->de_title, NULL)); pro = de->de_config->dvr_profile; prch = malloc(sizeof(*prch)); profile_chain_init(prch, pro, de->de_channel); if (profile_chain_open(prch, &de->de_config->dvr_muxcnf, 0, 0)) { tvherror("dvr", "unable to create new channel streaming chain for '%s'", channel_get_name(de->de_channel)); return; } de->de_s = subscription_create_from_channel(prch, weight, buf, prch->prch_flags, NULL, NULL, NULL); if (de->de_s == NULL) { tvherror("dvr", "unable to create new channel subcription for '%s'", channel_get_name(de->de_channel)); profile_chain_close(prch); free(prch); de->de_chain = NULL; return; } de->de_chain = prch; tvhthread_create(&de->de_thread, NULL, dvr_thread, de); }
/** * \brief Find an old channel record that corresponds to a new channel * \param[in] mgr Event manager * \param[in] ch_new Pointer to the new channel (from a profiler) * \return If the record is in the manager, returns a pointer to the record. * Otherwise (the record not found) returns NULL. */ static struct pevents_item * pevents_update_mapper_find_old_channel(pevents_t *mgr, void *ch_new) { // New channel path and name const char *path_new = channel_get_path(ch_new); const char *name_new = channel_get_name(ch_new); const char *path_old; const char *name_old; struct pevents_group *ch_grp = &mgr->channels; // Old channels const size_t old_chnl_cnt = ch_grp->all_size; // Number of old channels for (size_t i = 0; i < old_chnl_cnt; ++i) { // Check if the channel has been already mapped (perform. optimization) if (bitset_get_fast(ch_grp->bitset, i)) { // Already mapped -> skip continue; } // Get the old channel struct pevents_item *item = group_item_at(ch_grp, i); void *ch_old = item->ctx.ptr.channel; // Compare names (shorter names -> faster) name_old = channel_get_name(ch_old); if (strcmp(name_old, name_new) != 0) { continue; } // Compare path path_old = channel_get_path(ch_old); if (strcmp(path_new, path_old) != 0) { continue; } return item; } // Not found return NULL; }
/** * \brief Store metadata information */ void Storage::storeMetadata(metadata* mdata) { std::stringstream ss; /* Geolocation info */ ss << "\"srcAS\": \"" << mdata->srcAS << "\", "; ss << "\"dstAS\": \"" << mdata->dstAS << "\", "; ss << "\"srcCountry\": \"" << mdata->srcCountry << "\", "; ss << "\"dstCountry\": \"" << mdata->dstCountry << "\", "; ss << "\"srcName\": \"" << mdata->srcName << "\", "; ss << "\"dstName\": \"" << mdata->dstName << "\", "; record += ss.str(); /* Profiles */ STR_APPEND(record, "\"profiles\": ["); if (mdata->channels) { // Get name of root profile void *profile_ptr = NULL; void *prev_profile_ptr = NULL; const char *root_profile_name; profile_ptr = channel_get_profile(mdata->channels[0]); while (profile_ptr != NULL) { prev_profile_ptr = profile_ptr; profile_ptr = profile_get_parent(profile_ptr); } root_profile_name = profile_get_name(prev_profile_ptr); // Process all channels for (int i = 0; mdata->channels[i] != 0; ++i) { if (i > 0) { STR_APPEND(record, ", "); } STR_APPEND(record, "{\"profile\": \""); record += root_profile_name; STR_APPEND(record, "/"); record += profile_get_path(channel_get_profile(mdata->channels[i])); STR_APPEND(record, "\", \"channel\": \""); record += channel_get_name(mdata->channels[i]); STR_APPEND(record, "\"}"); } } record += ']'; }
/* In IRC a channel can be specified by '#'+channelname or '!'+channelid */ extern char const * irc_convert_channel(t_channel const * channel) { char const * bname; static char out[CHANNEL_NAME_LEN]; unsigned int outpos; int i; if (!channel) return "*"; memset(out,0,sizeof(out)); out[0] = '#'; outpos = 1; bname = channel_get_name(channel); for (i=0; bname[i]!='\0'; i++) { if (bname[i]==' ') { out[outpos++] = '_'; } else if (bname[i]=='_') { out[outpos++] = '%'; out[outpos++] = '_'; } else if (bname[i]=='%') { out[outpos++] = '%'; out[outpos++] = '%'; } else if (bname[i]=='\b') { out[outpos++] = '%'; out[outpos++] = 'b'; } else if (bname[i]=='\n') { out[outpos++] = '%'; out[outpos++] = 'n'; } else if (bname[i]=='\r') { out[outpos++] = '%'; out[outpos++] = 'r'; } else if (bname[i]==':') { out[outpos++] = '%'; out[outpos++] = '='; } else if (bname[i]==',') { out[outpos++] = '%'; out[outpos++] = '-'; } else { out[outpos++] = bname[i]; } if ((outpos+2)>=(sizeof(out))) { sprintf(out,"!%u",channel_get_channelid(channel)); return out; } } return out; }
void display_ctor(Display* disp, Menu_enum menu_type, Display* left, Display* right, Display* select, Display* back, uint16_t value) { disp->menu_type = menu_type; disp->left = left; disp->right = right; disp->select = select; disp->back = back; disp->i = value; switch(menu_type){ case CHANNEL_DISPLAY:{//CHANNEL_DISPLAY: display_set_text(disp, CHANNEL_DISPLAY_TEXT, 16); break;} case CHANNEL_SELECT:{//CHANNEL_SELECT: display_set_text(disp, CHANNEL_SELECT_TEXT, 16); break;} case CHANNEL_VOLUME:{//CHANNEL_VOLUME: display_set_text(disp, VOLUME_TEXT, 16); break;} case AMP_TYPE:{//AMP_TYPE: display_set_text(disp, AMP_TYPE_TEXT, 16); break;} case CHANNEL_DISPLAY_2:{ switch(value){ case 1:{ display_set_text(disp,"L/Main Speaker",16); //this is just to load something onto the second line this will need to be replaced Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break; } case 2:{ display_set_text(disp,"R Speaker",16); //this is just to load something onto the second line this will need to be replaced Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break; } case 3:{ display_set_text(disp,"L SPDIF",16); //this is just to load something onto the second line this will need to be replaced Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break; } case 4:{ display_set_text(disp,"R SPDIF",16); //this is just to load something onto the second line this will need to be replaced Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break; } case 5:{ display_set_text(disp,"L XLR",16); //this is just to load something onto the second line this will need to be replaced Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break; } case 6:{ display_set_text(disp,"R XLR",16); //this is just to load something onto the second line this will need to be replaced Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break; } case 7:{ display_set_text(disp,"L Headphone",16); //this is just to load something onto the second line this will need to be replaced Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break; } case 8:{ display_set_text(disp,"R Headphone",16); //this is just to load something onto the second line this will need to be replaced Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break; } } break;} case CHANNEL_SELECT_2:{ display_set_text(disp, CHANNEL_SELECT_TEXT, 16); Io_enum temp_io = OUTPUT; Channel* temp_channel = get_channel_from_memory(temp_io, value); display_set_text_line_2(disp, channel_get_name(temp_channel), 16); break;} case CHANNEL_VOLUME_2:{ display_set_text(disp, VOLUME_TEXT, 16); //volume TODO: volume display display_set_text_line_2(disp, "-123456789AB+", 16); break;} case AMP_TYPE_2:{ display_set_text(disp, AMP_TYPE_TEXT, 16); switch(value){ case 1: { display_set_text_line_2(disp, "Stereo", 16); break; } case 2: { display_set_text_line_2(disp, "Mono", 16); break; } } break;} case CHANNEL_SELECT_3:{ display_set_text(disp, "channel select 3", 16); switch(value){ case 1:{ display_set_text_line_2(disp,"L/Main Speaker",16); break; } case 2:{ display_set_text_line_2(disp,"R Speaker",16); break; } case 3:{ display_set_text_line_2(disp,"L SPDIF",16); break; } case 4:{ display_set_text_line_2(disp,"R SPDIF",16); break; } case 5:{ display_set_text_line_2(disp,"L XLR",16); break; } case 6:{ display_set_text_line_2(disp,"R XLR",16); break; } case 7:{ display_set_text_line_2(disp,"L Headphone",16); break; } case 8:{ display_set_text_line_2(disp,"R Headphone",16); break; } } break;} case HOME:{ display_set_text(disp, HOME_TEXT, 16); break;} default:{ printf("error disp_ctor"); break;} } }
int output_standard_writer(std::FILE * fp) { t_elem const *curr; t_connection *conn; t_channel const *channel; t_game *game; char const *channel_name; int number; char clienttag_str[5]; int uptime = server_get_uptime(); if (prefs_get_XML_status_output()) { int seconds; int minutes; int hours; int days; days = (uptime / (60 * 60 * 24)); hours = (uptime / (60 * 60)) % 24; minutes = (uptime / 60) % 60; seconds = uptime % 60; std::fprintf(fp, "<?xml version=\"1.0\"?>\n<status>\n"); std::fprintf(fp, "\t\t<Version>%s</Version>\n", PVPGN_VERSION); std::fprintf(fp, "\t\t<Uptime>\n"); std::fprintf(fp, "\t\t\t<Days>%d</Days>\n", days); std::fprintf(fp, "\t\t\t<Hours>%d</Hours>\n", hours); std::fprintf(fp, "\t\t\t<Minutes>%d</Minutes>\n", minutes); std::fprintf(fp, "\t\t\t<Seconds>%d</Seconds>\n", seconds); std::fprintf(fp, "\t\t</Uptime>\n"); std::fprintf(fp, "\t\t<Users>\n"); std::fprintf(fp, "\t\t<Number>%d</Number>\n", connlist_login_get_length()); LIST_TRAVERSE_CONST(connlist(), curr) { conn = (t_connection*)elem_get_data(curr); if (conn_get_account(conn)) std::fprintf(fp, "\t\t<user><name>%s</name><clienttag>%s</clienttag><version>%s</version>", conn_get_username(conn), tag_uint_to_str(clienttag_str, conn_get_clienttag(conn)), conn_get_clientver(conn)); if ((game = conn_get_game(conn))) std::fprintf(fp, "<gameid>%u</gameid>", game_get_id(game)); std::fprintf(fp, "</user>\n"); } std::fprintf(fp, "\t\t</Users>\n"); std::fprintf(fp, "\t\t<Games>\n"); std::fprintf(fp, "\t\t<Number>%d</Number>\n", gamelist_get_length()); gamelist_traverse(_glist_cb_xml, fp); std::fprintf(fp, "\t\t</Games>\n"); std::fprintf(fp, "\t\t<Channels>\n"); std::fprintf(fp, "\t\t<Number>%d</Number>\n", channellist_get_length()); LIST_TRAVERSE_CONST(channellist(), curr) { channel = (t_channel*)elem_get_data(curr); channel_name = channel_get_name(channel); std::fprintf(fp, "\t\t<channel>%s</channel>\n", channel_name); }
int main (int argc, const char * argv[]) { ApiRead r1, r2; ApiWrite w1, w2; ApiAck a1, a2; ApiNot n1, n2; //TEST API READ CONSTRUCTOR AND RE-CONSTRUCTOR ApiRead_ctor(&r1, 1, OUTPUT, COMP, THRESHOLD); char read_format[3]; char read_format2[3]; printf("ApiRead Constructor Results:\n"); ApiRead_inspect(&r1); ApiRead_frmtr(&r1, read_format); printf("%X %X %X\n\n", read_format[0], read_format[1], read_format[2]); printf("Reconstructed\n"); ApiRead_rector(&r2, read_format); ApiRead_frmtr(&r2, read_format2); ApiRead_inspect(&r2); printf("%X %X %X\n\n", read_format2[0], read_format2[1], read_format2[2]); //TEST API WRITE CONSTRUCTOR AND RE-CONSTRUCTOR ApiWrite_ctor(&w1, 3, OUTPUT, COMP, THRESHOLD, 7567.557); char write_format[7]; char write_format2[7]; printf("ApiWrite Constructor Results:\n"); ApiWrite_inspect(&w1); ApiWrite_frmtr(&w1, write_format); printf("%X %X %X\n", write_format[0], write_format[1], write_format[2]); printf("value float to 4 bytes: %X %X %X %X\n\n", write_format[3] & 0x000000FF, write_format[4] & 0x000000FF, write_format[5] & 0x000000FF, write_format[6] & 0x000000FF); printf("Reconstructed\n"); ApiWrite_rector(&w2, write_format); ApiWrite_frmtr(&w2, write_format2); ApiWrite_inspect(&w2); printf("%X %X %X\n", write_format2[0], write_format2[1], write_format2[2]); printf("value float to 4 bytes: %X %X %X %X\n\n", write_format2[3] & 0x000000FF, write_format2[4] & 0x000000FF, write_format2[5] & 0x000000FF, write_format2[6] & 0x000000FF); Type_enum *recovered_type = (Type_enum *) &w1; printf("\n\nrecovered type: %d\n\n", *recovered_type); //TEST API ACKNOWLEDGE CONSTRUCTOR AND RE-RECONSTRUCTOR ApiAck_ctor(&a1, 99, 7567.557); char ack_format[6]; char ack_format2[6]; printf("ApiAck Constructor Results:\n"); ApiAck_inspect(&a1); ApiAck_frmtr(&a1, ack_format); printf("%X %X\n", ack_format[0], ack_format[1]); printf("value float to 4 bytes: %X %X %X %X\n\n", ack_format[2] & 0x000000FF, ack_format[3] & 0x000000FF, ack_format[4] & 0x000000FF, ack_format[5] & 0x000000FF); printf("Reconstructed\n"); ApiAck_rector(&a2, ack_format); ApiAck_frmtr(&a2, ack_format2); ApiAck_inspect(&a2); printf("%X %X\n", ack_format2[0], ack_format2[1]); printf("value float to 4 bytes: %X %X %X %X\n\n", ack_format2[2] & 0x000000FF, ack_format2[3] & 0x000000FF, ack_format2[4] & 0x000000FF, ack_format2[5] & 0x000000FF); Type_enum *recovered_type2 = (Type_enum *) &a1; printf("\n\nrecovered type: %d\n\n", *recovered_type2); //TEST API NOTIFICATION CONSTRUCTOR AND RE-CONSTRUCTOR ApiNot_ctor(&n1, 1, OUTPUT, COMP, 4); char not_format[2]; char not_format2[2]; printf("ApiNot Constructor Results:\n"); ApiNot_inspect(&n1); ApiNot_frmtr(&n1, not_format); printf("%X %X\n\n", not_format[0] & 0x000000FF, not_format[1] & 0x000000FF); printf("Reconstructed\n"); ApiNot_rector(&n2, not_format); ApiNot_frmtr(&n2, not_format2); ApiNot_inspect(&n2); printf("%X %X\n\n", not_format2[0] & 0x000000FF, not_format2[1] & 0x000000FF); Type_enum *recovered_type3 = (Type_enum *) &n1; printf("\n\nrecovered type: %d\n\n", *recovered_type3); //END API TESTING //START CHANNEL TESTING printf("All API Command Tests Pass!\n"); printf("Start Channel Testing\n\n"); Channel ch1; Channel_ctor(&ch1, 1, "Ch1", ACTIVE, INPUT); //get_name test char* ptr = channel_get_name(&ch1); printf("ch1 name: %s\n\n", ptr); //set_name test channel_set_name(&ch1, "CH1!!"); char* ptr2 = channel_get_name(&ch1); printf("ch1 name: %s\n\n", ptr2); channel_inspect_full(&ch1); //test interaction with eqband EqBand* eq = channel_get_eqband(&ch1, 1); eqband_enable(eq); eqband_set_type(eq, HPF); eqband_set_band_num(eq, 5); eqband_set_bw(eq, 10.0); eqband_set_freq(eq, 1357); eqband_set_gain(eq, 4.0); EqBand* eq2 = channel_get_eqband(&ch1, 2); eqband_enable(eq2); eqband_set_type(eq2, HPF); eqband_set_band_num(eq2, 5); eqband_set_bw(eq2, 10.0); eqband_set_freq(eq2, 1357); eqband_set_gain(eq2, 4.0); EqBand* eq3 = channel_get_eqband(&ch1, 3); eqband_enable(eq3); eqband_set_type(eq3, HPF); eqband_set_band_num(eq3, 5); eqband_set_bw(eq3, 10.0); eqband_set_freq(eq3, 1357); eqband_set_gain(eq3, 4.0); EqBand* eq4 = channel_get_eqband(&ch1, 4); eqband_enable(eq4); eqband_set_type(eq4, HPF); eqband_set_band_num(eq4, 5); eqband_set_bw(eq4, 10.0); eqband_set_freq(eq4, 1357); eqband_set_gain(eq4, 4.0); eqband_inspect(channel_get_eqband(&ch1, 2)); Enable_enum en = eqband_is_enabled(eq); if(en) printf("enum values usable as boolean logic\n"); //test setting parameters in compressor Comp *comp = channel_get_comp(&ch1); comp_enable(comp); comp_set_threshold(comp, 10.0); comp_set_ratio(comp, 1.5); comp_set_attack(comp, 10); comp_set_release(comp, 500); comp_set_gain(comp, 2.0); comp_inspect(comp); //Now let's use malloc to allocate memory for a channel Channel *ch2 = malloc(sizeof *ch2); Channel_ctor(ch2, 2, "Ch2", ACTIVE, INPUT); channel_inspect_basic(ch2); free(ch2); Channel *ch01 = malloc(sizeof *ch01); Channel *ch02 = malloc(sizeof *ch02); Channel *ch03 = malloc(sizeof *ch03); Channel *ch04 = malloc(sizeof *ch04); Channel *ch05 = malloc(sizeof *ch05); Channel *ch06 = malloc(sizeof *ch06); Channel *ch07 = malloc(sizeof *ch07); Channel *ch08 = malloc(sizeof *ch08); Channel *ch09 = malloc(sizeof *ch09); Channel *ch10 = malloc(sizeof *ch10); Channel *ch11 = malloc(sizeof *ch11); Channel *ch12 = malloc(sizeof *ch12); Channel *ch13 = malloc(sizeof *ch13); Channel *ch14 = malloc(sizeof *ch14); char temp[5]; strncpy(temp, "ch01", 4); temp[4] = '\0'; strncpy(&(ch01->name[0]), "ch01", 4); ch01->name[4] = '\0'; channel_set_name(ch01, "ch01"); Matrix* matrix = malloc(sizeof(Matrix)); Channel* ch_array[14] = {ch01, ch02, ch03, ch04, ch05, ch06, ch07, ch08, ch09, ch10, ch11, ch12, ch13, ch14}; matrix_set_input_channels(matrix, ch_array[0], 14); Channel_ctor(ch02, 2, "Ch2!", ACTIVE, INPUT); channel_inspect_basic(ch_array[1]); channel_inspect_basic(ch02); // for(int i = 0; i < 13; i++) { // free (ch_array[i]); // } printf("size of ch_array: %lu bytes\n", sizeof(ch_array)); printf("size of a channel: %lu bytes\n", sizeof(Channel)); printf("size of 14 channels: %lu bytes\n", sizeof(Channel) * 14); //TEST TRANSMISSION & RECEPTION HANDLERS printf("\n\nTx&Rx Handler Testing\n\n"); //initialize the handler variables struct ApiHandlerVars handler_vars; struct ApiCmdNode* tx2_stack = malloc(sizeof(struct ApiCmdNode)); Api_init_handler_vars(&handler_vars, tx2_stack); handler_vars.cmd_counter = 17; //let's transmit the read_1 api command //have it call callbackFunction upon reception of the corresponding value Api_tx_all(&r1, &handler_vars, callbackFunction); //Let's transmit a Notification Api_register_notif_callback(&handler_vars, notif_callback); Api_tx_all(&n1, &handler_vars, NULL); //Let's transmit a Write Api_tx_all(&w1, &handler_vars, callbackFunction); //Now, Let's test out that stack list struct ApiCmdNode* tx_stack = malloc(sizeof(struct ApiCmdNode)); tx_stack->cmd_count = 5; tx_stack->next = NULL; Api_tx_stack_push(&tx_stack, &r1, r1.super.cmd_count); Api_tx_stack_push(&tx_stack, &a1, a1.super.cmd_count); Api_tx_stack_append(&tx_stack, &w1, w1.super.cmd_count); printf("cmd counts: %d %d %d\n", r2.super.cmd_count, a1.super.cmd_count, w1.super.cmd_count); printf("length of stack: %d\n\n", Api_tx_stack_length(tx_stack)); printf("next: %d %d %d\n", (int) tx_stack->next, a1.super.cmd_count, w1.super.cmd_count); struct ApiCmdNode* match = Api_tx_stack_locate(&tx_stack, r1.super.cmd_count); if (match != NULL) { ApiAck* matching = (ApiAck*) match->api_ptr; printf("\nmatching list type: %d\n", (Type_enum) ((matching->super).type)); } else { printf("\nNo match found\n"); } tx_stack = Api_tx_stack_delete(tx_stack, w1.super.cmd_count); printf("length of stack: %d\n\n", Api_tx_stack_length(tx_stack)); //WEB API COMMANDS printf("now let's try web api commands\n"); //these should work just fine char url[80] = "/a/i/chanlist"; http_process_url(url, strlen(url)); strcpy(url, "/a/i/5/eqparams"); http_process_url(url, strlen(url)); strcpy(url, "/a/o/3/compparams"); http_process_url(url, strlen(url)); strcpy(url, "/a/i/15/blah"); http_process_url(url, strlen(url)); //check for improper api command identifier strcpy(url, "/a/x/4/chanlist"); http_process_url(url, strlen(url)); //check for larger than 16 num channels error strcpy(url, "/a/i/17/chanlist"); http_process_url(url, strlen(url)); //check for wrong channel number format strcpy(url, "/a/i/1x/chanlist"); http_process_url(url, strlen(url)); //get routing matrix without error strcpy(url, "/a/m/routes"); http_process_url(url, strlen(url)); strcpy(url, "/a/s/bob"); http_process_url(url, strlen(url)); strcpy(url, "/a/s/clip"); http_process_url(url, strlen(url)); //should return error strcpy(url, "/a/s/blah"); http_process_url(url, strlen(url)); strcpy(url, "/a/m/14/modroute"); http_process_url(url, strlen(url)); strcpy(url, "/a/m/3/modroute?i=14&name=4325&blah=14.375&zenerab=1&z=98345.895"); printf("%s\n",url); http_process_url(url, strlen(url)); KeyValueMap map; map.num_values = 0; char testing[5]; strncpy(testing, "blah", 4); testing[4] = '\0'; //map_add_key_value_pair(&map, testing, 4.56789, 5); char testing2[5]; strncpy(testing2, "blag", 4); testing2[4] = '\0'; //map_add_key_value_pair(&map, testing2, 1.25, 5); char testing3[5]; strncpy(testing3, "blar", 4); testing3[4] = '\0'; //map_add_key_value_pair(&map, testing3, 12, 5); char testing4[5]; strncpy(testing4, "blag", 4); testing4[4] = '\0'; map_get_value_by_key(&map, testing4); Json* json1 = (Json*) json_encode_comp(&ch1); printf("comp encoded: %s\n\n", json1->string[0]); Json* json2 = (Json*) json_encode_eq(&ch1); printf("eq encoded: %s\n\n", json2->string[0]); Json* json3 = (Json*) json_encode_channels(ch_array, 14); printf("channels encoded: %s \n\n",json3->string[0]); char test16[10]; get_string_from_float(19590.345, test16); printf("%s\n",test16); printf("All done!"); return 0; }
extern char const * irc_convert_ircname(char const * pircname) { static char out[CHANNEL_NAME_LEN]; unsigned int outpos; int special; int i; char const * ircname = pircname + 1; if (!ircname) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL ircname"); return NULL; } outpos = 0; memset(out,0,sizeof(out)); special = 0; if (pircname[0]=='!') { t_channel * channel; channel = channellist_find_channel_bychannelid(atoi(ircname)); if (channel) return channel_get_name(channel); else return NULL; } else if (pircname[0]!='#') { return NULL; } for (i=0; ircname[i]!='\0'; i++) { if (ircname[i]=='_') { out[outpos++] = ' '; } else if (ircname[i]=='%') { if (special) { out[outpos++] = '%'; special = 0; } else { special = 1; } } else if (special) { if (ircname[i]=='_') { out[outpos++] = '_'; } else if (ircname[i]=='b') { out[outpos++] = '\b'; } else if (ircname[i]=='n') { out[outpos++] = '\n'; } else if (ircname[i]=='r') { out[outpos++] = '\r'; } else if (ircname[i]=='=') { out[outpos++] = ':'; } else if (ircname[i]=='-') { out[outpos++] = ','; } else { /* maybe it's just a typo :) */ out[outpos++] = '%'; out[outpos++] = ircname[i]; } } else { out[outpos++] = ircname[i]; } if ((outpos+2)>=(sizeof(out))) { return NULL; } } return out; }