Exemplo n.º 1
0
int main(void) {
  char *string, *query;
  char *qlist[256], **qp;
  int queries, tmatches, matches;

  qContentType("text/html");
  qDecoder();

  string = qValueNotEmpty("Type any string.", "string");
  query = qValueNotEmpty("Type any query.", "query");

  queries = qArgMake(query, qlist);
  matches = qArgMatch(string, qlist);

  printf("String: <b>%s</b><br>\n", string);
  printf("Query Input: <b>%s</b><br>\n", query);

  printf("<hr>\n");

  printf("qArgMake(): <b>");
  for(qp = qlist; *qp; qp++) qPrintf(1, "\"%s\" ", *qp);
  printf("</b> (%d queries)<br>\n", queries);
  printf("qArgEmprint(): "); tmatches = qArgEmprint(1, string, qlist); printf(" (%d query matched)<br>\n", tmatches);
  printf("qArgMatch(): %d query matched<br>\n", matches);

  qArgFree(qlist);
  qFree();
  return 0;
}
Exemplo n.º 2
0
/**********************************************
** Usage : qPrint(pointer of the first Entry);
** Return: Amount of entries.
** Do    : Print all parsed values & names for debugging.
**********************************************/
int qPrint(void) {
    int amount;

    if (_first_entry == NULL) qDecoder();
    amount = _EntryPrint(_first_entry);
    printf("<hr>\n");
    printf("COOKIE = %d , GET = %d , POST = %d, NEW = %d\n", _cookie_cnt, _get_cnt, _post_cnt, _new_cnt);
    return amount;
}
Exemplo n.º 3
0
/**********************************************
** Usage : qiValue(query name);
** Return: Success integer of value string, Fail 0.
** Do    : Find value string pointer and convert to integer.
**********************************************/
int qiValue(char *format, ...) {
    char    name[1024];
    int     status;
    va_list arglist;

    va_start(arglist, format);
    status = vsprintf(name, format, arglist);
    if ((strlen(name) + 1 > sizeof(name)) || (status == EOF)) qError("qiValue(): Message is too long or invalid.");
    va_end(arglist);

    if (_first_entry == NULL) qDecoder();
    return _EntryiValue(_first_entry, name);
}
Exemplo n.º 4
0
/**********************************************
** Usage : qValueFirst(query name);
** Return: Success pointer of first value string, Fail NULL.
** Do    : Find first value string pointer.
**********************************************/
char *qValueFirst(char *format, ...) {
    int     status;
    va_list arglist;

    va_start(arglist, format);
    status = vsprintf(_multi_last_key, format, arglist);
    if ((strlen(_multi_last_key) + 1 > sizeof(_multi_last_key)) || (status == EOF)) qError("qValueFirst(): Message is too long or invalid.");
    va_end(arglist);

    if (_first_entry == NULL) qDecoder();
    _multi_last_entry = _first_entry;

    return qValueNext();
}
Exemplo n.º 5
0
int main(void) {
  char *list;

  qDecoder();

  qContentType("text/html");
  if((list = qValueFirst("checklist")) == NULL) qError("Check what you want to order please.");
  printf("You ordered ");
  for(; list; list = qValueNext()) {
    printf("<b>%s</b> \n", list);
  }

  qFree();
  return 0;
}
Exemplo n.º 6
0
/**********************************************
** Usage : qValueDefault(default string, query name);
** Return: Success pointer of value string, Fail using default string.
** Do    : If the query is not found, default string is used instead.
**********************************************/
char *qValueDefault(char *defstr, char *format, ...) {
    char    name[1024];
    int     status;
    va_list arglist;
    char    *value;

    va_start(arglist, format);
    status = vsprintf(name, format, arglist);
    if ((strlen(name) + 1 > sizeof(name)) || (status == EOF)) qError("qValueDefault(): Message is too long or invalid.");
    va_end(arglist);

    if (_first_entry == NULL) qDecoder();
    if ((value = _EntryValue(_first_entry, name)) == NULL) value = defstr;

    return value;
}
Exemplo n.º 7
0
/**********************************************
** Usage : qValueNotEmpty(error message, query name);
** Return: Success pointer of value string, Fail error message.
** Do    : Find value string pointer which is not empty and NULL.
**         When the query is not found or the value string is
**         empty, error message will be shown using qError().
**********************************************/
char *qValueNotEmpty(char *errmsg, char *format, ...) {
    char    name[1024];
    int     status;
    va_list arglist;
    char    *value;

    va_start(arglist, format);
    status = vsprintf(name, format, arglist);
    if ((strlen(name) + 1 > sizeof(name)) || (status == EOF)) qError("qValueNotEmpty(): Message is too long or invalid.");
    va_end(arglist);

    if (_first_entry == NULL) qDecoder();
    if ((value = _EntryValue(_first_entry, name)) == NULL) qError("%s", errmsg);
    if (!strcmp(value, "")) qError("%s", errmsg);

    return value;
}
Exemplo n.º 8
0
/**********************************************
** Usage : qValueType(name);
** Return: Cookie 'C', Get method 'G', Post method 'P', New data 'N', Not found '-'
** Do    : Returns type of query.
**
** ex) qValueRemove("NAME");
**********************************************/
char qValueType(char *format, ...) {
    char    name[1024];
    int     status;
    va_list arglist;
    int     v_no;

    va_start(arglist, format);
    status = vsprintf(name, format, arglist);
    if ((strlen(name) + 1 > sizeof(name)) || (status == EOF)) qError("qValue(): Message is too long or invalid.");
    va_end(arglist);

    if (_first_entry == NULL) qDecoder();

    v_no = _EntryNo(_first_entry, name);
    if ((1 <= v_no) && (v_no <= _cookie_cnt)) return 'C';
    else if ((_cookie_cnt + 1 <= v_no) && (v_no <= _cookie_cnt + _get_cnt)) return 'G';
    else if ((_cookie_cnt + _get_cnt + 1 <= v_no) && (v_no <= _cookie_cnt + _get_cnt + _post_cnt)) return 'P';
    else if ((_cookie_cnt + _get_cnt + _post_cnt <= v_no)) return 'N';

    return '-';
}
Exemplo n.º 9
0
/**********************************************
** Usage : qValueAdd(name, value);
** Do    : Force to add given name and value to linked list.
**         If same name exists, it'll be replaced.
**
** ex) qValueAdd("NAME", "Seung-young Kim");
**********************************************/
char *qValueAdd(char *name, char *format, ...) {
    Q_Entry *new_entry;
    char    value[1024];
    int     status;
    va_list arglist;

    if (!strcmp(name, "")) qError("qValueAdd(): can not add empty name.");

    va_start(arglist, format);
    status = vsprintf(value, format, arglist);
    if ((strlen(value) + 1 > sizeof(value)) || (status == EOF)) qError("qValueAdd(): Message is too long or invalid.");
    va_end(arglist);

    if (_first_entry == NULL) qDecoder();

    if (qValue(name) == NULL) _new_cnt++; // if it's new entry, count up.
    new_entry = _EntryAdd(_first_entry, name, value);
    if (!_first_entry) _first_entry = new_entry;

    return qValue(name);
}
Exemplo n.º 10
0
/**********************************************
** Usage : qValueReplace(mode, query name, token string, word);
** Return: String pointer which is new or replaced.
** Do    : Replace string or tokens as word from linked list
**         with given mode.
**
** Refer the description of qStrReplace() for more detail.
**********************************************/
char *qValueReplace(char *mode, char *name, char *tokstr, char *word) {
    Q_Entry *entries;
    char    *retstr, *repstr, method, memuse, newmode[2 + 1];

    /* initialize pointers to avoid compile warnings */
    retstr = repstr = NULL;

    if (_first_entry == NULL) qDecoder();

    if (strlen(mode) != 2) qError("qValueReplace(): Unknown mode \"%s\".", mode);
    method     = mode[0], memuse = mode[1];
    newmode[0] = method, newmode[1] = 'n', newmode[2] = '\0';

    if ((method != 't') && (method != 's')) qError("qValueReplace(): Unknown mode \"%s\".", mode);
    if (memuse == 'n') { /* new */
        if ((repstr = _EntryValue(_first_entry, name)) != NULL) {
            retstr = qStrReplace(newmode, repstr, tokstr, word);
        } else retstr = NULL;
    } else if (memuse == 'r') {   /* replace */
        /* To support multiful queries, it searches whole list and convert all of
           matched ones due to the possibility of duplicated query name.
           So when you need to do this replacement for duplicated query name,
           you can call this once before qValueFirst(). */
        for (retstr = NULL, entries = _first_entry; entries; entries = entries->next) {
            if (!strcmp(name, entries->name)) {
                repstr = qStrReplace(newmode, entries->value, tokstr, word);
                free(entries->value);
                entries->value = repstr;
                if (retstr == NULL) retstr = repstr; /* To catch first matched one */
            }
        }
    } else qError("qValueReplace(): Unknown mode \"%s\".", mode);

    /* Return the value of first matched one */
    return retstr;
}
Exemplo n.º 11
0
/**********************************************
** Usage : qGetFirstEntry();
** Do    : Return _first_entry.
**********************************************/
Q_Entry *qGetFirstEntry(void) {
    if (_first_entry == NULL) qDecoder();
    return _first_entry;
}