示例#1
0
文件: httpd.c 项目: tindzk/Jivai
def(String *, OnQueryParameter, RdString name) {
	if (String_Equals(name, $("test"))) {
		/* test's value will be put into this variable. */
		return &this->paramTest;
	} else if (String_Equals(name, $("test2"))) {
		return &this->paramTest2;
	}

	/* Ignore all other parameters */
	return NULL;
}
示例#2
0
文件: Method.c 项目: tindzk/Jivai
sdef(self, FromString, RdString s) {
	if (String_Equals(s, $("GET"))) {
		return ref(Get);
	} else if (String_Equals(s, $("POST"))) {
		return ref(Post);
	} else if (String_Equals(s, $("HEAD"))) {
		return ref(Head);
	}

	return ref(Unset);
}
示例#3
0
static Int32 AsyncRequestList_Find(STRING_PURE String* id, AsyncRequest* item) {
	Int32 i;
	for (i = 0; i < async_processed.Count; i++) {
		String reqID = String_FromRawArray(async_processed.Requests[i].ID);
		if (!String_Equals(&reqID, id)) continue;

		*item = async_processed.Requests[i];
		return i;
	}
	return -1;
}
示例#4
0
文件: System.c 项目: tindzk/Jivai
/* We use __environ allowing us to use this function in constructors. */
sdef(bool, IsRunningOnValgrind) {
	assert(__environ != NULL);

	for (char **cur = __environ; *cur != NULL; cur++) {
		RdString item = String_FromNul(*cur);

		if (String_Equals(item, $("_=/usr/bin/valgrind"))) {
			return true;
		}
	}

	return false;
}
示例#5
0
文件: System.c 项目: tindzk/Jivai
sdef(bool, IsDebugging) {
	assert(__environ != NULL);

	for (char **cur = __environ; *cur != NULL; cur++) {
		RdString item = String_FromNul(*cur);

		if (String_Equals(item, $("DEBUG=yes"))) {
			return true;
		}
	}

	return false;
}
示例#6
0
/* Adds all locales from the program's external libraries. */
static sdef(int, onLibrary, struct dl_phdr_info *info, __unused size_t size, void *data) {
	DynInstName(self) $this = (DynInstName(self)) (self *) data;

	RdString path = String_FromNul((char *) info->dlpi_name);
	path.len != 0 || ret(0);

	RdString ext      = Path_getFileExtension(path);
	RdString fileName = Path_getFileName(path);

	Logger_Debug(&this->logger, $("Found external library %."), fileName);

	if (!String_Equals(ext, $("dll"))) {
		Logger_Debug(&this->logger, $("Incompatible library extension."));
		return 0;
	}

	String realPath;
	if (Path_isLink(path)) {
		realPath = Path_followLink(path);
	} else {
		realPath = String_Clone(path);
	}

	RdString folderPath = Path_getFolderPath(realPath.rd);
	RdString context    = String_Slice(fileName, 0, -4);

	String lngpath = String_Format($("%Locale/"), folderPath);

	if (!Path_exists(lngpath.rd)) {
		Logger_Debug(&this->logger, $("External library % has no locales."),
			context);
		String_Destroy(&lngpath);
	} else {
		if (Locale_hasContext(Locale_GetInstance(), context)) {
			Logger_Error(&this->logger, $(
				"The locale context % was already registered. Possibly "
				"the program maintains a local copy of its external locales."),
				context);
		} else {
			Logger_Debug(&this->logger,
				$("Adding locale directory % (for external library %)."),
				lngpath.rd, context);

			Locale_addContext(Locale_GetInstance(), context, lngpath);
		}
	}

	String_Destroy(&realPath);

	return 0;
}
示例#7
0
static def(void, ParseSubscriptions, YAML_Node *node) {
	for (size_t i = 0; i < node->len; i++) {
		YAML_Node *child = node->buf[i];
		ProviderFacadeInstance provider = ProviderFacade_Null();

		if (child->type == YAML_NodeType_Item) {
			Logger_Debug(this->logger,
				$("Adding provider '%' (%)..."),
				YAML_Item(child)->value,
				YAML_Item(child)->key);

			provider = call(NewProvider, YAML_Item(child)->key);

			if (!ProviderFacade_IsNull(provider)) {
				ProviderFacade_SetName(provider,
					YAML_Item(child)->value);
			}
		} else if (child->type == YAML_NodeType_Section) {
			Logger_Debug(this->logger,
				$("Adding provider '%'..."),
				YAML_Section(child)->name);

			provider = call(NewProvider, YAML_Section(child)->name);
		}

		if (!ProviderFacade_IsNull(provider) && child->len > 0) {
			for (size_t j = 0; j < child->buf[0]->len; j++) {
				YAML_Node *_child = child->buf[0]->buf[j];

				if (_child->type == YAML_NodeType_Item) {
					String key   = YAML_Item(_child)->key;
					String value = YAML_Item(_child)->value;

					if (String_Equals(key, $("limit"))) {
						ProviderFacade_SetLimit(provider,
							Int32_Parse(value));
					} else {
						bool handled = ProviderFacade_SetOption(
							provider, key, value);

						if (!handled) {
							ProviderFacade_AddSource(provider,
								YAML_Item(_child)->value);
						}
					}
				}
			}
		}
	}
}
示例#8
0
void FileResponse(Response *resp, RdString path, DateTime lastModified) {
	try {
		File file = File_New(path, FileStatus_ReadOnly);

		Stat64 attr = File_GetStat(&file);

		if (!BitMask_Has(attr.mode, FileMode_Regular)) {
			Response_SetStatus(resp, HTTP_Status_ClientError_NotFound);
			BufferResponse(resp, $$("Not a file."));
			// Logger_Error(&logger, $("Not a file."));
		} else {
			DateTime fileTime = DateTime_FromUnixEpoch(attr.mtime.sec);

			if (DateTime_Compare(lastModified, fileTime) >= 0) {
				// Logger_Debug(&logger, $("No need to send file."));
				Response_SetStatus(resp, HTTP_Status_Redirection_NotModified);
			} else {
				// Logger_Debug(&logger, $("Sending file..."));

				RdString ext = Path_GetExtension(path);

				Response_SetContentType(resp,
					String_ToCarrier($$("application/octet-stream")));

				fwd(i, MimeTypes_Length) {
					if (String_Equals(ext, MimeTypes[i].extension)) {
						Response_SetContentType(resp,
							String_ToCarrier(
								RdString_Exalt(
									MimeTypes[i].mimeType)));

						break;
					}
				}

				Response_SetFileBody    (resp, file, attr.size);
				Response_SetLastModified(resp, fileTime);
			}

			Response_Flush(resp);
		}
	} catch(File, NotFound) {
		Response_SetStatus(resp, HTTP_Status_ClientError_NotFound);
		BufferResponse(resp, $$("File not found."));
		// Logger_Error(&logger, $("File not found."));
	} catch(File, AccessDenied) {
示例#9
0
static sdef(void, onData, Instance inst) {
	ref(Process) *procItem = inst.addr;

	printf("onData fd=%i\n", procItem->entry->ch->id);
	fflush(stdout);

	String s = String_New(1024);
	s.len = Channel_Read(procItem->entry->ch, s.buf, String_GetSize(s));

	if (String_Equals(s.rd, $("Hello World\n"))) {
		System_out($("Received 'Hello World'.\n"));
	} else {
		System_out($("Received unexpected data."));
	}

	String_Destroy(&s);
}
示例#10
0
文件: Client.c 项目: tindzk/Jivai
static def(void, OnHeader, RdString name, RdString value) {
	callback(this->onHeader, name, value);

	String_ToLower((String *) &name);

	if (String_Equals(name, $("connection"))) {
		String_ToLower((String *) &value);

		if (String_Equals(value, $("close"))) {
			this->keepAlive = false;
		} else if (String_Equals(value, $("keep-alive"))) {
			this->keepAlive = true;
		}
	} else if (String_Equals(name, $("transfer-encoding"))) {
		if (String_Equals(value, $("chunked"))) {
			this->chunked = true;
		}
	} else if (String_Equals(name, $("content-length"))) {
		this->total = Int64_Parse(value);
	}
}
示例#11
0
文件: Downloader.c 项目: tindzk/podfm
static def(void, OnHeader, String name, String value) {
	if (String_Equals(name, $("Location"))) {
		String_Copy(&this->location, value);
	}
}