Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding UTF-8 support for WideCharToMultiByte method - Windows Platform #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

xeronix
Copy link

@xeronix xeronix commented Oct 6, 2016

If process environment variable value has non-english language characters (e.g. chinese ) then SIGAR_W2A(lpw, lpa, chars) is not able to make the conversion into multi byte properly. Fixing this by specifying code page as UTF-8.

SIGAR_A2W(lpa, lpw, bytes) will also use UTF-8 now for consistency.

If process environment variable value has non-english language characters (e.g. chinese ) then SIGAR_W2A(lpw, lpa, chars) is not able to make the conversion into multi byte properly. Fixing this by specifying code page as UTF-8.

SIGAR_A2W(lpa, lpw, bytes) will also use UTF-8 now for consistency.
@zw3413
Copy link

zw3413 commented Feb 22, 2018

Hi,Xeronix
I was facing the problem of Chinese characters showing, I modified the code you mentioned here, and complied the sigar source by myself, with win7, vs2015 and java1.8. After all compiled ok though encountered some reference problem in the compiling. But unfortunatly, after the modification you suggested, I didn't see the chinese characters showing correctly still.
I have read a lot of suggestions about fixing the chinese showing problem. The main point is to convert the string to utf-8 at c/c++ side (as asc and gb2312 were used for encoding at c/c++ or win side mixly), I also readed the c source of sigar, but didn't find where I can add this conversion, can you kindly give some tips?
In the ant buidling, looks like the jni was built by the perl script, I don't know about perl , so it is hard to read all the structure. It would be very grateful if you can provide some direction, or suggestions on looking into the sigar source and the way to resolve the chinese showing problem.
Thanks,
zhangw

@xeronix
Copy link
Author

xeronix commented Feb 22, 2018 via email

@zw3413
Copy link

zw3413 commented Mar 6, 2018

Hi,
All Chinese character from Sigar failed to show, regardless of the methods.
I tried some processing as per suggestions which is to resolve the JNI encoding issue like below:
remove all 0 in the bytes which returned by Sigar native method, remove the BOM head, then encode the bytes with utf-8.
This worked for some case really like: "Bluetooth �x(个人区域网", though some wrong character still there, but it looks much better than the original string returned by Sigar method.
But it is not the real way to resolve the encoding issue, as much Chinese still were not showed correctly.
When I have VM avalilable, I will provide you more snaps.
Thanks!

@zw3413
Copy link

zw3413 commented Mar 8, 2018

 Hi Vipul,
this is a new find, can you help me to address?
I compiled the source with your instruction, additionally added some minor modification as followed other thread of issue fixing.
But After I put the output sigar.jar and sigar-amd64-winnt.dll into lib of project. I got a incorrect net information output. looks like below:

with the Sigar compiled

cfg.getName() Loopback Pseudo-Interface 1
cfg.getDescription() Intel(R) Centrino(R) Ultimate-N 6300 AGN
cfg.getName() Loopback Pseudo-Interface 1
cfg.getDescription() Intel(R) Centrino(R) Ultimate-N 6300 AGN
cfg.getName() Intel(R) 82577LM Gigabit Network Connection-QoS Packet Scheduler-0000
cfg.getDescription() Intel(R) 82577LM Gigabit Network Connection-QoS Packet Scheduler-0000
cfg.getName() Intel(R) 82577LM Gigabit Network Connection-WFP LightWeight Filter-0000
cfg.getDescription() Intel(R) 82577LM Gigabit Network Connection-WFP LightWeight Filter-0000
cfg.getName() Loopback Pseudo-Interface 1
cfg.getDescription() Intel(R) Centrino(R) Ultimate-N 6300 AGN
cfg.getName() WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
cfg.getDescription() WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
cfg.getName() Bluetooth rt (Network Monitor)-QoS Packet Scheduler-0000
cfg.getDescription() Intel(R) 82577LM Gigabit Network Connection
cfg.getName() Bluetooth rt (Network Monitor)-QoS Packet Scheduler-0000
cfg.getDescription() Intel(R) 82577LM Gigabit Network Connection

with the original Sigar Binary

cfg.getName() eth0
cfg.getDescription() WAN Miniport (IPv6)
cfg.getName() eth1
cfg.getDescription() WAN Miniport (Network Monitor)
cfg.getName() eth2
cfg.getDescription() Intel(R) 82577LM Gigabit Network Connection-QoS Packet Scheduler-0000
cfg.getName() eth3
cfg.getDescription() Intel(R) 82577LM Gigabit Network Connection-WFP LightWeight Filter-0000
cfg.getName() eth4
cfg.getDescription() WAN Miniport (IP)
cfg.getName() eth5
cfg.getDescription() WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
cfg.getName() eth6
cfg.getDescription() Bluetooth ?豸(???????ò??
cfg.getName() eth7
cfg.getDescription() Intel(R) 82577LM Gigabit Network Connection
cfg.getName() eth8
cfg.getDescription() WAN Miniport (IP)-QoS Packet Scheduler-0000

the code is as below:
String[] ifaces = sigar.getNetInterfaceList();
for (int i = 0; i < ifaces.length; i++) {
NetInterfaceConfig cfg = sigar.getNetInterfaceConfig(ifaces[i]);
cfg.getName();
cfg.getDescription();
}

It is obsvious that the getName() and get Description() function didn't work properly, I didn't check any other similar problem functions. Could you help?
the issue binary were compiled by source of both of your branch and the master branch.

Below is the step I did the compiling:
tools: win7, CMAKE 3.11.0-rc2, jdk 1.8, perl5, ant 1.10.1, vs2015

  1. open a new cmd
  2. run vcvarsall.bat amd64
  3. modified source according to
    Compilation fails on Visual Studio 2017 (VS 15.0) #112
    Compilation fails on Visual Studio 15 and above #111
  4. commented below lines in jni-build.xml, as these 2 os cannot be recognized by my environment.

and

  1. "ant clean" and "ant"
    The compiling is completed with successfully.
    @xeronix
    Thanks so much!
    zhangw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants