How to change libwebsockets color scheme - libwebsockets

I am using libwebsockets library. This exposes certain methods for writing into a log file.
lwsl_warn(...), lwsl_err(...) and lwsl_err(...)
to name the most common.
The output is color coded using ANSI sequences.
Is there a way to set the default color scheme (other than recompiling the library)?
Thanks.

I poked around in the libwebsockets source and found my answer:
The colors are hard coded - so the answer to my original question is "no".
However, the color scheme is not hard to find and edit. It resides in two source files - one of these is compiled depending on options:
libwebsockets/lib/core/logs.c
and
libwebsockets/lib/plat/optee/lws-plat-optee.c
All it takes is to edit the self-explanatory table:
static const char * const colours[] = {
"[31;1m", /* LLL_ERR */
"[36;1m", /* LLL_WARN */
"[35;1m", /* LLL_NOTICE */
"[32;1m", /* LLL_INFO */
"[34;1m", /* LLL_DEBUG */
"[33;1m", /* LLL_PARSER */
"[33m", /* LLL_HEADER */
"[33m", /* LLL_EXT */
"[33m", /* LLL_CLIENT */
"[33;1m", /* LLL_LATENCY */
"[0;1m", /* LLL_USER */
"[31m", /* LLL_THREAD */
};
Then build as before. Once in the libwebsockets/build directory do the following:
make clean
make && sudo make install
sudo ldconfig
... and enjoy!

Related

Explain fst_posmode, difference between F_PEOFPOSMODE and F_VOLPOSMODE?

Header file:
/* Position Modes (fst_posmode) for F_PREALLOCATE */
#define F_PEOFPOSMODE 3 /* Make it past all of the SEEK pos modes so that */
/* we can keep them in sync should we desire */
#define F_VOLPOSMODE 4 /* specify volume starting postion */
Man page:
The position modes (fst_posmode) for the F_PREALLOCATE command indicate how to use the offset field.
The modes are as follows:
F_PEOFPOSMODE Allocate from the physical end of file.
F_VOLPOSMODE Allocate from the volume offset.
The doc is hard to understand.

How to read GetDeviceCaps() return values?

I am new to Windows API and I just can't seem to figure this out:
According to the documentation the function int GetDeviceCaps(HDC hdc,int index); returns integer values which correspond to the selected item I want to know about. However, how am I supposed to convert the integers to the values?
printf("Rastercaps: %d\n", GetDeviceCaps(hdc, RASTERCAPS));
// rastercaps: 32409
item RASTERCAPS:
values
RC_BANDING Requires banding support.
RC_BITBLT Capable of transferring bitmaps.
RC_BITMAP64 Capable of supporting bitmaps larger than 64 KB.
RC_DI_BITMAP Capable of supporting the SetDIBits and GetDIBits
functions.
RC_DIBTODEV Capable of supporting the SetDIBitsToDevice
function.
RC_FLOODFILL Capable of performing flood fills.
...
Does 32409 mean the device has RASTERCAP values (capabilities) 3,2,4,0 and 9, in the order as stated in their table?
Thank you.
They're bitmasks. In the relevant C header file (wingdi.h) there is
/* Raster Capabilities */
#define RC_NONE
#define RC_BITBLT 1 /* Can do standard BLT. */
#define RC_BANDING 2 /* Device requires banding support */
#define RC_SCALING 4 /* Device requires scaling support */
#define RC_BITMAP64 8 /* Device can support >64K bitmap */
...and many more.
The return value (32409) is made up of the bitwise-or of these values. So, for example, if you wanted to know if the device could support >64K bitmap you would do
int rc = GetDeviceCaps(hdc, RASTERCAPS);
if (rc & RC_BITMAP64) { /* it does support >64k */ }
So in this case, 32409 is 0111111010011001 in binary which means it has the capabilities RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DI_BITMAP |
RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_FLOODFILL | RC_STRETCHDIB | RC_OP_DX_OUTPUT.
See "Bitwise operations in C"

PBXBuildFile vs PBXFileReference section

