コード例 #1
0
ファイル: date.c プロジェクト: chopley/controlCode
/*.......................................................................
 * Convert a UTC date string to the equivalent Modified Julian Date.
 *
 * Input:
 *  date_string  char *  The string to be decoded, eg:
 *                        "12-may-1998 12:34:50" or "12-May-1998 3:45".
 * Input/Output:
 *  mjd        double *  The decoded Modified Julian Date.
 * Output:
 *  return        int    0 - OK.
 *                       1 - Error (an error message will have been
 *                                  sent to stderr).
 */
int date_to_mjd(char *date_string, double *mjd)
{
  InputStream *input = new_InputStream();
  if(!input ||
     open_StringInputStream(input, 0, date_string) ||
     input_utc(input, 1, 0, mjd)) {
    close_InputStream(input);
    return 1;
  };
  close_InputStream(input);
  del_InputStream(input); 
  return 0;
}
コード例 #2
0
ファイル: context.c プロジェクト: shidasan/konoha2
static kInputStream *new_InputStreamStdIn(CTX, kString *enc)
{
	kio_t *io2 = new_io2_stdio(_ctx, 0, 0);
	return new_InputStream(_ctx, io2, new_Path(_ctx, TS_DEVSTDIN));
}
コード例 #3
0
ファイル: evidence.c プロジェクト: utrhira/mpik
/* added by Wakamori */
void loadPolicy(CTX ctx)
{
	if (enforce_security == 0) return;
	// load $konoha.home.path/policy
	knh_setProperty(ctx, new_String(ctx, "role"), (dynamic *)new_String(ctx, role));
	CWB_t cwbbuf, *cwb = CWB_open0(ctx, &cwbbuf);
	kString *s = knh_getPropertyNULL(ctx, STEXT("konoha.home.path"));
	CWB_write(ctx, cwb, S_tobytes(s));
	CWB_write(ctx, cwb, STEXT("/policy"));
	kInputStream *is = new_InputStream(ctx, NULL, new_Path(ctx, CWB_newString0(ctx, cwb)));

	if (is == NULL) {
		DBG_P("policy file not found. All @Restricted annotated method is rescricted");
	}
	else {
		/*
		if (enforce_security == 0) {
			enforce_security = 1;
			knh_memcpy(role, "Default", 7);
			role[7] = '\0';
		}
		*/
		// parse policy file written in JSON
		// it must be refactored in the future
		kDictMap *dmap = ctx->share->securityDictMap;
		kString *line = knh_InputStream_readLine(ctx, is);
		while (IS_NOTNULL(line)) {
			//fprintf(stderr, "line=%s\n", S_totext(line));
			if (S_equals(line, STEXT("[")) || S_equals(line, STEXT("]"))) {
				/* ignore */
			} else {
				kString *key = NULL;
				kArray *a = new_Array(ctx, CLASS_String, 0);
				const char *idx = NULL;
				char *p = strstr(S_totext(line), "\"name\": \"");
				if (p != NULL) {
					p += 9; // == strlen("\"name\": \"")
					idx = strchr((const char *)p, '"');
					if (idx != NULL) {
						p[idx - p] = '\0';
						//fprintf(stderr, "name: %s\n", p);
						//knh_DictMap_set(ctx, dmap, new_String(ctx, "name"), new_String(ctx, p));
						key = new_String(ctx, p);
						p = (char *)idx + 1;
					}
				}
				p = strstr((const char *)p, "\"permission\": [");
				if (p != NULL) {
					p += 16; // == strlen("\"permission\": \[\"")
					idx = strchr((const char *)p, '"');
					while (idx != NULL) {
						p[idx - p] = '\0';
						if (strstr((const char *)p, ", ") == NULL) {
							//fprintf(stderr, "permission: %s\n", p);
							knh_Array_add(ctx, a, new_String(ctx, p));
						}
						p = (char *)idx + 1;
						idx = strchr((const char *)p, '"');
					}
				}
				if (key != NULL) {
					knh_DictMap_set(ctx, dmap, key, a);
				}
			}
			line = knh_InputStream_readLine(ctx, is);
		}
		knh_InputStream_close(ctx, is);
	}
}