Ignore:
Timestamp:
04/30/11 16:17:48 (9 years ago)
Author:
Admin
Message:

WebIf: Some internal restructuring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-http-helpers.c

    r5130 r5131  
    491491}
    492492
    493 char *getParam(struct uriparams *params, char *name){
    494     int32_t i;
    495     for(i=(*params).paramcount-1; i>=0; --i){
    496         if(strcmp((*params).params[i], name) == 0) return (*params).values[i];
    497     }
    498     return "";
    499 }
    500 
    501493/* Helper function for urldecode.*/
    502494int32_t x2i(int32_t i){
     
    664656}
    665657
     658/* Parse url parameters and save them to params array. The pch pointer is increased to the position where parsing stopped. */
     659void parseParams(struct uriparams *params, char *pch) {
     660    char *pch2;
     661    // parsemode = 1 means parsing next param, parsemode = -1 parsing next
     662  //value; pch2 points to the beginning of the currently parsed string, pch is the current position
     663    int32_t parsemode = 1;
     664
     665    pch2=pch;
     666    while(pch[0] != '\0') {
     667        if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&')) {
     668            pch[0] = '\0';
     669            urldecode(pch2);
     670            if(parsemode == 1) {
     671                if(params->paramcount >= MAXGETPARAMS) break;
     672                ++params->paramcount;
     673                params->params[params->paramcount-1] = pch2;
     674            } else {
     675                params->values[params->paramcount-1] = pch2;
     676            }
     677            parsemode = -parsemode;
     678            pch2 = pch + 1;
     679        }
     680        ++pch;
     681    }
     682    /* last value wasn't processed in the loop yet... */
     683    if(parsemode == -1 && params->paramcount <= MAXGETPARAMS) {
     684        urldecode(pch2);
     685        params->values[params->paramcount-1] = pch2;
     686    }
     687}
     688
     689/* Returns the value of the parameter called name or an empty string if it doesn't exist. */
     690char *getParam(struct uriparams *params, char *name){
     691    int32_t i;
     692    for(i=(*params).paramcount-1; i>=0; --i){
     693        if(strcmp((*params).params[i], name) == 0) return (*params).values[i];
     694    }
     695    return "";
     696}
     697
     698struct s_reader *get_reader_by_label(char *lbl){
     699    struct s_reader *rdr;
     700    LL_ITER *itr = ll_iter_create(configured_readers);
     701    while((rdr = ll_iter_next(itr)))
     702      if (strcmp(lbl, rdr->label) == 0) break;
     703    ll_iter_release(itr);
     704    return rdr;
     705}
     706
     707struct s_client *get_client_by_name(char *name) {
     708    struct s_client *cl;
     709    for (cl = first_client; cl ; cl = cl->next) {
     710        if (strcmp(name, cl->account->usr) == 0)
     711            return cl;
     712    }
     713    return NULL;
     714}
     715
     716struct s_auth *get_account_by_name(char *name) {
     717    struct s_auth *account;
     718    for (account=cfg.account; (account); account=account->next) {
     719        if(strcmp(name, account->usr) == 0)
     720            return account;
     721    }
     722    return NULL;
     723}
     724
    666725#endif
Note: See TracChangeset for help on using the changeset viewer.