int mcp_frame_package_docallback(McpFrame * mfr, McpMesg * msg) { McpPkg *ptr = NULL; if (!strcmp_nocase(msg->package, MCP_INIT_PKG)) { mcp_basic_handler(mfr, msg, NULL); } else { if (!mfr->enabled) { return EMCP_NOMCP; } for (ptr = mfr->packages; ptr; ptr = ptr->next) { if (!strcmp_nocase(ptr->pkgname, msg->package)) { break; } } if (!ptr) { if (!strcmp_nocase(msg->package, MCP_NEGOTIATE_PKG)) { McpVer twooh = { 2, 0 }; mcp_negotiate_handler(mfr, msg, twooh, NULL); } else { return EMCP_NOPACKAGE; } } else { ptr->callback(mfr, msg, ptr->maxver, ptr->context); } } return EMCP_SUCCESS; }
void mcp_frame_package_remove(McpFrame * mfr, const char *package) { McpPkg *tmp; McpPkg *prev; while (mfr->packages && !strcmp_nocase(mfr->packages->pkgname, package)) { tmp = mfr->packages; mfr->packages = tmp->next; if (tmp->pkgname) free(tmp->pkgname); free(tmp); } prev = mfr->packages; while (prev && prev->next) { if (!strcmp_nocase(prev->next->pkgname, package)) { tmp = prev->next; prev->next = tmp->next; if (tmp->pkgname) free(tmp->pkgname); free(tmp); } else { prev = prev->next; } } }
ngram_file_type_t ngram_file_name_to_type(const char *file_name) { const char *ext; ext = strrchr(file_name, '.'); if (ext == NULL) { return NGRAM_INVALID; } if (0 == strcmp_nocase(ext, ".gz")) { while (--ext >= file_name) { if (*ext == '.') break; } if (ext < file_name) { return NGRAM_INVALID; } } else if (0 == strcmp_nocase(ext, ".bz2")) { while (--ext >= file_name) { if (*ext == '.') break; } if (ext < file_name) { return NGRAM_INVALID; } } /* We use strncmp because there might be a .gz on the end. */ if (0 == strncmp_nocase(ext, ".ARPA", 5)) return NGRAM_ARPA; if (0 == strncmp_nocase(ext, ".DMP", 4) || 0 == strncmp_nocase(ext, ".BIN", 4)) return NGRAM_BIN; return NGRAM_INVALID; }
void mcp_mesg_arg_remove(McpMesg * msg, const char *argname) { McpArg *ptr = msg->args; McpArg *prev = NULL; while (ptr && !strcmp_nocase(ptr->name, argname)) { msg->args = ptr->next; msg->bytes -= sizeof(McpArg); if (ptr->name) { free(ptr->name); msg->bytes -= strlen(ptr->name) + 1; } while (ptr->value) { McpArgPart *ptr2 = ptr->value; ptr->value = ptr->value->next; msg->bytes -= sizeof(McpArgPart); if (ptr2->value) { msg->bytes -= strlen(ptr2->value) + 1; free(ptr2->value); } free(ptr2); } free(ptr); ptr = msg->args; } prev = msg->args; if (ptr) ptr = ptr->next; while (ptr) { if (!strcmp_nocase(argname, ptr->name)) { prev->next = ptr->next; msg->bytes -= sizeof(McpArg); if (ptr->name) { free(ptr->name); msg->bytes -= strlen(ptr->name) + 1; } while (ptr->value) { McpArgPart *ptr2 = ptr->value; ptr->value = ptr->value->next; msg->bytes -= sizeof(McpArgPart); if (ptr2->value) { msg->bytes -= strlen(ptr2->value) + 1; free(ptr2->value); } free(ptr2); } free(ptr); ptr = prev->next; } else { prev = ptr; ptr = ptr->next; } } }
ngram_file_type_t ngram_str_to_type(const char *str_name) { if (0 == strcmp_nocase(str_name, "arpa")) return NGRAM_ARPA; if (0 == strcmp_nocase(str_name, "dmp")) return NGRAM_DMP; return NGRAM_INVALID; }
static int32 cmp_name(const void *a, const void *b) { return (strcmp_nocase ((* (arg_t**) a)->name, (* (arg_t**) b)->name)); }
int maincsm_onmessage(CSM_RAM* data, GBS_MSG* msg) { if (msg->msg == MSG_RECONFIGURE_REQ) { if (strcmp_nocase(successed_config_filename, (char*)msg->data0) == 0) InitConfig(); } return 1; }
bool _expr_str::match(scanner& s, context& c) const { if(s.eof()) return false; std::string str = s.str(s.pos(), s.pos() + str_.size()); if((!nocase_ && str == str_) || (nocase_ && strcmp_nocase(str, str_) == 0)){ s.advance(str_.size()); return true; } return false; }
void mcp_frame_package_renegotiate(const char* package) { McpVer nullver = { 0, 0 }; McpFrameList* mfrl = mcp_frame_list; McpFrame* mfr; McpMesg cando; char verbuf[32]; McpPkg *p; p = mcp_PackageList; while (p) { if (!strcmp_nocase(p->pkgname, package)) { break; } p = p->next; } if (!p) { mcp_mesg_init(&cando, MCP_NEGOTIATE_PKG, "can"); mcp_mesg_arg_append(&cando, "package", package); mcp_mesg_arg_append(&cando, "min-version", "0.0"); mcp_mesg_arg_append(&cando, "max-version", "0.0"); } else { mcp_mesg_init(&cando, MCP_NEGOTIATE_PKG, "can"); mcp_mesg_arg_append(&cando, "package", p->pkgname); snprintf(verbuf, sizeof(verbuf), "%d.%d", p->minver.vermajor, p->minver.verminor); mcp_mesg_arg_append(&cando, "min-version", verbuf); snprintf(verbuf, sizeof(verbuf), "%d.%d", p->maxver.vermajor, p->maxver.verminor); mcp_mesg_arg_append(&cando, "max-version", verbuf); } while (mfrl) { mfr = mfrl->mfr; if (mfr->enabled) { if (mcp_version_compare(mfr->version, nullver) > 0) { mcp_frame_package_remove(mfr, package); mcp_frame_output_mesg(mfr, &cando); } } mfrl = mfrl->next; } mcp_mesg_clear(&cando); /* mcp_mesg_init(&cando, MCP_NEGOTIATE_PKG, "end"); mcp_frame_output_mesg(mfr, &cando); mcp_mesg_clear(&cando); */ }
void mcp_package_deregister(const char *pkgname) { McpPkg *ptr = mcp_PackageList; McpPkg *prev = NULL; while (ptr && !strcmp_nocase(ptr->pkgname, pkgname)) { mcp_PackageList = ptr->next; if (ptr->cleanup) ptr->cleanup(ptr->context); if (ptr->pkgname) free(ptr->pkgname); free(ptr); ptr = mcp_PackageList; } prev = mcp_PackageList; if (ptr) ptr = ptr->next; while (ptr) { if (!strcmp_nocase(pkgname, ptr->pkgname)) { prev->next = ptr->next; if (ptr->cleanup) ptr->cleanup(ptr->context); if (ptr->pkgname) free(ptr->pkgname); free(ptr); ptr = prev->next; } else { prev = ptr; ptr = ptr->next; } } mcp_frame_package_renegotiate(pkgname); }
int PKI_X509_CRL_REASON_CODE_get ( const char * st ) { int ret = -1; int i = 0; if ( !st ) return ret; for ( i = 0; i < PKI_X509_CRL_REASON_CODE_num(); i++ ) { if( strcmp_nocase( (char *) st, (char *) PKI_X509_CRL_REASON_DESCR[i].name ) == 0 ) { ret = PKI_X509_CRL_REASON_DESCR[i].code; break; } } return ret; };
static char * _ext_txt ( unsigned char * str ) { char ** pnt = NULL; if( !str ) return ( NULL ); pnt = ext_txt_db; while ( *pnt != NULL ) { if( (strcmp_nocase( (char * )str, *pnt ) == 0 ) && ( strlen( (char *) str ) == strlen( *pnt ))) { return ( *pnt ); } pnt++; } return ( (char *) str ); }
int mcp_mesg_arg_linecount(McpMesg * msg, const char *name) { McpArg *ptr = msg->args; int cnt = 0; while (ptr && strcmp_nocase(ptr->name, name)) { ptr = ptr->next; } if (ptr) { McpArgPart *ptr2 = ptr->value; while (ptr2) { ptr2 = ptr2->next; cnt++; } } return cnt; }
int mcp_frame_package_add(McpFrame * mfr, const char *package, McpVer minver, McpVer maxver) { McpPkg *nu; McpPkg *ptr; McpVer selver; if (!mfr->enabled) { return EMCP_NOMCP; } for (ptr = mcp_PackageList; ptr; ptr = ptr->next) { if (!strcmp_nocase(ptr->pkgname, package)) { break; } } if (!ptr) { return EMCP_NOPACKAGE; } mcp_frame_package_remove(mfr, package); selver = mcp_version_select(ptr->minver, ptr->maxver, minver, maxver); nu = (McpPkg *) malloc(sizeof(McpPkg)); nu->pkgname = string_dup(ptr->pkgname); nu->minver = selver; nu->maxver = selver; nu->callback = ptr->callback; nu->context = ptr->context; nu->next = NULL; if (!mfr->packages) { mfr->packages = nu; } else { McpPkg *lastpkg = mfr->packages; while (lastpkg->next) lastpkg = lastpkg->next; lastpkg->next = nu; } return EMCP_SUCCESS; }
McpVer mcp_frame_package_supported(McpFrame * mfr, const char *package) { McpPkg *ptr; McpVer errver = { 0, 0 }; if (!mfr->enabled) { return errver; } for (ptr = mfr->packages; ptr; ptr = ptr->next) { if (!strcmp_nocase(ptr->pkgname, package)) { break; } } if (!ptr) { return errver; } return (ptr->minver); }
char * mcp_mesg_arg_getline(McpMesg * msg, const char *argname, int linenum) { McpArg *ptr = msg->args; while (ptr && strcmp_nocase(ptr->name, argname)) { ptr = ptr->next; } if (ptr) { McpArgPart *ptr2 = ptr->value; while (linenum > 0 && ptr2) { ptr2 = ptr2->next; linenum--; } if (ptr2) { return (ptr2->value); } return NULL; } return NULL; }
int bin_mdef_ciphone_id_nocase(bin_mdef_t * m, const char *ciphone) { int low, mid, high; /* Exact binary search on m->ciphone */ low = 0; high = m->n_ciphone; while (low < high) { int c; mid = (low + high) / 2; c = strcmp_nocase(ciphone, m->ciname[mid]); if (c == 0) return mid; else if (c > 0) low = mid + 1; else if (c < 0) high = mid; } return -1; }
/* ---------------------------------------------------------------------- */ int spread_row_to_solution (struct spread_row *heading, struct spread_row *units, struct spread_row *data, struct defaults defaults) /* ---------------------------------------------------------------------- */ { int i, j, n, l, next_keyword_save; int n_user, n_user_end; int default_pe, alk; int count_isotopes; int max_mass_balance, count_mass_balance; char *ptr, *ptr1; char *description; char token[MAX_LENGTH], token1[MAX_LENGTH]; char string[2 * MAX_LENGTH]; LDBLE dummy; int return_value, opt; char *next_char; const char *opt_list[] = { "temp", /* 0 */ "temperature", /* 1 */ "dens", /* 2 */ "density", /* 3 */ "units", /* 4 */ "redox", /* 5 */ "ph", /* 6 */ "pe", /* 7 */ "unit", /* 8 */ "isotope", /* 9 */ "water", /* 10 */ "description", /* 11 */ "desc", /* 12 */ "descriptor" /* 13 */ }; int count_opt_list = 14; /* * look for solution number */ n_user = -1; n_user_end = -1; description = string_duplicate (""); for (i = 0; i < heading->count; i++) { if (strcmp_nocase (heading->char_vector[i], "number") == 0) { break; } } if (i == heading->count || data->type_vector[i] == EMPTY || data->count <= i) { n_user = -1; #ifdef SKIP for (i = 0; i < count_solution; i++) { if (n_user <= solution[i]->n_user) { n_user = solution[i]->n_user + 1; } } #endif } else if (data->type_vector[i] == STRING) { input_error++; sprintf (error_string, "Expected solution number or number range in 'number' column, found: %s.", data->char_vector[i]); error_msg (error_string, CONTINUE); } else { strcpy (string, "solution_s "); strcat (string, data->char_vector[i]); ptr = string; description = (char *) free_check_null (description); next_keyword_save = next_keyword; next_keyword = 42; read_number_description (ptr, &n_user, &n_user_end, &description); next_keyword = next_keyword_save; } /* * set up solution */ if (n_user >= 0 && solution_bsearch (n_user, &n, FALSE) != NULL) { solution_free (solution[n]); } else { n = count_solution++; if (count_solution >= max_solution) { space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *)); } } solution[n] = solution_alloc (); solution[n]->n_user = n_user; solution[n]->n_user_end = n_user_end; if (use.solution_in == FALSE) { use.solution_in = TRUE; use.n_solution_user = n_user; } max_mass_balance = MAX_MASS_BALANCE; /* * Set default ph, temp, density, pe, units */ solution[n]->description = description; solution[n]->tc = defaults.temp; solution[n]->ph = defaults.ph; solution[n]->density = defaults.density; solution[n]->solution_pe = defaults.pe; solution[n]->mass_water = defaults.water; solution[n]->ah2o = 1.0; solution[n]->mu = 1e-7; solution[n]->cb = 0.0; default_pe = 0; solution[n]->units = defaults.units; solution[n]->totals[0].description = NULL; count_mass_balance = 0; count_isotopes = 0; default_pe = pe_data_store (&(solution[n]->pe), defaults.redox); /* * Read concentration data */ return_value = UNKNOWN; for (i = 0; i < heading->count; i++) { if (strcmp_nocase (heading->char_vector[i], "number") == 0) continue; if (strcmp_nocase (heading->char_vector[i], "uncertainty") == 0) continue; if (strcmp_nocase (heading->char_vector[i], "uncertainties") == 0) continue; if (strcmp_nocase (heading->char_vector[i], "isotope_uncertainty") == 0) continue; /* * Copy in element name */ if (heading->type_vector[i] == EMPTY) continue; strcpy (string, heading->char_vector[i]); strcat (string, " "); /* * Copy in concentration data */ if (i >= data->count || data->type_vector[i] == EMPTY) continue; strcat (string, data->char_vector[i]); strcat (string, " "); /* * Copy in concentration data */ if (units != NULL && i < units->count && units->type_vector[i] != EMPTY) { strcat (string, units->char_vector[i]); } /* * Parse string just like read_solution input */ next_char = string; opt = get_option_string (opt_list, count_opt_list, &next_char); if (opt == OPTION_DEFAULT && heading->type_vector[i] == NUMBER) { opt = 9; } switch (opt) { case OPTION_EOF: /* end of file */ return_value = EOF; break; case OPTION_KEYWORD: /* keyword */ return_value = KEYWORD; break; case OPTION_ERROR: input_error++; error_msg ("Unknown input in SOLUTION keyword.", CONTINUE); error_msg (line_save, CONTINUE); break; case 0: /* temperature */ case 1: sscanf (next_char, SCANFORMAT, &(solution[n]->tc)); break; case 2: /* density */ case 3: sscanf (next_char, SCANFORMAT, &(solution[n]->density)); break; case 4: /* units */ case 8: /* unit */ if (copy_token (token, &next_char, &l) == EMPTY) break; if (check_units (token, FALSE, FALSE, solution[n]->units, TRUE) == OK) { solution[n]->units = string_hsave (token); } else { input_error++; } break; case 5: /* redox */ if (copy_token (token, &next_char, &l) == EMPTY) break; if (parse_couple (token) == OK) { default_pe = pe_data_store (&(solution[n]->pe), token); } else { input_error++; } break; case 6: /* ph */ next_char = string; if (read_conc (n, count_mass_balance, next_char) == ERROR) { input_error++; break; } solution[n]->ph = solution[n]->totals[count_mass_balance].input_conc; if (solution[n]->totals[count_mass_balance].equation_name == NULL) { break; } solution[n]->totals[count_mass_balance].description = string_hsave ("H(1)"); count_mass_balance++; break; case 7: /* pe */ next_char = string; if (read_conc (n, count_mass_balance, next_char) == ERROR) { input_error++; break; } solution[n]->solution_pe = solution[n]->totals[count_mass_balance].input_conc; if (solution[n]->totals[count_mass_balance].equation_name == NULL) { break; } solution[n]->totals[count_mass_balance].description = string_hsave ("E"); count_mass_balance++; break; case 9: /* isotope */ next_char = string; if (copy_token (token, &next_char, &l) != DIGIT) { input_error++; sprintf (error_string, "Expected isotope name to" " begin with an isotopic number."); error_msg (error_string, CONTINUE); continue; } solution[n]->isotopes = (struct isotope *) PHRQ_realloc (solution[n]->isotopes, (size_t) (count_isotopes + 1) * sizeof (struct isotope)); if (solution[n]->isotopes == NULL) malloc_error (); /* read and save element name */ ptr1 = token; get_num (&ptr1, &(solution[n]->isotopes[count_isotopes].isotope_number)); if (ptr1[0] == '\0' || isupper ((int) ptr1[0]) == FALSE) { error_msg ("Expecting element name.", CONTINUE); error_msg (line_save, CONTINUE); input_error++; return (ERROR); } solution[n]->isotopes[count_isotopes].elt_name = string_hsave (ptr1); /* read and store isotope ratio */ if (copy_token (token, &next_char, &l) != DIGIT) { input_error++; sprintf (error_string, "Expected numeric value for isotope ratio."); error_msg (error_string, CONTINUE); continue; } sscanf (token, SCANFORMAT, &(solution[n]->isotopes[count_isotopes].ratio)); /* read and store isotope ratio uncertainty */ /* first choice is next column */ if ((i + 1) < heading->count && (strcmp_nocase (heading->char_vector[i + 1], "uncertainty") == 0 || strcmp_nocase (heading->char_vector[i + 1], "isotope_uncertainty") == 0 || strcmp_nocase (heading->char_vector[i + 1], "uncertainties") == 0) && (i + 1) < data->count && data->type_vector[i + 1] == NUMBER) { solution[n]->isotopes[count_isotopes].ratio_uncertainty = data->d_vector[i + 1]; } else { next_char = string; copy_token (token, &next_char, &l); for (j = 0; j < defaults.count_iso; j++) { if (strcmp (token, defaults.iso[j].name) == 0) { solution[n]->isotopes[count_isotopes].ratio_uncertainty = defaults.iso[j].uncertainty; break; } } if (j == defaults.count_iso) { solution[n]->isotopes[count_isotopes].ratio_uncertainty = NAN; } } count_isotopes++; break; case 10: /* water */ j = copy_token (token, &next_char, &l); if (j == EMPTY) { solution[n]->mass_water = 1.0; } else if (j != DIGIT) { input_error++; sprintf (error_string, "Expected numeric value for mass of water in solution."); error_msg (error_string, CONTINUE); } else { sscanf (token, SCANFORMAT, &dummy); solution[n]->mass_water = (LDBLE) dummy; } break; case 11: /* description */ case 12: /* desc */ case 13: /* descriptor */ solution[n]->description = (char *) free_check_null (solution[n]->description); solution[n]->description = string_duplicate (next_char); break; case OPTION_DEFAULT: /* * Read concentration */ next_char = string; if (copy_token (token, &next_char, &l) == LOWER) continue; next_char = string; if (read_conc (n, count_mass_balance, next_char) == ERROR) { #ifdef SKIP input_error++; break; #endif } count_mass_balance++; break; } if (count_mass_balance + 1 >= max_mass_balance) { space ((void **) ((void *) &(solution[n]->totals)), count_mass_balance + 1, &max_mass_balance, sizeof (struct conc)); } if (return_value == EOF || return_value == KEYWORD) break; } /* * Sort totals by description */ qsort (solution[n]->totals, (size_t) count_mass_balance, (size_t) sizeof (struct conc), conc_compare); /* * fix up default units and default pe */ for (i = 0; i < count_mass_balance; i++) { strcpy (token, solution[n]->totals[i].description); str_tolower (token); if (solution[n]->totals[i].units == NULL) { solution[n]->totals[i].units = solution[n]->units; } else { alk = FALSE; if (strstr (token, "alk") == token) alk = TRUE; strcpy (token1, solution[n]->totals[i].units); if (check_units (token1, alk, TRUE, solution[n]->units, TRUE) == ERROR) { input_error++; } else { solution[n]->totals[i].units = string_hsave (token1); } } if (solution[n]->totals[i].n_pe < 0) { solution[n]->totals[i].n_pe = default_pe; } } solution[n]->default_pe = default_pe; /* * Mark end of solution */ solution[n]->totals[count_mass_balance].description = NULL; solution[n]->count_isotopes = count_isotopes; if (count_isotopes > 0) { qsort (solution[n]->isotopes, (size_t) count_isotopes, (size_t) sizeof (struct isotope), isotope_compare); } else { solution[n]->isotopes = (struct isotope *) free_check_null (solution[n]->isotopes); } return (return_value); }
unsigned int GetExtUid(const char *ext) { unsigned int uid = 0; unsigned int len = strlen(ext); if (!len) return uid; if (strcmp_nocase(ext, "mp3") == 0) uid = UID_MP3; else if (strcmp_nocase(ext, "m3u") == 0) uid = UID_M3U; else if (strcmp_nocase(ext, "jar") == 0) uid = UID_JAR; else if (strcmp_nocase(ext, "jad") == 0) uid = UID_JAD; else if (strcmp_nocase(ext, "mid") == 0) uid = UID_MID; else if (strcmp_nocase(ext, "amr") == 0) uid = UID_AMR; else if (strcmp_nocase(ext, "imy") == 0) uid = UID_IMY; else if (strcmp_nocase(ext, "srt") == 0) uid = UID_SRT; else if (strcmp_nocase(ext, "aac") == 0) uid = UID_AAC; else if (strcmp_nocase(ext, "wav") == 0) uid = UID_WAV; else if (strcmp_nocase(ext, "jts") == 0) uid = UID_JTS; else if (strcmp_nocase(ext, "xmf") == 0) uid = UID_XMF; else if (strcmp_nocase(ext, "m4a") == 0) uid = UID_M4A; else if (strcmp_nocase(ext, "bmx") == 0) uid = UID_BMX; else if (strcmp_nocase(ext, "wbmp") == 0) uid = UID_WBMP; else if (strcmp_nocase(ext, "bmp") == 0) uid = UID_BMP; else if (strcmp_nocase(ext, "jpg") == 0) uid = UID_JPG; else if (strcmp_nocase(ext, "jpeg") == 0) uid = UID_JPG; else if (strcmp_nocase(ext, "png") == 0) uid = UID_PNG; else if (strcmp_nocase(ext, "gif") == 0) uid = UID_GIF; else if (strcmp_nocase(ext, "svg") == 0) uid = UID_SVG; else if (strcmp_nocase(ext, "3gp") == 0) uid = UID_3GP; else if (strcmp_nocase(ext, "mp4") == 0) uid = UID_M4A; else if (strcmp_nocase(ext, "sdp") == 0) uid = UID_SDP; else if (strcmp_nocase(ext, "pvx") == 0) uid = UID_PVX; else if (strcmp_nocase(ext, "sdt") == 0) uid = UID_SDT; else if (strcmp_nocase(ext, "ldb") == 0) uid = UID_LDB; else if (strcmp_nocase(ext, "txt") == 0) uid = UID_TXT; else if (strcmp_nocase(ext, "url") == 0) uid = UID_URL; return uid; }
int mcp_frame_output_mesg(McpFrame * mfr, McpMesg * msg) { char outbuf[BUFFER_LEN * 2]; int bufrem = sizeof(outbuf); char mesgname[128]; char datatag[32]; McpArg *anarg = NULL; int mlineflag = 0; char *p; char *out; int flushcount = 8; if (!mfr->enabled && strcmp_nocase(msg->package, MCP_INIT_PKG)) { return EMCP_NOMCP; } /* Create the message name from the package and message subnames */ if (msg->mesgname && *msg->mesgname) { snprintf(mesgname, sizeof(mesgname), "%s-%s", msg->package, msg->mesgname); } else { snprintf(mesgname, sizeof(mesgname), "%s", msg->package); } strcpyn(outbuf, sizeof(outbuf), MCP_MESG_PREFIX); strcatn(outbuf, sizeof(outbuf), mesgname); if (strcmp_nocase(mesgname, MCP_INIT_PKG)) { McpVer nullver = { 0, 0 }; strcatn(outbuf, sizeof(outbuf), " "); strcatn(outbuf, sizeof(outbuf), mfr->authkey); if (strcmp_nocase(msg->package, MCP_NEGOTIATE_PKG)) { McpVer ver = mcp_frame_package_supported(mfr, msg->package); if (!mcp_version_compare(ver, nullver)) { return EMCP_NOPACKAGE; } } } /* If the argument lines contain newlines, split them into separate lines. */ for (anarg = msg->args; anarg; anarg = anarg->next) { if (anarg->value) { McpArgPart *ap = anarg->value; while (ap) { p = ap->value; while (*p) { if (*p == '\n' || *p == '\r') { McpArgPart *nu = (McpArgPart *) malloc(sizeof(McpArgPart)); nu->next = ap->next; ap->next = nu; *p++ = '\0'; nu->value = string_dup(p); ap->value = (char *) realloc(ap->value, strlen(ap->value) + 1); ap = nu; p = nu->value; } else { p++; } } ap = ap->next; } } } /* Build the initial message string */ out = outbuf; bufrem = outbuf + sizeof(outbuf) - out; for (anarg = msg->args; anarg; anarg = anarg->next) { out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; if (!anarg->value) { anarg->was_shown = 1; snprintf(out, bufrem, " %s: %s", anarg->name, MCP_ARG_EMPTY); out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; } else { int totlen = strlen(anarg->value->value) + strlen(anarg->name) + 5; if (anarg->value->next || totlen > ((BUFFER_LEN - (out - outbuf)) / 2)) { /* Value is multi-line or too long. Send on separate line(s). */ mlineflag = 1; anarg->was_shown = 0; snprintf(out, bufrem, " %s*: %s", anarg->name, MCP_ARG_EMPTY); } else { anarg->was_shown = 1; snprintf(out, bufrem, " %s: ", anarg->name); out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; msgarg_escape(out, bufrem, anarg->value->value); out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; } out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; } } /* If the message is multi-line, make sure it has a _data-tag field. */ if (mlineflag) { snprintf(datatag, sizeof(datatag), "%.8lX", (unsigned long)(RANDOM() ^ RANDOM())); snprintf(out, bufrem, " %s: %s", MCP_DATATAG, datatag); out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; } /* Send the initial line. */ SendText(mfr, outbuf); SendText(mfr, "\r\n"); if (mlineflag) { /* Start sending arguments whose values weren't already sent. */ /* This is usually just multi-line argument values. */ for (anarg = msg->args; anarg; anarg = anarg->next) { if (!anarg->was_shown) { McpArgPart *ap = anarg->value; while (ap) { *outbuf = '\0'; snprintf(outbuf, sizeof(outbuf), "%s* %s %s: %s", MCP_MESG_PREFIX, datatag, anarg->name, ap->value); SendText(mfr, outbuf); SendText(mfr, "\r\n"); if (!--flushcount) { FlushText(mfr); flushcount = 8; } ap = ap->next; } } } /* Let the other side know we're done sending multi-line arg vals. */ snprintf(outbuf, sizeof(outbuf), "%s: %s", MCP_MESG_PREFIX, datatag); SendText(mfr, outbuf); SendText(mfr, "\r\n"); } return EMCP_SUCCESS; }
int main(int argc, char *argv[]) { PKI_X509 *sigObj = NULL; PKI_X509 *obj = NULL; PKI_X509_KEYPAIR *kp = NULL; PKI_X509_KEYPAIR_VALUE *pVal = NULL; // PKI_X509_SIGNATURE *sig = NULL; PKI_ALGOR *algor = NULL; PKI_OID *oid = NULL; char *pnt = NULL; char *sigName = NULL; char *kName = NULL; int nid = 0; if(argv[0]) prg_name = strdup(argv[0]); // Check the number of Arguments if ( argc < 2 ) usage(); while( argc > 0 ) { argv++; argc--; if((pnt = *argv) == NULL) break; if( strcmp_nocase( pnt, "-in" ) == 0) { if( ++argv == NULL ) usage(); sigName = *argv; argc--; } else if ( strcmp_nocase(pnt, "-signer") == 0) { if( ++argv == NULL ) usage(); kName = *argv; argc--; } else if ( strcmp_nocase(pnt, "-h") == 0 ) { usage(); } else { fprintf(stderr, "\n ERROR: unknown param %s\n\n", pnt); usage(); }; }; if( !sigName ) sigName = "stdin"; if( !kName ) { fprintf( stderr, "\n ERROR, signer param is needed!\n\n"); usage(); }; // Init LibPKI PKI_init_all(); // Loads the Signer's Object obj = PKI_X509_get( kName, PKI_DATATYPE_ANY, NULL, NULL); if( obj == NULL) { fprintf(stderr, "ERROR, can not load key source: %s\n\n", kName); exit(1); } // Loads the Signed Object sigObj = PKI_X509_get( sigName, PKI_DATATYPE_ANY, NULL, NULL); if( sigObj == NULL) { fprintf(stderr, "ERROR, can not load signed Object: %s\n\n", kName); exit(1); } // Check if the Object is signed (has a signature ?) if ( PKI_X509_is_signed ( sigObj ) != PKI_OK ) { fprintf(stderr, "ERROR, object (%s) is not signed!\n\n", sigName); exit(1); } // Get the Key from the Key Source switch ( PKI_X509_get_type( obj )) { case PKI_DATATYPE_X509_KEYPAIR: kp = obj; break; case PKI_DATATYPE_X509_CERT: pVal = PKI_X509_get_data ( obj, PKI_X509_DATA_PUBKEY ); if ( !pVal ) { fprintf(stderr, "ERROR, can not retrieve the PubKey!\n\n"); exit(1); }; kp = PKI_X509_new_value ( PKI_DATATYPE_X509_KEYPAIR, pVal, NULL ); break; default: fprintf(stderr, "ERROR, (%s) not a cert or a key (%d)!\n\n", kName, PKI_X509_get_type( obj ) ); exit(1); } if (!kp) { fprintf( stderr, "ERROR, no key found in %s!\n\n", kName ); exit(1); }; printf("Signature:\n Info:\n"); printf(" Signed Object Type:\n %s\n", PKI_X509_get_type_parsed( sigObj )); algor = PKI_X509_get_data ( sigObj, PKI_X509_DATA_ALGORITHM ); if ( algor ) { printf(" Algorithm:\n %s\n", PKI_ALGOR_get_parsed ( algor )); }; printf("\n Signer's Key Info:\n"); printf(" Scheme: "); switch ( PKI_X509_KEYPAIR_get_scheme( kp )) { case PKI_SCHEME_RSA: printf("RSA\n"); break; case PKI_SCHEME_DSA: printf("DSA\n"); break; case PKI_SCHEME_ECDSA: printf("ECDSA\n"); nid = PKI_X509_KEYPAIR_get_curve ( kp ); if((oid = PKI_OID_new_id( nid )) != NULL ) { printf(" Curve Name: %s\n", PKI_OID_get_descr( oid )); PKI_OID_free ( oid ); }; break; default: printf("Unknown!\n"); exit(1); }; printf(" Key Size: %d\n", PKI_X509_KEYPAIR_get_size( kp )); printf("\n Verify: "); if( PKI_X509_verify(sigObj, kp) == PKI_OK) { printf("Ok\n"); } else { printf("ERROR!\n"); }; printf("\n"); return 0; }
PKI_X509_PRQP_RESP * PKI_DISCOVER_get_resp_url ( PKI_X509_PRQP_REQ *p, URL *url ) { PKI_X509_PRQP_RESP * ret = NULL; char line[1024], name[1024], addr[1024]; FILE *file; if( !p || !p->value ) { PKI_log_debug( "WARNING, no PRQP request when trying to get" " the response!"); return ( NULL ); } if( url ) { if (( ret = PKI_X509_PRQP_RESP_get_http ( url, p, 0)) != NULL ) { return ret; } else { return NULL; } } file = fopen( PKI_PRQP_LIB_CONF_FILE, "r"); if( !file ) { PKI_log_debug( "WARNING, PRQP config file %s not found!", PKI_PRQP_LIB_CONF_FILE ); return ( NULL ); } while(!feof(file)) { if( fgets(line, sizeof(line), file) ) { if((memcmp(line, ";", 1) == 0) || (memcmp(line, "#", 1) == 0)) continue; if(sscanf(line, "%1024s %1024s", name, addr ) > 1 ) { char *full_url_s = NULL; size_t full_len = 0; if((strcmp_nocase( name, PKI_PRQP_LIB_CONF_ENTRY_LONG)==0) || (strcmp_nocase ( name, PKI_PRQP_LIB_CONF_ENTRY_SHORT ) == 0)) { URL *l_url = NULL; full_len = sizeof( addr ) + 12; full_url_s = PKI_Malloc ( full_len ); snprintf( full_url_s, full_len, "http://%s", addr ); if ( strchr ( addr, ':') == NULL ) { strncat ( full_url_s, ":830", full_len ); } PKI_log_debug( "Trying PRQP RQA -> %s", full_url_s ); if((l_url = URL_new( full_url_s )) == NULL) { PKI_log_debug("Can not parse address %s", full_url_s ); PKI_Free ( full_url_s ); continue; } if( l_url->port <= 0 ) l_url->port = PKI_PRQP_DEFAULT_PORT; l_url->proto = URI_PROTO_HTTP; ret = PKI_X509_PRQP_RESP_get_http ( l_url, p, 0); PKI_Free ( full_url_s ); if( ret == NULL ) { PKI_log( PKI_LOG_ERR, "Can not get response " "from server (%s:%d)!", l_url->addr, l_url->port); URL_free ( l_url ); } else { /* Exit the cycle */ PKI_log_debug("Got PRQP response from server"); URL_free ( l_url ); fclose(file); return ret; } } } } } fclose(file); return ret; }
int mcp_intern_is_mesg_start(McpFrame * mfr, const char *in) { char mesgname[128]; char authkey[128]; char *subname = NULL; McpMesg *newmsg = NULL; McpPkg *pkg = NULL; int longlen = 0; if (!mcp_intern_is_ident(&in, mesgname, sizeof(mesgname))) return 0; if (strcmp_nocase(mesgname, MCP_INIT_PKG)) { if (!isspace(*in)) return 0; while (isspace(*in)) in++; if (!mcp_intern_is_unquoted(&in, authkey, sizeof(authkey))) return 0; if (strcmp(authkey, mfr->authkey)) return 0; } if (strncmp_nocase(mesgname, MCP_INIT_PKG, 3)) { for (pkg = mfr->packages; pkg; pkg = pkg->next) { int pkgnamelen = strlen(pkg->pkgname); if (!strncmp_nocase(pkg->pkgname, mesgname, pkgnamelen)) { if (mesgname[pkgnamelen] == '\0' || mesgname[pkgnamelen] == '-') { if (pkgnamelen > longlen) { longlen = pkgnamelen; } } } } } if (!longlen) { int neglen = strlen(MCP_NEGOTIATE_PKG); if (!strncmp_nocase(mesgname, MCP_NEGOTIATE_PKG, neglen)) { longlen = neglen; } else if (!strcmp_nocase(mesgname, MCP_INIT_PKG)) { longlen = strlen(mesgname); } else { return 0; } } subname = mesgname + longlen; if (*subname) { *subname++ = '\0'; } newmsg = (McpMesg *) malloc(sizeof(McpMesg)); mcp_mesg_init(newmsg, mesgname, subname); while (*in) { if (!mcp_intern_is_keyval(newmsg, &in)) { mcp_mesg_clear(newmsg); free(newmsg); return 0; } } /* Okay, we've recieved a valid message. */ if (newmsg->incomplete) { /* It's incomplete. Remember it to finish later. */ const char *msgdt = mcp_mesg_arg_getline(newmsg, MCP_DATATAG, 0); newmsg->datatag = string_dup(msgdt); mcp_mesg_arg_remove(newmsg, MCP_DATATAG); newmsg->next = mfr->messages; mfr->messages = newmsg; } else { /* It's complete. Execute the callback function for this package. */ mcp_frame_package_docallback(mfr, newmsg); mcp_mesg_clear(newmsg); free(newmsg); } return 1; }
/* * See read_boulder.h for description. */ int read_record(FILE *file_input, const int *strict_tags, const int *io_version, int echo_output, const p3_file_type read_file_type, p3_global_settings *pa, seq_args *sa, pr_append_str *glob_err, /* Really should be called fatal_parse_err */ pr_append_str *nonfatal_parse_err) { int line_len; /* seq_len; n_quality; */ int tag_len, datum_len; int data_found = 0; p3_file_type file_type = all_parameters; int pick_internal_oligo = 2; char *s, *n, *datum, *task_tmp = NULL; const char *p; pr_append_str *parse_err; pr_append_str *non_fatal_err; char *repeat_file_path = NULL, *int_repeat_file_path = NULL; /* FIX ME call p3_create_seq_args inside read_boulder? */ non_fatal_err = nonfatal_parse_err; while ((s = p3_read_line(file_input)) != NULL && strcmp(s,"=")) { /* Deal with the file headers */ if ((strcmp(s,"Primer3 File - http://primer3.sourceforge.net")) == 0) { /* read FILE_TYPE */ if ((s = p3_read_line(file_input)) == NULL && !(strcmp(s,"="))) break; if ((strcmp(s,"P3_FILE_TYPE=all_parameters")) == 0) { file_type = all_parameters; } else if ((strcmp(s,"P3_FILE_TYPE=sequence")) == 0) { file_type = sequence; } else if ((strcmp(s,"P3_FILE_TYPE=settings")) == 0) { file_type = settings; } else { pr_append_new_chunk(glob_err, "Unknown P3_FILE_TYPE"); } /* read the empty line */ if ((s = p3_read_line(file_input)) == NULL && !(strcmp(s,"="))) break; /* Check if the file type matches the expected type */ if (file_type != read_file_type && echo_output){ pr_append_new_chunk(nonfatal_parse_err, "Unexpected P3 file type parsed"); } continue; } /* Read only the PRIMER tags if settings is selected */ if (read_file_type == settings && strncmp(s, "PRIMER_", 7) && strncmp(s, "P3_FILE_ID", 10)) { continue; } /* Silently ignore all primer3plus tags */ if (!(strncmp(s, "P3P_", 4))) { continue; } data_found = 1; /* Print out the input */ if (echo_output) printf("%s\n", s); line_len = strlen(s); /* If the line has an "=" read the tag in the right place */ if ((n=strchr(s,'=')) == NULL) { /* The input line is illegal because it has no * "=" in it, but we still will read to the end * of the record. */ pr_append_new_chunk(glob_err, "Input line with no '=': "); pr_append(glob_err, s); } else { /* Get the tag and the value pointers */ tag_len = n - s; datum = n + 1; datum_len = line_len - tag_len - 1; /* Process "Sequence" (i.e. Per-Record) Arguments". */ parse_err = non_fatal_err; /* Process the old sequence Tags*/ if (*io_version == 0) { /* COMPARE_AND_MALLOC("SEQUENCE", sa->sequence); */ if (COMPARE("SEQUENCE")) { /* NEW WAY */ if (/* p3_get_seq_arg_sequence(sa) */ sa->sequence) { pr_append_new_chunk(parse_err, "Duplicate tag: "); pr_append(parse_err, "SEQUENCE"); } else { if (p3_set_sa_sequence(sa, datum)) exit(-2); } continue; } if (COMPARE("PRIMER_SEQUENCE_QUALITY")) { if ((sa->n_quality = parse_seq_quality(datum, &sa->quality)) == 0) { pr_append_new_chunk(parse_err, "Error in sequence quality data"); /* continue; // FIX ME superfluous ? */ } continue; } COMPARE_AND_MALLOC("PRIMER_SEQUENCE_ID", sa->sequence_name); COMPARE_AND_MALLOC("MARKER_NAME", sa->sequence_name); COMPARE_AND_MALLOC("PRIMER_LEFT_INPUT", sa->left_input); COMPARE_AND_MALLOC("PRIMER_RIGHT_INPUT", sa->right_input); COMPARE_AND_MALLOC("PRIMER_INTERNAL_OLIGO_INPUT", sa->internal_input); COMPARE_INTERVAL_LIST("TARGET", &sa->tar2); COMPARE_INTERVAL_LIST("EXCLUDED_REGION", &sa->excl2); COMPARE_INTERVAL_LIST("PRIMER_INTERNAL_OLIGO_EXCLUDED_REGION", &sa->excl_internal2); if (COMPARE("INCLUDED_REGION")) { p = parse_int_pair("INCLUDED_REGION", datum, ',', &sa->incl_s, &sa->incl_l, parse_err); if (NULL == p) /* * An error; the message is already * in parse_err. */ continue; while (' ' == *p || '\t' == *p) p++; if (*p != '\n' && *p != '\0') tag_syntax_error("INCLUDED_REGION", datum, parse_err); continue; } COMPARE_INT("PRIMER_START_CODON_POSITION", sa->start_codon_pos); } /* Process the new sequence Tags*/ else { /* COMPARE_AND_MALLOC("SEQUENCE", sa->sequence); */ if (COMPARE("SEQUENCE_DNA")) { /* NEW WAY */ if (/* p3_get_seq_arg_sequence(sa) */ sa->sequence) { pr_append_new_chunk(parse_err, "Duplicate tag: "); pr_append(parse_err, "SEQUENCE_DNA"); } else { if (p3_set_sa_sequence(sa, datum)) exit(-2); } continue; } if (COMPARE("SEQUENCE_QUALITY")) { if ((sa->n_quality = parse_seq_quality(datum, &sa->quality)) == 0) { pr_append_new_chunk(parse_err, "Error in sequence quality data"); /* continue; // FIX ME superfluous ? */ } continue; } COMPARE_AND_MALLOC("SEQUENCE_ID", sa->sequence_name); COMPARE_AND_MALLOC("SEQUENCE_PRIMER", sa->left_input); COMPARE_AND_MALLOC("SEQUENCE_PRIMER_REVCOMP", sa->right_input); COMPARE_AND_MALLOC("SEQUENCE_OLIGO", sa->internal_input); COMPARE_INTERVAL_LIST("SEQUENCE_TARGET", &sa->tar2); COMPARE_INTERVAL_LIST("SEQUENCE_EXCLUDED_REGION", &sa->excl2); COMPARE_INTERVAL_LIST("SEQUENCE_INTERNAL_EXCLUDED_REGION", &sa->excl_internal2); if (COMPARE("SEQUENCE_INCLUDED_REGION")) { p = parse_int_pair("SEQUENCE_INCLUDED_REGION", datum, ',', &sa->incl_s, &sa->incl_l, parse_err); if (NULL == p) /* * An error; the message is already * in parse_err. */ continue; while (' ' == *p || '\t' == *p) p++; if (*p != '\n' && *p != '\0') tag_syntax_error("SEQUENCE_INCLUDED_REGION", datum, parse_err); continue; } COMPARE_INT("SEQUENCE_START_CODON_POSITION", sa->start_codon_pos); } /* * Process "Global" Arguments (those that persist between boulder * records). */ parse_err = glob_err; /* These errors are considered fatal. */ if (COMPARE("PRIMER_PRODUCT_SIZE_RANGE") || COMPARE("PRIMER_DEFAULT_PRODUCT")) { parse_product_size("PRIMER_PRODUCT_SIZE_RANGE", datum, pa, parse_err); continue; } COMPARE_INT("PRIMER_DEFAULT_SIZE", pa->p_args.opt_size); COMPARE_INT("PRIMER_OPT_SIZE", pa->p_args.opt_size); COMPARE_INT("PRIMER_MIN_SIZE", pa->p_args.min_size); COMPARE_INT("PRIMER_MAX_SIZE", pa->p_args.max_size); COMPARE_INT("PRIMER_MAX_POLY_X", pa->p_args.max_poly_x); COMPARE_FLOAT("PRIMER_OPT_TM", pa->p_args.opt_tm); COMPARE_FLOAT("PRIMER_OPT_GC_PERCENT", pa->p_args.opt_gc_content); COMPARE_FLOAT("PRIMER_MIN_TM", pa->p_args.min_tm); COMPARE_FLOAT("PRIMER_MAX_TM", pa->p_args.max_tm); COMPARE_FLOAT("PRIMER_MAX_DIFF_TM", pa->max_diff_tm); if (*io_version == 0) { COMPARE_INT("PRIMER_TM_SANTALUCIA", pa->tm_santalucia); /* added by T.Koressaar */ } else { COMPARE_INT("PRIMER_TM_FORMULA", pa->tm_santalucia); /* added by T.Koressaar */ } COMPARE_INT("PRIMER_SALT_CORRECTIONS", pa->salt_corrections); /* added by T.Koressaar */ COMPARE_FLOAT("PRIMER_MIN_GC", pa->p_args.min_gc); COMPARE_FLOAT("PRIMER_MAX_GC", pa->p_args.max_gc); /* begin of added by T.Koressaar: */ if (*io_version == 0) { COMPARE_FLOAT("PRIMER_SALT_CONC", pa->p_args.salt_conc); COMPARE_FLOAT("PRIMER_DIVALENT_CONC", pa->p_args.divalent_conc); } else { COMPARE_FLOAT("PRIMER_SALT_MONOVALENT", pa->p_args.salt_conc); COMPARE_FLOAT("PRIMER_SALT_DIVALENT", pa->p_args.divalent_conc); } COMPARE_FLOAT("PRIMER_DNTP_CONC", pa->p_args.dntp_conc); /* end of added by T.Koressaar: */ COMPARE_FLOAT("PRIMER_DNA_CONC", pa->p_args.dna_conc); COMPARE_INT("PRIMER_NUM_NS_ACCEPTED", pa->p_args.num_ns_accepted); COMPARE_INT("PRIMER_PRODUCT_OPT_SIZE", pa->product_opt_size); COMPARE_ALIGN_SCORE("PRIMER_SELF_ANY", pa->p_args.max_self_any); COMPARE_ALIGN_SCORE("PRIMER_SELF_END", pa->p_args.max_self_end); COMPARE_ALIGN_SCORE("PRIMER_PAIR_ANY", pa->pair_compl_any); COMPARE_ALIGN_SCORE("PRIMER_PAIR_END", pa->pair_compl_end); if (*io_version == 0) { COMPARE_INT("PRIMER_FILE_FLAG", pa->file_flag); } else { COMPARE_INT("P3_FILE_FLAG", pa->file_flag); } COMPARE_INT("PRIMER_PICK_ANYWAY", pa->pick_anyway); COMPARE_INT("PRIMER_GC_CLAMP", pa->gc_clamp); COMPARE_INT("PRIMER_EXPLAIN_FLAG", pa->explain_flag); COMPARE_INT("PRIMER_LIBERAL_BASE", pa->liberal_base); COMPARE_INT("PRIMER_FIRST_BASE_INDEX", pa->first_base_index); COMPARE_INT("PRIMER_NUM_RETURN", pa->num_return); COMPARE_INT("PRIMER_MIN_QUALITY", pa->p_args.min_quality); COMPARE_INT("PRIMER_MIN_END_QUALITY", pa->p_args.min_end_quality); COMPARE_INT("PRIMER_MIN_THREE_PRIME_DISTANCE", pa->min_three_prime_distance); if (*io_version > 0 && file_type == settings) { COMPARE_AND_MALLOC("P3_FILE_ID", pa->settings_file_id); } COMPARE_INT("PRIMER_QUALITY_RANGE_MIN", pa->quality_range_min); COMPARE_INT("PRIMER_QUALITY_RANGE_MAX", pa->quality_range_max); COMPARE_FLOAT("PRIMER_PRODUCT_MAX_TM", pa->product_max_tm); COMPARE_FLOAT("PRIMER_PRODUCT_MIN_TM", pa->product_min_tm); COMPARE_FLOAT("PRIMER_PRODUCT_OPT_TM", pa->product_opt_tm); COMPARE_AND_MALLOC("PRIMER_TASK", task_tmp); if (0 < *io_version) { COMPARE_INT("PRIMER_PICK_RIGHT_PRIMER", pa->pick_right_primer); COMPARE_INT("PRIMER_PICK_INTERNAL_OLIGO", pa->pick_internal_oligo); COMPARE_INT("PRIMER_PICK_LEFT_PRIMER", pa->pick_left_primer); } else { COMPARE_INT("PRIMER_PICK_INTERNAL_OLIGO", pick_internal_oligo); } COMPARE_INT("PRIMER_INTERNAL_OLIGO_OPT_SIZE", pa->o_args.opt_size); COMPARE_INT("PRIMER_INTERNAL_OLIGO_MAX_SIZE", pa->o_args.max_size); COMPARE_INT("PRIMER_INTERNAL_OLIGO_MIN_SIZE", pa->o_args.min_size); COMPARE_INT("PRIMER_INTERNAL_OLIGO_MAX_POLY_X", pa->o_args.max_poly_x); COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_OPT_TM", pa->o_args.opt_tm); COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_OPT_GC_PERCENT", pa->o_args.opt_gc_content); COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_MAX_TM", pa->o_args.max_tm); COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_MIN_TM", pa->o_args.min_tm); COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_MIN_GC", pa->o_args.min_gc); COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_MAX_GC", pa->o_args.max_gc); COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_SALT_CONC", pa->o_args.salt_conc); COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_DIVALENT_CONC", pa->o_args.divalent_conc); /* added by T.Koressaar */ COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_DNTP_CONC", pa->o_args.dntp_conc); /* added by T.Koressaar */ COMPARE_FLOAT("PRIMER_INTERNAL_OLIGO_DNA_CONC", pa->o_args.dna_conc); COMPARE_INT("PRIMER_INTERNAL_OLIGO_NUM_NS", pa->o_args.num_ns_accepted); COMPARE_INT("PRIMER_INTERNAL_OLIGO_MIN_QUALITY", pa->o_args.min_quality); COMPARE_ALIGN_SCORE("PRIMER_INTERNAL_OLIGO_SELF_ANY", pa->o_args.max_self_any); COMPARE_ALIGN_SCORE("PRIMER_INTERNAL_OLIGO_SELF_END", pa->o_args.max_self_end); COMPARE_ALIGN_SCORE("PRIMER_MAX_MISPRIMING", pa->p_args.max_repeat_compl); COMPARE_ALIGN_SCORE("PRIMER_INTERNAL_OLIGO_MAX_MISHYB", pa->o_args.max_repeat_compl); COMPARE_ALIGN_SCORE("PRIMER_PAIR_MAX_MISPRIMING", pa->pair_repeat_compl); /* Mispriming / mishybing in the template. */ COMPARE_ALIGN_SCORE("PRIMER_MAX_TEMPLATE_MISPRIMING", pa->p_args.max_template_mispriming); COMPARE_ALIGN_SCORE("PRIMER_PAIR_MAX_TEMPLATE_MISPRIMING", pa->pair_max_template_mispriming); COMPARE_ALIGN_SCORE("PRIMER_INTERNAL_OLIGO_MAX_TEMPLATE_MISHYB", pa->o_args.max_template_mispriming); /* Control interpretation of ambiguity codes in mispriming and mishyb libraries. */ COMPARE_INT("PRIMER_LIB_AMBIGUITY_CODES_CONSENSUS", pa->lib_ambiguity_codes_consensus); COMPARE_FLOAT("PRIMER_INSIDE_PENALTY", pa->inside_penalty); COMPARE_FLOAT("PRIMER_OUTSIDE_PENALTY", pa->outside_penalty); if (COMPARE("PRIMER_MISPRIMING_LIBRARY")) { if (repeat_file_path != NULL) { pr_append_new_chunk(glob_err, "Duplicate PRIMER_MISPRIMING_LIBRARY tag"); free(repeat_file_path); repeat_file_path = NULL; } else { repeat_file_path = _rb_safe_malloc(strlen(datum) + 1); strcpy(repeat_file_path, datum); } continue; } if (COMPARE("PRIMER_INTERNAL_OLIGO_MISHYB_LIBRARY")) { if (int_repeat_file_path != NULL) { pr_append_new_chunk(glob_err, "Duplicate PRIMER_INTERNAL_OLIGO_MISHYB_LIBRARY tag"); free(int_repeat_file_path); int_repeat_file_path = NULL; } else { int_repeat_file_path = _rb_safe_malloc(strlen(datum) + 1); strcpy(int_repeat_file_path, datum); } continue; } if (COMPARE("PRIMER_COMMENT") || COMPARE("COMMENT")) continue; COMPARE_FLOAT("PRIMER_MAX_END_STABILITY", pa->max_end_stability); COMPARE_INT("PRIMER_LOWERCASE_MASKING", pa->lowercase_masking); /* added by T. Koressaar */ /* weights for objective functions */ /* CHANGE TEMP/temp -> TM/tm */ COMPARE_FLOAT("PRIMER_WT_TM_GT", pa->p_args.weights.temp_gt); COMPARE_FLOAT("PRIMER_WT_TM_LT", pa->p_args.weights.temp_lt); COMPARE_FLOAT("PRIMER_WT_GC_PERCENT_GT", pa->p_args.weights.gc_content_gt); COMPARE_FLOAT("PRIMER_WT_GC_PERCENT_LT", pa->p_args.weights.gc_content_lt); COMPARE_FLOAT("PRIMER_WT_SIZE_LT", pa->p_args.weights.length_lt); COMPARE_FLOAT("PRIMER_WT_SIZE_GT", pa->p_args.weights.length_gt); COMPARE_FLOAT("PRIMER_WT_COMPL_ANY", pa->p_args.weights.compl_any); COMPARE_FLOAT("PRIMER_WT_COMPL_END", pa->p_args.weights.compl_end); COMPARE_FLOAT("PRIMER_WT_NUM_NS", pa->p_args.weights.num_ns); COMPARE_FLOAT("PRIMER_WT_REP_SIM", pa->p_args.weights.repeat_sim); COMPARE_FLOAT("PRIMER_WT_SEQ_QUAL", pa->p_args.weights.seq_quality); COMPARE_FLOAT("PRIMER_WT_END_QUAL", pa->p_args.weights.end_quality); COMPARE_FLOAT("PRIMER_WT_POS_PENALTY", pa->p_args.weights.pos_penalty); COMPARE_FLOAT("PRIMER_WT_END_STABILITY", pa->p_args.weights.end_stability); COMPARE_FLOAT("PRIMER_WT_TEMPLATE_MISPRIMING", pa->p_args.weights.template_mispriming); COMPARE_FLOAT("PRIMER_IO_WT_TM_GT", pa->o_args.weights.temp_gt); COMPARE_FLOAT("PRIMER_IO_WT_TM_LT", pa->o_args.weights.temp_lt); COMPARE_FLOAT("PRIMER_IO_WT_GC_PERCENT_GT", pa->o_args.weights.gc_content_gt); COMPARE_FLOAT("PRIMER_IO_WT_GC_PERCENT_LT", pa->o_args.weights.gc_content_lt); COMPARE_FLOAT("PRIMER_IO_WT_SIZE_LT", pa->o_args.weights.length_lt); COMPARE_FLOAT("PRIMER_IO_WT_SIZE_GT", pa->o_args.weights.length_gt); COMPARE_FLOAT("PRIMER_IO_WT_COMPL_ANY", pa->o_args.weights.compl_any); COMPARE_FLOAT("PRIMER_IO_WT_COMPL_END", pa->o_args.weights.compl_end); COMPARE_FLOAT("PRIMER_IO_WT_NUM_NS", pa->o_args.weights.num_ns); COMPARE_FLOAT("PRIMER_IO_WT_REP_SIM", pa->o_args.weights.repeat_sim); COMPARE_FLOAT("PRIMER_IO_WT_SEQ_QUAL", pa->o_args.weights.seq_quality); COMPARE_FLOAT("PRIMER_IO_WT_END_QUAL", pa->o_args.weights.end_quality); COMPARE_FLOAT("PRIMER_IO_WT_TEMPLATE_MISHYB", pa->o_args.weights.template_mispriming); COMPARE_FLOAT("PRIMER_PAIR_WT_PR_PENALTY", pa->pr_pair_weights.primer_quality); COMPARE_FLOAT("PRIMER_PAIR_WT_IO_PENALTY", pa->pr_pair_weights.io_quality); COMPARE_FLOAT("PRIMER_PAIR_WT_DIFF_TM", pa->pr_pair_weights.diff_tm); COMPARE_FLOAT("PRIMER_PAIR_WT_COMPL_ANY", pa->pr_pair_weights.compl_any); COMPARE_FLOAT("PRIMER_PAIR_WT_COMPL_END", pa->pr_pair_weights.compl_end); COMPARE_FLOAT("PRIMER_PAIR_WT_PRODUCT_TM_LT", pa->pr_pair_weights.product_tm_lt); COMPARE_FLOAT("PRIMER_PAIR_WT_PRODUCT_TM_GT", pa->pr_pair_weights.product_tm_gt); COMPARE_FLOAT("PRIMER_PAIR_WT_PRODUCT_SIZE_GT", pa->pr_pair_weights.product_size_gt); COMPARE_FLOAT("PRIMER_PAIR_WT_PRODUCT_SIZE_LT", pa->pr_pair_weights.product_size_lt); COMPARE_FLOAT("PRIMER_PAIR_WT_REP_SIM", pa->pr_pair_weights.repeat_sim); COMPARE_FLOAT("PRIMER_PAIR_WT_TEMPLATE_MISPRIMING", pa->pr_pair_weights.template_mispriming); } /* End of reading the tags in the right place */ /* Complain about unrecognized tags */ if (*strict_tags == 1) { pr_append_new_chunk(glob_err, "Unrecognized tag: "); pr_append(glob_err, s); fprintf(stderr, "Unrecognized tag: %s\n", s); } } /* while ((s = p3_read_line(stdin)) != NULL && strcmp(s,"=")) { */ /* Check if the record was terminated by "=" */ if (NULL == s) { /* End of file. */ if (data_found) { pr_append_new_chunk(glob_err, "Final record not terminated by '='"); return 1; } else return 0; } /* Figure out the right settings for the tasks*/ if (task_tmp != NULL) { if (!strcmp_nocase(task_tmp, "pick_pcr_primers")) { pa->primer_task = pick_detection_primers; pa->pick_left_primer = 1; pa->pick_right_primer = 1; pa->pick_internal_oligo = 0; } else if (!strcmp_nocase(task_tmp, "pick_pcr_primers_and_hyb_probe")) { pa->primer_task = pick_detection_primers; pa->pick_left_primer = 1; pa->pick_right_primer = 1; pa->pick_internal_oligo = 1; } else if (!strcmp_nocase(task_tmp, "pick_left_only")) { pa->primer_task = pick_detection_primers; pa->pick_left_primer = 1; pa->pick_right_primer = 0; pa->pick_internal_oligo = 0; } else if (!strcmp_nocase(task_tmp, "pick_right_only")) { pa->primer_task = pick_detection_primers; pa->pick_left_primer = 0; pa->pick_right_primer = 1; pa->pick_internal_oligo = 0; } else if (!strcmp_nocase(task_tmp, "pick_hyb_probe_only")) { pa->primer_task = pick_detection_primers; pa->pick_left_primer = 0; pa->pick_right_primer = 0; pa->pick_internal_oligo = 1; } else if (*io_version == 0) { pr_append_new_chunk(glob_err, "Unrecognized PRIMER_TASK"); } else if (!strcmp_nocase(task_tmp, "pick_detection_primers")) { pa->primer_task = pick_detection_primers; } else if (!strcmp_nocase(task_tmp, "pick_cloning_primers")) { pa->primer_task = pick_cloning_primers; } else if (!strcmp_nocase(task_tmp, "pick_discriminative_primers")) { pa->primer_task = pick_discriminative_primers; } else if (!strcmp_nocase(task_tmp, "pick_sequencing_primers")) { pa->primer_task = pick_sequencing_primers; } else if (!strcmp_nocase(task_tmp, "pick_primer_list")) { pa->primer_task = pick_primer_list; } else if (!strcmp_nocase(task_tmp, "check_primers")) { pa->primer_task = check_primers; } else pr_append_new_chunk(glob_err, "Unrecognized PRIMER_TASK"); free(task_tmp); } /* WARNING: read_seq_lib uses p3_read_line, so repeat files cannot be read * inside the while ((s = p3_read_line(stdin))...) loop above. * FIX ME, in fact the reading of the library contents probably * belongs inside primer3_boulder_main.c or libprimer3.c. */ /* Reading in the repeat libraries */ if (NULL != repeat_file_path) { destroy_seq_lib(pa->p_args.repeat_lib); if ('\0' == *repeat_file_path) { /* Input now specifies no repeat library. */ pa->p_args.repeat_lib = NULL; } else { pa->p_args.repeat_lib = read_and_create_seq_lib(repeat_file_path, "mispriming library"); if(pa->p_args.repeat_lib->error.data != NULL) { pr_append_new_chunk(glob_err, pa->p_args.repeat_lib->error.data); } } free(repeat_file_path); repeat_file_path = NULL; } /* Reading in the repeat libraries for internal oligo */ if (NULL != int_repeat_file_path) { destroy_seq_lib(pa->o_args.repeat_lib); if ('\0' == *int_repeat_file_path) { /* Input now specifies no mishybridization library. */ pa->o_args.repeat_lib = NULL; } else { pa->o_args.repeat_lib = read_and_create_seq_lib(int_repeat_file_path, "internal oligo mishyb library"); if(pa->o_args.repeat_lib->error.data != NULL) { pr_append_new_chunk(glob_err, pa->o_args.repeat_lib->error.data); } } free(int_repeat_file_path); int_repeat_file_path = NULL; } /* Fix very old tags for backward compatibility */ if (*io_version == 0) { /* This next belongs here rather than libprimer3, because it deals with potential incompatibility with old tags (kept for backward compatibility, and new tags. */ if (pa->primer_task == pick_pcr_primers_and_hyb_probe) { PR_ASSERT(pa->pick_internal_oligo); } /* Give a error if the tasks don't match */ if((pick_internal_oligo == 1 || pick_internal_oligo == 0) && (pa->primer_task == pick_left_only || pa->primer_task == pick_right_only || pa->primer_task == pick_hyb_probe_only)) { pr_append_new_chunk(glob_err, "Contradiction in primer_task definition"); if (pa->primer_task == pick_pcr_primers_and_hyb_probe) { PR_ASSERT(pa->pick_internal_oligo); } } else if (pick_internal_oligo == 1) { pa->pick_left_primer = 1; pa->pick_right_primer = 1; pa->pick_internal_oligo = 1; if (pa->primer_task == pick_pcr_primers_and_hyb_probe) { PR_ASSERT(pa->pick_internal_oligo); } } else if (pick_internal_oligo == 0) { pa->pick_left_primer = 1; pa->pick_right_primer = 1; pa->pick_internal_oligo = 0; if (pa->primer_task == pick_pcr_primers_and_hyb_probe) { PR_ASSERT(pa->pick_internal_oligo); } } if (pa->primer_task == pick_pcr_primers_and_hyb_probe) { PR_ASSERT(pa->pick_internal_oligo); } } if (pa->primer_task == pick_pcr_primers_and_hyb_probe) { PR_ASSERT(pa->pick_internal_oligo); } return 1; }
void mcp_basic_handler(McpFrame * mfr, McpMesg * mesg, void *dummy) { McpVer myminver = { 2, 1 }; McpVer mymaxver = { 2, 1 }; McpVer minver = { 0, 0 }; McpVer maxver = { 0, 0 }; McpVer nullver = { 0, 0 }; const char *ptr; const char *auth; if (!*mesg->mesgname) { auth = mcp_mesg_arg_getline(mesg, "authentication-key", 0); if (auth) { mfr->authkey = string_dup(auth); } else { McpMesg reply; char authval[128]; mcp_mesg_init(&reply, MCP_INIT_PKG, ""); mcp_mesg_arg_append(&reply, "version", "2.1"); mcp_mesg_arg_append(&reply, "to", "2.1"); snprintf(authval, sizeof(authval), "%.8lX", (unsigned long)(RANDOM() ^ RANDOM())); mcp_mesg_arg_append(&reply, "authentication-key", authval); mfr->authkey = string_dup(authval); mcp_frame_output_mesg(mfr, &reply); mcp_mesg_clear(&reply); } ptr = mcp_mesg_arg_getline(mesg, "version", 0); if (!ptr) return; while (isdigit(*ptr)) minver.vermajor = (minver.vermajor * 10) + (*ptr++ - '0'); if (*ptr++ != '.') return; while (isdigit(*ptr)) minver.verminor = (minver.verminor * 10) + (*ptr++ - '0'); ptr = mcp_mesg_arg_getline(mesg, "to", 0); if (!ptr) { maxver = minver; } else { while (isdigit(*ptr)) maxver.vermajor = (maxver.vermajor * 10) + (*ptr++ - '0'); if (*ptr++ != '.') return; while (isdigit(*ptr)) maxver.verminor = (maxver.verminor * 10) + (*ptr++ - '0'); } mfr->version = mcp_version_select(myminver, mymaxver, minver, maxver); if (mcp_version_compare(mfr->version, nullver)) { McpMesg cando; char verbuf[32]; McpPkg *p = mcp_PackageList; mfr->enabled = 1; while (p) { if (strcmp_nocase(p->pkgname, MCP_INIT_PKG)) { mcp_mesg_init(&cando, MCP_NEGOTIATE_PKG, "can"); mcp_mesg_arg_append(&cando, "package", p->pkgname); snprintf(verbuf, sizeof(verbuf), "%d.%d", p->minver.vermajor, p->minver.verminor); mcp_mesg_arg_append(&cando, "min-version", verbuf); snprintf(verbuf, sizeof(verbuf), "%d.%d", p->maxver.vermajor, p->maxver.verminor); mcp_mesg_arg_append(&cando, "max-version", verbuf); mcp_frame_output_mesg(mfr, &cando); mcp_mesg_clear(&cando); } p = p->next; } mcp_mesg_init(&cando, MCP_NEGOTIATE_PKG, "end"); mcp_frame_output_mesg(mfr, &cando); mcp_mesg_clear(&cando); } } }
/* ---------------------------------------------------------------------- */ int read_solution_spread (void) /* ---------------------------------------------------------------------- */ { /* * Reads solution data * * Arguments: * none * * Returns: * KEYWORD if keyword encountered, input_error may be incremented if * a keyword is encountered in an unexpected position * EOF if eof encountered while reading mass balance concentrations * ERROR if error occurred reading data * */ struct spread_row *heading, *row_ptr, *units; int i, j, l, j1, num, count; int strings, numbers; int spread_lines; char token[MAX_LENGTH], token1[MAX_LENGTH]; char *ptr; struct defaults defaults = { 25, 1, "mmol/kgw", "pe", 7, 4, 1, 1, iso_defaults, }; int return_value, opt; char *next_char; const char *opt_list[] = { "temp", /* 0 */ "temperature", /* 1 */ "dens", /* 2 */ "density", /* 3 */ "units", /* 4 */ "redox", /* 5 */ "ph", /* 6 */ "pe", /* 7 */ "unit", /* 8 */ "isotope", /* 9 */ "water", /* 10 */ "isotope_uncertainty", /* 11 */ "uncertainty", /* 12 */ "uncertainties" /* 13 */ }; int count_opt_list = 14; if (svnid == NULL) fprintf (stderr, " "); heading = NULL; units = NULL; defaults.count_iso = count_iso_defaults; defaults.iso = (struct iso *) PHRQ_malloc ((size_t) defaults.count_iso * sizeof (struct iso)); if (defaults.iso == NULL) malloc_error (); memcpy (defaults.iso, iso_defaults, (size_t) defaults.count_iso * sizeof (struct iso)); return_value = UNKNOWN; spread_lines = 0; /* * Loop on solutions */ for (;;) { opt = get_option (opt_list, count_opt_list, &next_char); if (spread_lines == 0 && opt != OPTION_DEFAULT) { row_ptr = string_to_spread_row (line); count = 0; ptr = line; numbers = 0; strings = 0; while (((j = copy_token (token, &ptr, &l)) != EMPTY)) { count++; if (j == UPPER || j == LOWER) strings++; if (j == DIGIT) numbers++; } #ifdef SKIP for (i = 0; i < row_ptr->count; i++) { if (row_ptr->type_vector[i] == STRING) { strings++; } else if (row_ptr->type_vector[i] == NUMBER) { numbers++; } } #endif /* * Is 2nd token all number */ ptr = line; copy_token (token, &ptr, &l); j = copy_token (token, &ptr, &l); num = FALSE; if (j == DIGIT) { strtod (token, &ptr); j1 = copy_token (token1, &ptr, &l); if (j1 != EMPTY) { num = FALSE; } else { num = TRUE; } } /* * Starts with hyphen */ ptr = line; copy_token (token, &ptr, &l); if (token[0] == '-') { opt = opt; } else { switch (opt) { case 0: /* temp */ case 1: /* temperature */ case 2: /* dens */ case 3: /* density */ case 10: /* water */ if (count == 2 && num == TRUE) { opt = opt; } else { opt = OPTION_DEFAULT; } break; case 6: /* ph */ case 7: /* pe */ if ((count == 2 || count == 3 || count == 4) && num == TRUE) { opt = opt; } else { opt = OPTION_DEFAULT; } break; case 5: /* redox */ case 4: /* units */ case 8: /* unit */ if (count == 2) { opt = opt; } else { opt = OPTION_DEFAULT; } break; case 9: /* isotope */ if (row_ptr->count > 4) { opt = OPTION_DEFAULT; } else { opt = opt; } break; case 11: /* isotope_uncertainty */ case 12: /* uncertainty */ case 13: /* uncertainties */ if (row_ptr->count > 3) { opt = OPTION_DEFAULT; } else { opt = opt; } break; } } spread_row_free (row_ptr); } if (opt == OPTION_DEFAULT) { if (spread_lines == 0) { opt = 100; } spread_lines++; } switch (opt) { case OPTION_EOF: /* end of file */ return_value = EOF; break; case OPTION_KEYWORD: /* keyword */ return_value = KEYWORD; break; case OPTION_ERROR: input_error++; error_msg ("Unknown input in SOLUTION keyword.", CONTINUE); error_msg (line_save, CONTINUE); break; case OPTION_DEFAULT: /* solution definition */ row_ptr = string_to_spread_row (line); if (spread_lines == 2) { numbers = 0; strings = 0; for (i = 0; i < heading->count; i++) { if (row_ptr->type_vector[i] == STRING) { strings++; } else if (row_ptr->type_vector[i] == NUMBER) { numbers++; } #ifdef SKIP if (row_ptr->type_vector[i] == STRING && (strcmp_nocase (heading->char_vector[i], "units") != 0) && (strcmp_nocase (heading->char_vector[i], "unit") != 0) && (strcmp_nocase (heading->char_vector[i], "description") != 0) && (strcmp_nocase (heading->char_vector[i], "desc") != 0) && (strcmp_nocase (heading->char_vector[i], "descriptor") != 0) && (strcmp_nocase (heading->char_vector[i], "redox") != 0)) { break; } #endif } #ifdef SKIP if (i < heading->count) { units = row_ptr; break; } #endif if (numbers == 0) { units = row_ptr; break; } } spread_row_to_solution (heading, units, row_ptr, defaults); #ifdef PHREEQCI_GUI add_row (row_ptr); #endif spread_row_free (row_ptr); break; case 0: /* temperature */ case 1: sscanf (next_char, SCANFORMAT, &(defaults.temp)); break; case 2: /* density */ case 3: sscanf (next_char, SCANFORMAT, &(defaults.density)); break; case 4: /* units */ case 8: /* unit */ if (copy_token (token, &next_char, &l) == EMPTY) break; if (check_units (token, FALSE, FALSE, NULL, TRUE) == OK) { defaults.units = string_hsave (token); } else { input_error++; } break; case 5: /* redox */ if (copy_token (token, &next_char, &l) == EMPTY) break; if (parse_couple (token) == OK) { defaults.redox = string_hsave (token); } else { input_error++; } break; case 6: /* ph */ copy_token (token, &next_char, &l); sscanf (token, SCANFORMAT, &(defaults.ph)); if (copy_token (token, &next_char, &l) != EMPTY) { warning_msg ("Not possible to use phase name or saturation index in definition of default pH in SOLUTION_SPREAD."); } break; case 7: /* pe */ copy_token (token, &next_char, &l); sscanf (token, SCANFORMAT, &(defaults.pe)); if (copy_token (token, &next_char, &l) != EMPTY) { warning_msg ("Not possible to use phase name or saturation index in definition of default pe in SOLUTION_SPREAD."); } break; case 11: /* isotope_uncertainty */ case 12: /* uncertainty */ case 13: /* uncertainties */ if (copy_token (token, &next_char, &l) != DIGIT) { input_error++; sprintf (error_string, "Expected isotope name to" " begin with an isotopic number."); error_msg (error_string, CONTINUE); continue; } for (i = 0; i < defaults.count_iso; i++) { if (strcmp (token, defaults.iso[i].name) == 0) { break; } } if (i == defaults.count_iso) { defaults.iso = (struct iso *) PHRQ_realloc (defaults.iso, (size_t) (i + 1) * sizeof (struct iso)); if (defaults.iso == NULL) malloc_error (); defaults.iso[i].name = string_duplicate (token); defaults.iso[i].value = NAN; defaults.iso[i].uncertainty = NAN; defaults.count_iso++; } /* read and store isotope ratio uncertainty */ if ((j = copy_token (token, &next_char, &l)) != EMPTY) { if (j != DIGIT) { input_error++; sprintf (error_string, "Expected numeric value for uncertainty in isotope ratio."); error_msg (error_string, CONTINUE); continue; } else { sscanf (token, SCANFORMAT, &(defaults.iso[i].uncertainty)); } } else { defaults.iso[i].uncertainty = NAN; } break; case 10: /* water */ j = copy_token (token, &next_char, &l); if (j != DIGIT) { input_error++; sprintf (error_string, "Expected numeric value for mass of water in solution."); error_msg (error_string, CONTINUE); } else { sscanf (token, SCANFORMAT, &(defaults.water)); } break; case 9: /* isotope */ if (copy_token (token, &next_char, &l) != DIGIT) { input_error++; sprintf (error_string, "Expected isotope name to" " begin with an isotopic number."); error_msg (error_string, CONTINUE); continue; } for (i = 0; i < defaults.count_iso; i++) { if (strcmp (token, defaults.iso[i].name) == 0) { break; } } if (i == defaults.count_iso) { defaults.iso = (struct iso *) PHRQ_realloc (defaults.iso, (size_t) (i + 1) * sizeof (struct iso)); if (defaults.iso == NULL) malloc_error (); defaults.iso[i].name = string_duplicate (token); defaults.iso[i].value = NAN; defaults.iso[i].uncertainty = NAN; defaults.count_iso++; } /* read and store isotope ratio */ if (copy_token (token, &next_char, &l) != DIGIT) { input_error++; sprintf (error_string, "Expected numeric value for default isotope ratio."); error_msg (error_string, CONTINUE); break; } sscanf (token, SCANFORMAT, &(defaults.iso[i].value)); /* read and store isotope ratio uncertainty */ if ((j = copy_token (token, &next_char, &l)) != EMPTY) { if (j != DIGIT) { input_error++; sprintf (error_string, "Expected numeric value for uncertainty in isotope ratio."); error_msg (error_string, CONTINUE); continue; } else { sscanf (token, SCANFORMAT, &(defaults.iso[i].uncertainty)); } } break; case 100: /* read headings */ heading = string_to_spread_row (line); for (i = 0; i < heading->count; i++) { while (replace (" ", "", heading->char_vector[i]) == TRUE); while (replace (",", "_", heading->char_vector[i]) == TRUE); } break; } if (return_value == EOF || return_value == KEYWORD) break; } #ifdef PHREEQCI_GUI if (heading) g_spread_sheet.heading = copy_row (heading); if (units) g_spread_sheet.units = copy_row (units); copy_defaults (&g_spread_sheet.defaults, &defaults); #endif spread_row_free (heading); spread_row_free (units); /* free non-default iso names */ for (i = count_iso_defaults; i < defaults.count_iso; i++) { defaults.iso[i].name = (char *) free_check_null (defaults.iso[i].name); } defaults.iso = (struct iso *) free_check_null (defaults.iso); return (return_value); }
int mcp_mesg_arg_append(McpMesg * msg, const char *argname, const char *argval) { McpArg *ptr = msg->args; int namelen = strlen(argname); int vallen = argval? strlen(argval) : 0; if (namelen > MAX_MCP_ARGNAME_LEN) { return EMCP_ARGNAMELEN; } if (vallen + msg->bytes > MAX_MCP_MESG_SIZE) { return EMCP_MESGSIZE; } while (ptr && strcmp_nocase(ptr->name, argname)) { ptr = ptr->next; } if (!ptr) { if (namelen + vallen + msg->bytes > MAX_MCP_MESG_SIZE) { return EMCP_MESGSIZE; } ptr = (McpArg *) malloc(sizeof(McpArg)); ptr->name = (char *) malloc(namelen + 1); strcpyn(ptr->name, namelen+1, argname); ptr->value = NULL; ptr->last = NULL; ptr->next = NULL; if (!msg->args) { msg->args = ptr; } else { int limit = MAX_MCP_MESG_ARGS; McpArg *lastarg = msg->args; while (lastarg->next) { if (limit-- <= 0) { free(ptr->name); free(ptr); return EMCP_ARGCOUNT; } lastarg = lastarg->next; } lastarg->next = ptr; } msg->bytes += sizeof(McpArg) + namelen + 1; } if (argval) { McpArgPart *nu = (McpArgPart *) malloc(sizeof(McpArgPart)); nu->value = (char *) malloc(vallen + 1); strcpyn(nu->value, vallen+1, argval); nu->next = NULL; if (!ptr->last) { ptr->value = ptr->last = nu; } else { ptr->last->next = nu; ptr->last = nu; } msg->bytes += sizeof(McpArgPart) + vallen + 1; } ptr->was_shown = 0; return EMCP_SUCCESS; }
char * PKI_CONFIG_find ( char *dir, char *name ) { struct dirent *dd = NULL; DIR *dirp = NULL; URL *url = NULL; int found = 0; char *ret = NULL; /* Check input */ if( !dir || !name ) { PKI_ERROR(PKI_ERR_PARAM_NULL, NULL); return (PKI_ERR); } if ((url = URL_new(dir)) == NULL) { PKI_log_debug("Dir [%s] is not a valid URI", dir ); return (PKI_ERR); } if (url->proto != URI_PROTO_FILE) { PKI_log_debug("URL is not a file, skipping!", dir ); return (PKI_ERR); } if ((dirp = opendir(url->addr)) == NULL) { PKI_log_debug("Can not open directory [%s]", url->addr ); return (PKI_ERR); } else { while(( dd = readdir( dirp )) != NULL ) { long len; char *filename = NULL; filename = dd->d_name; len = (long) strlen( filename ); PKI_log_debug("Processing file [%s]", filename ); if (len < 4 || strcmp(".xml", filename +len-4) != 0) { PKI_log_debug("Skipping %s", filename ); continue; } else { char fullpath[BUFF_MAX_SIZE]; size_t fullsize = 0; PKI_CONFIG *tmp_cfg = NULL; char *tmp_name = NULL; snprintf(fullpath, BUFF_MAX_SIZE, "%s/%s", url->addr, filename ); PKI_log_debug("Opening File %s", fullpath ); // Check the allowed size fullsize = strlen(url->addr) + strlen( filename ) + 1; if (fullsize > BUFF_MAX_SIZE) continue; if ((tmp_cfg = PKI_CONFIG_load(fullpath)) == NULL) { PKI_log_debug("Can not load %s", fullpath ); continue; } PKI_log_debug("Getting Name Param... "); tmp_name = PKI_CONFIG_get_value(tmp_cfg, "/*/name"); PKI_CONFIG_free(tmp_cfg); if (tmp_name != NULL) { PKI_log_debug("Got Name::%s", tmp_name); if (strcmp_nocase(tmp_name, name) == 0) { PKI_Free(tmp_name); tmp_name = NULL; // Safety found = 1; ret = strdup(fullpath); PKI_log_debug("File successfully loaded %s", fullpath ); break; } PKI_Free(tmp_name); tmp_name = NULL; // Safety } else PKI_log_debug("No Name found!"); } } closedir( dirp ); } // Let's free the URL memory if (url) URL_free(url); // If found, let's return it if (found == 1) return ret; // If not found, we return NULL return NULL; }
int main (int argc, char *argv[]) { PKI_MEM_STACK *sk = NULL; PKI_MEM *obj = NULL; PKI_SSL *ssl = NULL; // PKI_TOKEN *tk = NULL; PKI_SOCKET *sock = NULL; URL * url = NULL; char *url_s = NULL; char *outurl_s = "fd://1"; char *trusted_certs = NULL; char *dump_cert = NULL; char *dump_chain = NULL; int debug = 0; int verify_chain = 1; int i = 0; int timeout = 0; int get_via_socket = 0; PKI_init_all(); if( !argv[1] ) { usage(); return(1); } for( i = 1; i <= argc; i++ ) { if( strcmp_nocase( argv[i], "-out" ) == 0 ) { outurl_s = argv[++i]; } else if ( strcmp_nocase ( argv[i], "-trusted" ) == 0 ) { trusted_certs = argv[++i]; } else if ( strcmp_nocase ( argv[i], "-dumpcert" ) == 0 ) { if((dump_cert = argv[++i]) == NULL ) { fprintf(stderr, "\nERROR: -dumpcert needs a file url!\n\n"); exit(1); } } else if ( strcmp_nocase ( argv[i], "-dumpchain" ) == 0 ) { if((dump_chain = argv[++i]) == NULL ) { fprintf(stderr, "\nERROR: -dumpchain needs a file url!\n\n"); exit(1); } } else if ( strcmp_nocase ( argv[i], "-timeout" ) == 0 ) { timeout = atoi( argv[++i] ); if ( timeout < 0 ) timeout = 0; } else if ( strcmp_nocase ( argv[i], "-no_verify" ) == 0 ) { verify_chain = 0; } else if ( strcmp_nocase( argv[i], "-debug" ) == 0 ) { debug = 1; } else { url_s = argv[i]; if ( i < argc - 1 ) { fprintf( stderr, "Args after URL ignored!(%s %d/%d)\n", url_s, i, argc ); } break; } } if((url = URL_new( url_s )) == NULL ) { printf("\nERROR, %s is not a valid URL!\n\n", url_s ); usage(); return (1); } if( debug ) { if(( PKI_log_init (PKI_LOG_TYPE_STDERR, PKI_LOG_INFO, NULL, PKI_LOG_FLAGS_ENABLE_DEBUG, NULL )) == PKI_ERR) { exit(1); } } else { if(( PKI_log_init (PKI_LOG_TYPE_STDERR, PKI_LOG_INFO, NULL, 0, NULL )) == PKI_ERR) { exit(1); } } // Check if we should use the socket approach or the simple URL // retrieval facility switch (url->proto) { case URI_PROTO_FD: case URI_PROTO_FILE: case URI_PROTO_HTTP: case URI_PROTO_HTTPS: case URI_PROTO_LDAP: get_via_socket = 1; break; default: get_via_socket = 0; } // // -------------------------- Setup the SSL Options ------------------------ // if(( ssl = PKI_SSL_new( NULL )) == NULL ) { fprintf(stderr, "ERROR: Memory allocation error (PKI_SSL_new)\n"); return ( 1 ); } if ( trusted_certs ) { PKI_X509_CERT_STACK *sk = NULL; if(( sk = PKI_X509_CERT_STACK_get ( trusted_certs, NULL, NULL)) == NULL ) { PKI_log_err ("Can't load Trusted Certs from %s", trusted_certs ); return 1; } PKI_SSL_set_trusted ( ssl, sk ); if ( verify_chain ) { PKI_SSL_set_verify(ssl, PKI_SSL_VERIFY_PEER_REQUIRE); } else { PKI_SSL_set_verify(ssl, PKI_SSL_VERIFY_PEER); } } if ( verify_chain == 0 ) { PKI_SSL_set_verify ( ssl, PKI_SSL_VERIFY_NONE ); fprintf(stderr, "WARNING: no verify set!\n"); } if(( sock = PKI_SOCKET_new ()) == NULL ) { fprintf(stderr, "ERROR, can not create a new Socket!\n\n"); exit(1); } PKI_SOCKET_set_ssl ( sock, ssl ); // // ------------------------------ Retrieve Data ----------------------------- // if (get_via_socket) { if( PKI_SOCKET_open( sock, url_s, timeout ) == PKI_ERR ) { fprintf(stderr, "ERROR, can not connect to %s!\n\n", url_s); exit(1); } ssl = PKI_SOCKET_get_ssl (sock); if (dump_cert) { PKI_X509_CERT *x = NULL; if ( !ssl ) { fprintf( stderr, "ERROR: Can not dump cert (no SSL)\n"); } if((x = PKI_SSL_get_peer_cert ( ssl )) == NULL ) { fprintf( stderr, "ERROR: No Peer certificate is available\n"); } if( PKI_X509_CERT_put ( x, PKI_DATA_FORMAT_PEM, dump_cert, NULL, NULL, NULL ) == PKI_ERR){ fprintf(stderr, "ERROR: can not write Peer cert to " "%s\n", dump_cert ); } } if (dump_chain) { PKI_X509_CERT_STACK *x_sk = NULL; if ( !ssl ) { fprintf( stderr, "ERROR: Can not dump cert (no SSL)\n"); } if((x_sk = PKI_SSL_get_peer_chain ( ssl )) == NULL ) { fprintf( stderr, "ERROR: No certificate chain is available\n"); } if( PKI_X509_CERT_STACK_put ( x_sk, PKI_DATA_FORMAT_PEM, dump_chain, NULL, NULL, NULL ) == PKI_ERR){ fprintf(stderr, "ERROR: can not write Peer cert to " "%s\n", dump_cert ); } } if((sk = URL_get_data_socket ( sock, timeout, 0 )) == NULL ) { fprintf(stderr, "ERROR, can not retrieve data!\n\n"); return(-1); } PKI_SOCKET_close ( sock ); PKI_SOCKET_free ( sock ); } else // Get Data via the usual URL socket-less approach { sk = URL_get_data_url (url, timeout, 0, ssl); } PKI_log_debug("URL: Number of retrieved entries is %d", PKI_STACK_MEM_elements(sk)); while( (obj = PKI_STACK_MEM_pop ( sk )) != NULL ) { URL_put_data ( outurl_s, obj, NULL, NULL, 0, 0, NULL ); } return 0; }
int main(int argc, char **argv) { int cmp; char *n1 = NULL; char *n2 = NULL; char s1[MAX_STR_LEN]; char s2[MAX_STR_LEN]; char strs[NUM_STRS][MAX_STR_LEN] = { STR0, STR1, STR2, STR3, STR4, STR5 }; if (argc < 2 || 3 == argc || argc > 4 || (strcmp(argv[1], "lcase") && strcmp(argv[1], "ucase") && strcmp(argv[1], "strcmp_nocase") )) { /*printf("INVALID PARAMETERS to chgCase\n"); */ exit(1); } if (2 == argc) { if (0 == strcmp(argv[1], "ucase")) { ucase(n1); } else if (0 == strcmp(argv[1], "lcase")) { lcase(n1); } else { strcmp_nocase(n1, n2); } /* if we're still alive we obviously didn't segfault */ exit(0); } if (4 == argc) { if (0 >= atoi(argv[2]) || atoi(argv[2]) >= NUM_STRS || 0 >= atoi(argv[3]) || atoi(argv[3]) >= NUM_STRS) { E_INFO("INVALID PARAMS TO chkCase\n"); exit(1); } strcpy(s1, strs[atoi(argv[2])]); strcpy(s2, strs[atoi(argv[3])]); if (0 == strcmp(argv[1], "ucase")) { ucase(s1); cmp = strcmp(s1, s2); } else if (0 == strcmp(argv[1], "lcase")) { lcase(s1); cmp = strcmp(s1, s2); } else { cmp = strcmp_nocase(s1, s2); } /* E_INFO("Value of cmp %d\n", cmp); */ if (0 != cmp) { E_FATAL("test failed\nstr1:|%s|\nstr2:|%s|\n", s1, s2); } return (cmp != 0); } /*somehow we got here and we shouldn't have */ exit(1); }