Esempio n. 1
0
void FlickrSearchCriteria_Destroy(FlickrSearchCriteria *c)
{
  String_Destroy(&c->m_user_id);
/*   free(c->m_tags); */
  String_Destroy(&c->m_text); 
  FlickrDateSearchCriteria_Destroy(&c->m_date_criteria);
}
/* Methods */
void _PLMTPC_Destroy(PlayListManager manager)
{
	PlayListManager_PC state = (PlayListManager_PC)manager->InternalState;
	if(state != NULL)
	{
		sem_wait(&state->LockObject);
		sem_destroy(&state->LockObject);

		String_Destroy(state->UDN);
		String_Destroy(state->ServiceID);
		String_Destroy(state->ContainerID);
		String_Destroy(state->FirstItemID);
		String_Destroy(state->SortArgs);

		ClearMetadata(state);

		free(state);
	}
	if(manager->TrackURI != NULL)
	{
		free(manager->TrackURI);
	}
	if(manager->TrackMetaData != NULL)
	{
		CDS_ObjRef_Release(manager->TrackMetaData);
	}
	sem_destroy(&manager->LockObject);
	if(manager->ShuffleArray != NULL)
	{
		BitArray_Destroy(manager->ShuffleArray);
	}

	free(manager);
}
int main(int argc, char **argv)
{
  int rv = EXIT_SUCCESS;
  curl_global_init( CURL_GLOBAL_ALL ) ;
  FlickrClient *c = newFlickrClient(flickr_API_key, flickr_API_secret);
  {
    String find_email;
    String nsid, username;

    String_InitWithString(&find_email, findByEmail_input, strlen(findByEmail_input));
    String_Init(&nsid);
    String_Init(&username);

    flickr_people_findByUsername(c,&find_email,
				 &nsid,&username);
    
    if(0==String_CompareCString(&nsid,findByEmail_output_nsid))
      rv = EXIT_FAILURE;
    if(0==String_CompareCString(&username,findByEmail_output_username))
      rv = EXIT_FAILURE;
    
    String_Destroy(&find_email);
    String_Destroy(&nsid);
    String_Destroy(&username);
  }
  deleteFlickrClient(c);
  curl_global_cleanup() ;
  return rv;
}
Esempio n. 4
0
void FlickrBlog_Destroy(FlickrBlog *p)
{
  String_Destroy(&p->m_id);
  String_Destroy(&p->m_name);
  p->m_needspassword=0;
  String_Destroy(&p->m_url);
}
Esempio n. 5
0
void FlickrTag_Destroy(FlickrTag *tag)
{
  String_Destroy(&tag->m_author);
  String_Destroy(&tag->m_authorname);
  String_Destroy(&tag->m_raw);
  String_Destroy(&tag->m_tagbody);
}
BOOL _PLMTPC_Seek(PlayListManager manager, int trackNumber)
{
	PlayListManager_PC state = (PlayListManager_PC)manager->InternalState;
	BOOL result = FALSE;

	if(trackNumber >= state->StartingTrackNumber && trackNumber <= (state->StartingTrackNumber + state->Count - 1))
	{
		int index = trackNumber - state->StartingTrackNumber;
		if(manager->TrackMetaData != NULL)
		{
			CDS_ObjRef_Release(manager->TrackMetaData);
			manager->TrackMetaData = NULL;
		}
		String_Destroy(manager->TrackURI);
		manager->TrackURI = NULL;
		manager->TrackMetaData = state->Objects[index];
		CDS_ObjRef_Add(manager->TrackMetaData);
		manager->TrackNumber = trackNumber;
		manager->TrackURI = String_Create(manager->TrackMetaData->Res->Value);

		result = TRUE;
	}
	else
	{
		if(Browse(state, trackNumber) == TRUE)
		{
			if(manager->TrackMetaData != NULL)
			{
				CDS_ObjRef_Release(manager->TrackMetaData);
				manager->TrackMetaData = NULL;
			}
			String_Destroy(manager->TrackURI);
			manager->TrackURI = NULL;
			manager->TrackMetaData = state->Objects[0];
			CDS_ObjRef_Add(manager->TrackMetaData);
			manager->TrackNumber = trackNumber;
			manager->TrackURI = String_Create(manager->TrackMetaData->Res->Value);

			result = TRUE;
		}
		else
		{
			if(manager->TrackMetaData != NULL)
			{
				CDS_ObjRef_Release(manager->TrackMetaData);
				manager->TrackMetaData = NULL;
			}
			String_Destroy(manager->TrackURI);
			manager->TrackURI = NULL;

			result = FALSE;
		}
	}

	return result;
}
Esempio n. 7
0
File: httpd.c Progetto: tindzk/Jivai
def(void, Destroy) {
	String strFd = Integer_ToString(this->conn->ch.id);
	Logger_Info(this->logger, $("Closing connection (fd=%)."), strFd.rd);
	String_Destroy(&strFd);

	HTTP_Server_Destroy(&this->server);

	String_Destroy(&this->resp);
	String_Destroy(&this->path);
	String_Destroy(&this->paramTest);
	String_Destroy(&this->paramTest2);
}
Esempio n. 8
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;
}
Esempio n. 9
0
// destructor
static ESIF_INLINE void EqlCmd_dtor (EqlCmdPtr self)
{
	ASSERT(self);
	String_Destroy(self->adapter);
	String_Destroy(self->subtype);
	String_Destroy(self->action);
	StringList_Destroy(self->messages);
	StringList_Destroy(self->parameters);
	StringList_Destroy(self->datatypes);
	StringList_Destroy(self->values);
	StringList_Destroy(self->options);
	EsifDataList_Destroy(self->results);
	WIPEPTR(self);
}
Esempio n. 10
0
static def(String, BuildPath, String prefix, ListingItem *item, String ext) {
	String title = scall(Sanitize, item->title);
	String path  = Storage_BuildPath(this->storage, this->providerId);

	String res = String_Format($("%/%%%.%"),
		path,
		prefix, (prefix.len > 0) ? $(" ") : $(""),
		title, ext);

	String_Destroy(&path);
	String_Destroy(&title);

	return res;
}
Esempio n. 11
0
File: Time.c Progetto: tindzk/Jivai
sdef(String, Format, self time) {
	String hour   = Number_Format(time.hour,   2);
	String minute = Number_Format(time.minute, 2);
	String second = Number_Format(time.second, 2);

	String fmt = String_Format($("%:%:%"),
		hour.rd, minute.rd, second.rd);

	String_Destroy(&second);
	String_Destroy(&minute);
	String_Destroy(&hour);

	return fmt;
}
Esempio n. 12
0
def(void, Parse) {
	String path =
		Storage_GetCfgPath(
			Application_GetStorage(this->app));

	if (!Path_Exists(path)) {
		Logger_Fatal(this->logger,
			$("The subscriptions file % does not exist!"), path);

		goto out;
	}

	File file;
	File_Open(&file, path, FileStatus_ReadOnly);

	BufferedStream stream;
	BufferedStream_Init(&stream, File_AsStream(&file));
	BufferedStream_SetInputBuffer(&stream, 1024, 128);

	YAML yml;
	YAML_Init(&yml, 4, &BufferedStreamImpl, &stream);
	YAML_Parse(&yml);

	call(ParseSubscriptions, YAML_GetRoot(&yml));

	YAML_Destroy(&yml);

	BufferedStream_Close(&stream);
	BufferedStream_Destroy(&stream);

out:
	String_Destroy(&path);
}
Esempio n. 13
0
void HTTP_Client_GetResponse(String hostname, String path, unsigned short port, String *resp) {
	Socket socket = Socket_New(Socket_Protocol_TCP);

	SocketConnection conn = Socket_Connect(&socket, hostname, port);

	typedef void (^CleanupBlock)(void *, void *);

	CleanupBlock cleanup = ^(void *a, void *b) {
		SocketConnection_Close(a);
		Socket_Destroy(b);
	};

	String request = String_Format(
		$(
			"GET % HTTP/1.1\r\n"
			"Host: %\r\n"
			"Connection: Close\r\n"
			"\r\n"),
		path,
		hostname);

	try {
		SocketConnection_Write(&conn, request.buf, request.len);
	} clean finally {
		cleanup(&socket, &conn);
		String_Destroy(&request);
	} tryEnd;

	while (HTTP_Client_Receive(&conn, resp));
}
Esempio n. 14
0
void FStream_Destroy(FStream* pfStream)
{
  if (pfStream->pFile != NULL)
  {
    fclose(pfStream->pFile);
  }
  String_Destroy(&pfStream->fileName);
}
Esempio n. 15
0
// destructor
void StringList_dtor (StringListPtr self)
{
	if (self) {
		int i;
		for (i = 0; i < self->items; i++)
			String_Destroy(self->list[i]);
		esif_ccb_free(self->list);
		WIPEPTR(self);
	}
}
Esempio n. 16
0
static void getRelated_EndElementHandler(void *userData, const XML_Char *name)
{
  if(strcmp(name,"tag")==0) {
    getListUserArg *args = (getListUserArg*)userData;
    args->m_parsing_tag=0;
    
    ((void (*)(void *, String *))args->m_cb)(args->m_userData,&args->m_tag);
    String_Destroy(&args->m_tag);
  }
}
Esempio n. 17
0
def(void, Destroy) {
	CarrierString_Destroy(&this->host);
	String_Destroy(&this->resp);

	if (!this->closed) {
		call(Close);
	}

	SocketClient_Destroy(&this->socket);
}
Esempio n. 18
0
int main(int argc, char **argv)
{
  int rv = EXIT_SUCCESS;
  curl_global_init( CURL_GLOBAL_ALL ) ;
  FlickrClient *c = newFlickrClient(flickr_API_key, flickr_API_secret);
  {
    String url;

    String_Init(&url);
    
    if(argc==1) {
      String frob;
      
      String_Init(&frob);
      flickr_auth_getFrob(c, &frob);
      printf("frob=%s\n",String_GetString(&frob));
      
      flickr_auth_url(c,&frob, PERM_READ, &url);
      printf("url=%s\n",String_GetString(&url));
      String_Destroy(&frob);
    } else {
      String frob;
      String_InitWithString(&frob,argv[1],strlen(argv[1]));

      getTokenArg p;

      getTokenArg_Init(&p);
      flickr_auth_getToken(c,
			   &frob,
			   (void*)&p,
			   &copyGetTokenResult);
      printf("token=%s\n",String_GetString(&p.token));

      getTokenArg_Destroy(&p);
      String_Destroy(&frob);
    }
    String_Destroy(&url);
  }
  deleteFlickrClient(c);
  curl_global_cleanup() ;
  return rv;
}
Esempio n. 19
0
int main(void) {
	String resp = HeapString(1024 * 150); // Fetch max. 150 KiB

	HTTP_Client_GetResponse($("www.kernel.org"), $("/"), 80, &resp);

	String_Print(resp);

	String_Destroy(&resp);

	return ExitStatus_Success;
}
Esempio n. 20
0
void FlickrPerson_Destroy(FlickrPerson *person)
{
  String_Destroy(&person->m_nsid);
  String_Destroy(&person->m_username);
  String_Destroy(&person->m_realname);
  String_Destroy(&person->m_location);
  String_Destroy(&person->m_photosurl);
  String_Destroy(&person->m_profileurl);
  String_Destroy(&person->m_firstdatetaken);
}
Esempio n. 21
0
static void printFlickrPhoto(const FlickrPhoto *p) {
  String url;
  
  String_Init(&url);
  
  flickr_build_photo_url(p->m_id,
			 atoi(p->m_server.m_start),
			 &p->m_secret,
			 PHOTO_SZ_THUMBNAIL,
			 &url);
  
  printf("%s\n",String_GetString(&url));
  String_Destroy(&url);
}
Esempio n. 22
0
int main(void) {
	Socket socket = Socket_New(Socket_Protocol_TCP);

	SocketConnection conn =
		Socket_Connect(&socket, $("www.kernel.org"), 80);

	String d1, d2;

	String_Print(
		d1 = String_Format(
			$("Connected to %:%\n\n"),
			d2 = NetworkAddress_ToString(conn.addr),
			Int16_ToString(conn.addr.port)));

	String_Destroy(&d2);
	String_Destroy(&d1);

	String request = $(
		"GET / HTTP/1.1\r\n"
		"Host: www.kernel.org\r\n"
		"Connection: Close\r\n"
		"\r\n");

	SocketConnection_Write(&conn, request.buf, request.len);

	String response = StackString(2048);

	response.len = SocketConnection_Read(&conn, response.buf, response.size);

	String_Print(response);

	SocketConnection_Close(&conn);

	Socket_Destroy(&socket);

	return ExitStatus_Success;
}
Esempio n. 23
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);
}
Esempio n. 24
0
def(void, SaveText, String prefix, ListingItem *item, String text) {
	File file;

	String path = call(BuildPath, prefix, item, $("txt"));

	File_Open(&file, path,
			FileStatus_Create   |
			FileStatus_Truncate |
			FileStatus_WriteOnly);

	String_Destroy(&path);

	File_Write(&file, text);

	File_Close(&file);

	Logger_Info(this->logger, $("Saved transcript."));
}
Esempio n. 25
0
void FlickrPhotoInfo_Destroy(FlickrPhotoInfo *info)
{
  String_Destroy(&info->m_id);
  String_Destroy(&info->m_secret);
  String_Destroy(&info->m_server);
  
  FlickrPhotoOwner_Destroy(&info->m_owner);
  String_Destroy(&info->m_title);
  String_Destroy(&info->m_description);
  FlickrPhotoDates_Destroy(&info->m_dates);

  String_Destroy(&info->m_photopage);

  free(&info->m_notes);
  free(&info->m_tags);
}
Esempio n. 26
0
File: httpd.c Progetto: tindzk/Jivai
def(void, Init, Server_Client *client, Logger *logger) {
	this->logger     = logger;
	this->client     = client;
	this->conn       = &client->socket.conn;
	this->resp       = String_New(2048);
	this->method     = HTTP_Method_Get;
	this->version    = HTTP_Version_1_0;
	this->persistent = false;
	this->path       = String_New(0);

	/* paramTest and paramTest2 must not be longer than 256 bytes,
	 * otherwise an `HTTP_Query_ExceedsPermittedLengthException'
	 * exception will be thrown.
	 */

	this->paramTest  = String_New(256);
	this->paramTest2 = String_New(256);

	this->server = HTTP_Server_New(this->conn, 2048, 4096);

	HTTP_Server_BindRequest(&this->server,
		HTTP_Server_OnRequest_For(this, ref(OnRequest)));

	HTTP_Server_BindRequestInfo(&this->server,
		HTTP_OnRequestInfo_For(this, ref(OnRequestInfo)));

	HTTP_Server_BindQueryParameter(&this->server,
		HTTP_OnParameter_For(this, ref(OnQueryParameter)));

	HTTP_Server_BindBodyParameter(&this->server,
		HTTP_OnParameter_For(this, ref(OnBodyParameter)));

	HTTP_Server_BindRespond(&this->server,
		HTTP_Server_OnRespond_For(this, ref(OnRespond)));

	String strFd = Integer_ToString(this->conn->ch.id);
	Logger_Info(this->logger, $("Incoming connection (fd=%)."), strFd.rd);
	String_Destroy(&strFd);
}
Esempio n. 27
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);

	for (;;) {
		s.len = Channel_Read(procItem->entry->ch, s.buf, String_GetSize(s));

		if (s.len == 0) {
			break;
		}

		System_out($("read data='"));
		System_out(s.rd);
		System_out($("'\n"));
	}

	String_Destroy(&s);
}
Esempio n. 28
0
BOOL ParsePlayContainerUri(PlayListManager_PC state, char* uri)
{
	struct parser_result_field* field;
	struct parser_result* parseResults;
	int length;
	char* pos = NULL;
	char* tmp = NULL;

	uri = PC_UriUnescape(uri);
	pos = uri + 21;

	if(ILibString_StartsWith(uri, (int)strlen(uri), "dlna-playcontainer://", 21) == 0)
	{
		free(uri);
		return FALSE;
	}
	if(ILibString_StartsWithEx(pos, (int)strlen(pos), "uuid:", 5, 0) != 0)
	{
		pos += 5;
	}
	{
		char out[4096];
		sprintf(out, "%s\n", pos);
		OutputDebugString(out);
	}
	tmp = MyStrChr(pos, 0x003f);
	{
		char out[4096];
		sprintf(out, "%s\n", tmp);
		OutputDebugString(out);
	}
	if(tmp == NULL)
	{
		free(uri);
		return FALSE;
	}
	length = (int)(tmp - pos);
	String_Destroy(state->UDN);
	state->UDN = String_CreateSize(length);
	strncpy(state->UDN, pos, (size_t)length);
	state->UDN[length] = 0;
	if(state->UDN[length - 1] == '/')
	{
		state->UDN[length - 1] = 0;
	}
	pos += length + 1;

	parseResults = ILibParseString(pos, 0, (int)strlen(pos), "&", 1);

	state->FirstItemIndex = -1;

	field = parseResults->FirstResult;
	while(field != NULL)
	{
		int length;
		char* val = field->data;
		if(ILibString_StartsWith(field->data, field->datalength, "sid=", 4) != 0)
		{
			length = field->datalength - 4;
			val += 4;
			String_Destroy(state->ServiceID);
			state->ServiceID = String_CreateSize(length);
			strncpy(state->ServiceID, val, (size_t)length);
			state->ServiceID[length] = 0;
		}
		else if(ILibString_StartsWith(field->data, field->datalength, "cid=", 4) != 0)
		{
			length = field->datalength - 4;
			val += 4;
			String_Destroy(state->ContainerID);
			state->ContainerID = String_CreateSize(length);
			strncpy(state->ContainerID, val, (size_t)length);
			state->ContainerID[length] = 0;
		}
		else if(ILibString_StartsWith(field->data, field->datalength, "fid=", 4) != 0)
		{
			length = field->datalength - 4;
			val += 4;
			String_Destroy(state->FirstItemID);
			state->FirstItemID = String_CreateSize(length);
			strncpy(state->FirstItemID, val, (size_t)length);
			state->FirstItemID[length] = 0;
		}
		else if(ILibString_StartsWith(field->data, field->datalength, "fii=", 4) != 0)
		{
			char* tmp = NULL;
			length = field->datalength - 4;
			val += 4;
			tmp = String_CreateSize(length);
			strncpy(tmp, val, length);
			tmp[length] = 0;
			state->FirstItemIndex = atoi(tmp);
			String_Destroy(tmp);
		}
		else if(ILibString_StartsWith(field->data, field->datalength, "sc=", 3) != 0)
		{
			length = field->datalength - 3;
			val += 3;
			String_Destroy(state->SortArgs);
			state->SortArgs = String_CreateSize(length);
			strncpy(state->SortArgs, val, (size_t)length);
			state->SortArgs[length] = 0;
		}
		else if(ILibString_StartsWith(field->data, field->datalength, "md=", 3) != 0)
		{
			char* tmp = NULL;
			length = field->datalength - 3;
			val += 3;
			tmp = String_CreateSize(length);
			strncpy(tmp, val, length);
			tmp[length] = 0;
			state->MaxDepth = atoi(tmp);
			String_Destroy(tmp);
		}
		else
		{
			String_Destroy(state->UDN);
			String_Destroy(state->ServiceID);
			String_Destroy(state->ContainerID);
			String_Destroy(state->FirstItemID);
			String_Destroy(state->SortArgs);
			ILibDestructParserResults(parseResults);

			return FALSE;
		}
		field = field->NextResult;
	}

	ILibDestructParserResults(parseResults);

	if(state->ServiceID != NULL && state->ContainerID != NULL && state->FirstItemID != NULL && state->FirstItemIndex != -1)
	{
		free(uri);
		return TRUE;
	}
	else
	{
		String_Destroy(state->UDN);
		String_Destroy(state->ServiceID);
		String_Destroy(state->ContainerID);
		String_Destroy(state->FirstItemID);
		String_Destroy(state->SortArgs);

		free(uri);
		return FALSE;
	}
}
Esempio n. 29
0
void SStream_Destroy(SStream* pfStream)
{
  String_Destroy(&pfStream->name);
}
Esempio n. 30
0
void FStream_Destroy(FStream* pfStream)
{
  File_Destroy(&pfStream->file);  
  String_Destroy(&pfStream->fileName);
}