Ejemplo n.º 1
0
static int
MimeInlineTextVCard_parse_line (const char *line, int32_t length, MimeObject *obj)
{
  // This routine gets fed each line of data, one at a time.
  char* linestring;
  MimeInlineTextVCardClass *clazz = ((MimeInlineTextVCardClass *) obj->clazz);

  if (!obj->output_p) return 0;
  if (!obj->options || !obj->options->output_fn) return 0;
  if (!obj->options->write_html_p)
  {
    return COM_MimeObject_write(obj, line, length, true);
  }

  linestring = (char *) PR_MALLOC (length + 1);
  memset(linestring, 0, (length + 1));

  if (linestring)
  {
    strcpySafe((char *)linestring, line, length + 1);
    NS_MsgSACat (&clazz->vCardString, linestring);
    PR_Free (linestring);
  }

  return 0;
}
Ejemplo n.º 2
0
	PHYSFS_File *openReadHandle(const char *filename,
	                            char *extBuf,
	                            size_t extBufN)
	{
		char found[512];

		if (!completeFilename(filename, found, sizeof(found)))
			throw Exception(Exception::NoFileError, "%s", filename);

		PHYSFS_File *handle = PHYSFS_openRead(found);

		if (!handle)
			throw Exception(Exception::PHYSFSError, "PhysFS: %s", PHYSFS_getLastError());

		if (!extBuf)
			return handle;

		for (char *q = found+strlen(found); q > found; --q)
		{
			if (*q == '/')
				break;

			if (*q != '.')
				continue;

			strcpySafe(extBuf, q+1, extBufN, -1);
			break;
		}

		return handle;
	}
Ejemplo n.º 3
0
	bool completeFilenameReg(const char *filepath,
	                         char *outBuffer,
	                         size_t outN)
	{
		strcpySafe(outBuffer, filepath, outN, -1);

		size_t len = strlen(outBuffer);
		char *delim;

		/* Find the deliminator separating directory and file name */
		for (delim = outBuffer + len; delim > outBuffer; --delim)
			if (*delim == '/')
				break;

		bool root = (delim == outBuffer);
		CompleteFilenameData d;

		if (!root)
		{
			/* If we have such a deliminator, we set it to '\0' so we
			 * can pass the first half to PhysFS as the directory name,
			 * and compare all filenames against the second half */
			d.outBuf = delim+1;
			d.filenameLen = len - (delim - outBuffer + 1);

			*delim = '\0';
		}
		else
		{
			/* Otherwise the file is in the root directory */
			d.outBuf = outBuffer;
			d.filenameLen = len - (delim - outBuffer);
		}

		d.found = false;
		d.outBufN = outN - (d.outBuf - outBuffer);

		PHYSFS_enumerateFilesCallback(root ? "" : outBuffer, completeFilenameRegCB, &d);

		if (!d.found)
			return false;

		/* Now we put the deliminator back in to form the completed
		 * file path (if required) */
		if (delim != outBuffer)
			*delim = '/';

		return true;
	}
Ejemplo n.º 4
0
	bool completeFilenamePC(const char *filepath,
	                        char *outBuffer,
	                        size_t outN)
	{
		std::string lowCase(filepath);

		for (size_t i = 0; i < lowCase.size(); ++i)
			lowCase[i] = tolower(lowCase[i]);

		if (!pathCache.contains(lowCase))
			return false;

		const std::string &fullPath = pathCache[lowCase];
		strcpySafe(outBuffer, fullPath.c_str(), outN, fullPath.size());

		return true;
	}
Ejemplo n.º 5
0
	static void completeFilenameRegCB(void *data, const char *,
	                                  const char *fname)
	{
		CompleteFilenameData &d = *static_cast<CompleteFilenameData*>(data);

		if (d.found)
			return;

		if (strncmp(d.outBuf, fname, d.filenameLen) != 0)
			return;

		/* If fname matches up to a following '.' (meaning the rest is part
		 * of the extension), or up to a following '\0' (full match), we've
		 * found our file */
		switch (fname[d.filenameLen])
		{
		case '.' :
			/* Overwrite the incomplete file name we looked for with
			 * the full version containing any extensions */
			strcpySafe(d.outBuf, fname, d.outBufN, -1);
		case '\0' :
			d.found = true;
		}
	}