What is the difference between PBXBuildFile and PBXFileReference in project.pbxproj? Does it matter if a file is listed in both of the sections? What is the policy what file in which section should get?
/* Begin PBXBuildFile section */
3D081B83146ACE36000CC86B /* B767.png in Resources */ = {isa = PBXBuildFile; fileRef = 3D081B82146ACE36000CC86B /* B767.png */; };
/* Begin PBXFileReference section */
3D081B82146ACE36000CC86B /* B767.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = B767.png; sourceTree = "<group>"; };
You should normally never have to worry about this, but it can come up in certain merge conflicts in the project.pbxproj file.
A PBXFileReference is a reference to the actual file. It's the object that backs up the files that appear in the left-hand project view.
A PBXBuildFile is a file in a target. It wraps a PBXFileReference and adds certain attributes like per-file compiler flags. If a file is added to a target, it will be listed in both sections. If a file is in more than one target, it will have more than one PBXBuildFile in the build files section.

System() command not working when enabling app sandboxing

Apple now require all future apps to be sandboxed and so I followed the instructions to sandbox an app. The build succeeded but then my system(rm -rf ~/.Trash/*) command stopped working. Nothing happened. What I find confusing here is why this system command does not work with App Sandboxing/Entitlements on. Here is are my entitlement settings:
Entitlements: Checked
App Sandboxing: Checked
And here is my current code:
- (void)viewDidLoad {
[self emptyTrash];
}
- (void)emptyTrash {
system(rm -rf ~/.Trash/*);
}
Thanks for your help!
Take a look at documentation.
Mac OS X path-finding APIs, above the POSIX layer, return paths
relative to the container instead of relative to the user’s home
directory. If your app, before you sandbox it, accesses locations in
the user’s actual home directory (~) and you are using Cocoa or Core
Foundation APIs, then, after you enable sandboxing, your path-finding
code automatically uses your app’s container instead.
you can use
struct passwd *getpwuid(uid_t uid);
struct passwd {
char *pw_name; /* user name */
char *pw_passwd; /* encrypted password */
uid_t pw_uid; /* user uid */
gid_t pw_gid; /* user gid */
__darwin_time_t pw_change; /* password change time */
char *pw_class; /* user access class */
char *pw_gecos; /* Honeywell login info */
char *pw_dir; /* home directory */
char *pw_shell; /* default shell */
__darwin_time_t pw_expire; /* account expiration */
}
#include <pwd.h>
#include <sys/types.h>
char *HomeDirectory = getpwuid(getuid())->pw_dir;
NSLog(#"%s", HomeDirectory);
system([[NSString stringWithFormat:#"rm -rf %s/.Trash/",HomeDirectory] UTF8String]);

organizing xcode 4.0 copy bundle resources

Is there an easy way to organize the files within the Copy Bundle Resources in xcode 4.0? I have multiple targets for my project, and every time I add files, I need to, most of the time, add them to every project. It would help a great deal if I had an easy way to catch myself when I mistakenly forget to copy resources to every target (other than just looking at the count of files in the bundle, which will eventually diverge from being the same for each project).
It'd be a lot easier if I could make folders within the resources list, but it doesn't seem I can. At the very least it might help if I could automatically alphabetize them.
What you have to do is to parse .pbxproj file. All linked file and resources in .pbxproj are identified from their own UUID. So,
Get the rootObject's UUID
Get list of targets UUID from rootObjects
For each target get the list of UUID for Resource, Source and Framework. And
find the list of files UUID for all of the three resource types
Compare the list of resources for each of the targets.
Some hints,
The format of the project file is like this, the rootObject refer to other objects.
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* .... List of all objects are here .... */
}
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}
From the rootObject we can follow the targets value.
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MyProject" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
German,
de,
);
mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
projectDirPath = "";
projectRoot = "";
targets = (
1D6058900D05DD3D006BFB54 /* TargetDebug */,
C446CDCB12BA35A1001324C8 /* TargetAdHoc */,
C446CF2D12BA3DDC001324C8 /* TargetAppStore */,
);
};
/* End PBXProject section */
In the target section of the project file, buildPhases contains the link to the copied bundle resources list and link.
/* Begin PBXNativeTarget section */
1D6058900D05DD3D006BFB54 /* TargetAdHoc */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "TargetAdHoc" */;
buildPhases = (
1D60588D0D05DD3D006BFB54 /* Resources */,
1D60588E0D05DD3D006BFB54 /* Sources */,
1D60588F0D05DD3D006BFB54 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = TargetAdHoc;
productName = MyProject;
productReference = 1D6058910D05DD3D006BFB54 /* MyProject.app */;
productType = "com.apple.product-type.application";
};
C446CDCC12BA35A1001324C8 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C446CDCD12BA35A1001324C8 /* MainWindow.xib in Resources */,
/* ....... list of all PNGs and XIB files..... */
81CDEBBF13B21B790067A088 /* AnImage.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
(on Xcode 3.2.x): You can alphabetize the files in a phase by selecting the phase, then Edit -> Sort -> By Name.
As far as breaking them up into "folders" -- nothing is stopping you from having multiple Copy phases! You can even give each one a descriptive name.
Don't know if it's helpful in this instance, but in Xcode, when you select a file and Get Info on it (command-I), one of the tabs is "Targets." From there, you can select all the targets you want a file to be a part of. I believe that for non-compiled files, it merely adds the file to the Copy Bundle Resources phase of the selected target(s).
You can have folders in your Resources group. Just drag a real finder folder into xcode and choose 'Create folder references for added folders', and choose all the targets that you want to use.
This will create a dynamic folder reference that will add all files within that folder automatically without you having to add the files individually everytime.

Resources