コード例 #1
0
ファイル: jsmn.c プロジェクト: drewt/psnet
int jsmn_get_values (const char *msg, jsmntok_t *obj, ...)
{
    va_list ap;
    char *key;
    int *i;
    int rc = 0;

    va_start (ap, obj);

    key = va_arg (ap, char*), i = va_arg (ap, int*);
    for (; key && i; key = va_arg (ap, char*), i = va_arg (ap, int*))
        if ((*i = jsmn_get_value (msg, obj, key)) == -1)
            rc = -1;

    va_end (ap);

    return rc;
}
コード例 #2
0
ファイル: httpd.c プロジェクト: timurey/oryx_stm32f205
static error_t parseHttpdConfig (char *data, size_t len, jsmn_parser* jSMNparser, jsmntok_t *jSMNtokens)
{
   uint8_t httpEnable = 0;
   jsmnerr_t resultCode;
   int tokNum;
   int length;
   jsmn_init(jSMNparser);
   resultCode = jsmn_parse(jSMNparser, data, len, jSMNtokens, CONFIG_JSMN_NUM_TOKENS);
   if (resultCode >0 )
   {
      tokNum = jsmn_get_value(data, jSMNtokens, resultCode, "/config/port");
      if (tokNum >= 0)
      {
         httpServerSettings.port = atoi(&data[jSMNtokens[tokNum].start]);
         httpEnable++;

      }

      tokNum = jsmn_get_value(data, jSMNtokens, resultCode, "/config/max connections");
      if (tokNum >= 0)
      {
         httpServerSettings.maxConnections = MIN (atoi(&data[jSMNtokens[tokNum].start]), APP_HTTP_MAX_CONNECTIONS);
         httpEnable++;

      }

      tokNum = jsmn_get_value(data, jSMNtokens, resultCode, "/config/root directory");
      if (tokNum >= 0)
      {
         length = jSMNtokens[tokNum].end - jSMNtokens[tokNum].start;
         if (length<=HTTP_SERVER_ROOT_DIR_MAX_LEN)
         {
            memcpy(&httpServerSettings.rootDirectory, &data[jSMNtokens[tokNum].start], length);
            httpServerSettings.rootDirectory[length]='\0';

            httpEnable++;
         }

      }
#if (HTTP_SERVER_GZIPED_FILES == ENABLED)
      tokNum = jsmn_get_value(data, jSMNtokens, resultCode, "/config/gziped directory");
      if (tokNum >= 0)
      {
         length = jSMNtokens[tokNum].end - jSMNtokens[tokNum].start;
         if (length<=HTTP_SERVER_ROOT_DIR_MAX_LEN)
         {
            memcpy(&httpServerSettings.gzipedDirectory, &data[jSMNtokens[tokNum].start], length);
            httpServerSettings.gzipedDirectory[length]='\0';

            httpEnable++;
         }

      }
#else
      httpEnable++;
#endif
      tokNum = jsmn_get_value(data, jSMNtokens, resultCode, "/config/default document");
      if (tokNum >= 0)
      {
         length = jSMNtokens[tokNum].end - jSMNtokens[tokNum].start;
         if (length<=HTTP_SERVER_DEFAULT_DOC_MAX_LEN)
         {
            memcpy(&httpServerSettings.defaultDocument, &data[jSMNtokens[tokNum].start], length);
            httpServerSettings.defaultDocument[length]='\0';

            httpEnable++;
         }

      }

      if (httpEnable<5)
         httpdUseDefaultConfig();

      return NO_ERROR;
   }
   else
   {
      httpdUseDefaultConfig();
      return NO_ERROR;
   }
}