JSONKit for xcode 4.6 ios 6 with ARC? - automatic-ref-counting

Well, I did add the JSONKit classes (JSONKit.h & JSONKit.h) but in the .m file, I have a lot of warnings & compil's error's like:
NSError *error; //--> ARC forbids Objetive-C in structs or unions
or
id key, object; whit the same error
anObject = [anObject retain]; //---> ARC forbids explicit message send 'retain''
or many error's in this part code:
static void _JKArrayInsertObjectAtIndex(JKArray *array, id newObject, NSUInteger objectIndex) {
NSCParameterAssert((array != NULL) && (array->objects != NULL) && (array->count <= array->capacity) && (objectIndex <= array->count) && (newObject != NULL));
if(!((array != NULL) && (array->objects != NULL) && (objectIndex <= array->count) && (newObject != NULL))) { [newObject autorelease]; return; }
if((array->count + 1UL) >= array->capacity) {
id *newObjects = NULL;
if((newObjects = (id *)realloc(array->objects, sizeof(id) * (array->capacity + 16UL))) == NULL) { [NSException raise:NSMallocException format:#"Unable to resize objects array."]; }
array->objects = newObjects;
array->capacity += 16UL;
memset(&array->objects[array->count], 0, sizeof(id) * (array->capacity - array->count));
}
array->count++;
if((objectIndex + 1UL) < array->count) { memmove(&array->objects[objectIndex + 1UL], &array->objects[objectIndex], sizeof(id) * ((array->count - 1UL) - objectIndex)); array->objects[objectIndex] = NULL; }
array->objects[objectIndex] = newObject;
}
how can I use in the best way the JSONKit & JSON framework for xcode 4.6 iOS 6?
& thanks a lot!!! greetings from Bolivia!! Rock ON!!! XD

Trying to use another fork of JSONKit. With a simple search, I have find some fork which have correct this problem.
Maybe this one: https://github.com/Kelp404/JSONKit/network
The last commit of original JSONKit is up to 8 month at this day... it's bad !

For anyone interested, I just forked the original repo and added in the fixes (and a Podspec file) that looks like it works with iOS6. https://github.com/JoistApp/JSONKit

Related

VendTransOpen marking with CustVendOpenTransManager

I have a button on VendOpenTrans and implemented its clicked method.
I thought this would work but i get an exception and AX closes..
void clicked()
{
LedgerJournalTrans ledgerJournalTrans;
VendTransOpen vto;
super();
switch (originator.TableId)
{
case tableNum(LedgerJournalTrans):
ledgerJournalTrans = element.args().record();
}
for ( vto = vendTransOpen_ds.getFirst(0); vto; vto = vendTransOpen_ds.getNext() )
{
//vendTransOpen_ds.markRecord(vto, 1);
if (vto.RecId)
{
if (manager.getTransMarked(vto) == NoYes::No)
{
select Invoice from vendTrans
where vto.AccountNum == vendTrans.AccountNum &&
vto.RefRecId == vendTrans.RecId;
if (ledgerJournalTrans.Invoice == vendTrans.Invoice)
{
// Mark transaction for settlement
showError = NoYes::No;
manager.updateTransMarked(vto, NoYes::Yes);
showError = NoYes::Yes;
}
}
}
// Update dynamic controls & refresh form as auto-redraw is not triggered
element.updateDesignDynamic();
element.redraw();
}
vendTransOpen_ds.refreshEx(-2);
}
If i comment out the following lines it will work, basically marking all the lines in the grid.
//select Invoice from vendTrans
//where vto.AccountNum == vendTrans.AccountNum &&
//vto.RefRecId == vendTrans.RecId;
//if (ledgerJournalTrans.Invoice == vendTrans.Invoice)
//{
// Mark transaction for settlement
showError = NoYes::No;
manager.updateTransMarked(vto, NoYes::Yes);
showError = NoYes::Yes;
//}
So, to be more clear, what stays is: manager.updateTransMarked(vto, NoYes::Yes);
and this way, it works. As far as i see something happens when i add that select.
Using debug i was able to check it and i think the exception is thrown by the for loop ..
Is there any chance to get a hint about this ?
Try changing your for loop definition to this:
for (vto = vendTransOpen_ds.getFirst(0) ? vendTransOpen_ds.getFirst(0) : vendTransOpen_ds.cursor(); vto; vto = vendTransOpen_ds.getNext())
And change this:
select Invoice from vendTrans
where vto.AccountNum == vendTrans.AccountNum &&
vto.RefRecId == vendTrans.RecId;
if (ledgerJournalTrans.Invoice == vendTrans.Invoice)
{
To this:
if (ledgerJournalTrans.Invoice == vto.vendTrans().Invoice)

Ax 2012 tts error

HI i am facing an error while updating a record in the invent table. I am using the following sample code.
static void Job4(Args _args)
{
CsInvBOMSplitQtyCalcHelper bomCalc;
Qty qty;
InventTable inventTable;
InventTable updateInventTable;
BOM bom;
boolean result;
BOMId bomId;
BOMVersion bomVersion;
ItemId item = "1000M-3C-Pcs";
select firstOnly * from bomversion
where bomversion.Active == true
&& bomversion.ItemId == item
&& csIsLengthItem(item) == false;
if (0 != bomVersion.RecId)
{
select * from bom
where bom.BOMId == bomversion.BOMId
exists join inventTable
where bom.ItemId == inventTable.ItemId
&& inventTable.CsIsLengthItem == true;
}
if (0 != bom.RecId)
{
result = true;
bomCalc = CsInvBOMSplitQtyCalcHelper::construct(item);
qty = bomCalc.getAdvicedBOMSpoolQty();
}
ttsBegin;
while select forUpdate updateInventTable
where updateInventTable.ItemId == item
{
updateInventTable.CsInvBOMSplitQty = qty;
updateInventTable.update();
}
ttsCommit;
info(strFmt('%1, %2, %3', result, qty, inventTable.CsInvBOMSplitQty));
}
This is the error I get:
Please help me in resolving this issue.
The error is obviously not caused by this job (but maybe an earlier version).
Just run this small job to reset the TTS level:
static ttsAbort(Args args)
{
ttsabort;
}
TTS level errors are usually caused by programming errors, say calling return before ttsCommit.

ASP.NET MVC UrlHelper.GenerateUrl exception: "Cannot use a leading .. to exit above the top directory"

I am using the IIS 7 Rewrite module to rewrite an incoming url like:
http://server/year/all
to
http://server/application/controller/year/all
Everything works fine, except when, while processing the rewritten request, I use MVC's UrlHelper.GenerateUrl() method:
UrlHelper.GenerateUrl(
"Assets",
"Css",
"Asset",
new RouteValueDictionary(new { site = site.Name, assetPath = assetPath }),
RouteTable.Routes,
controllerContext.RequestContext,
false);
Calling this method results in an HttpException:
System.Web.HttpException: Cannot use a leading .. to exit above the top directory.
at System.Web.Util.UrlPath.ReduceVirtualPath(String path)
at System.Web.Util.UrlPath.Reduce(String path)
at System.Web.VirtualPath.Combine(VirtualPath relativePath)
at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
at System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath)
at System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath)
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues)
Looking at the RequestContext, it seems that all of the request paths are correct (ie, have the rewritten values). I can't seem to figure out why it's trying to exit out of the top level directory... There's nowhere we are using .... in a path.
I've also made sure the RewriteModule is in above the UrlRouting module in IIS.
While I can step into the framework methods, I can't examine any of the local variables (either in VS or WinDbg) because it's been compiler optimized.
Any thoughts?
This is a grotesque workaround involving private implementation details, but add this:
HttpContext.Current.Request.ServerVariables.Remove("IIS_WasUrlRewritten");
This avoids the internal check done in PathHelper.GenerateClientUrlInternal to see if the request was rewritten. It's quite likely that this will break some scenarios, as hinted at by this comment in the reference sources:
// Since the rawUrl represents what the user sees in his browser, it is what we want to use as the base
// of our absolute paths. For example, consider mysite.example.com/foo, which is internally
// rewritten to content.example.com/mysite/foo. When we want to generate a link to ~/bar, we want to
// base it from / instead of /foo, otherwise the user ends up seeing mysite.example.com/foo/bar,
// which is incorrect.
Working solution is to insert the line before Url.Content/UrlHelper.GenerateContentUrl (best place is in Application_BeginRequest):
System.Web.HttpContext.Current.Items.Add("IIS_WasUrlRewritten", "false");
My answer is the result of 2 above answers (Rick Schott and Thom). Both was quite right but that didn't help.
I learned source code at https://github.com/aspnet/AspNetWebStack/blob/master/src/ of two classes (System.Web.WebPages.Utils.UrlRewriterHelper.cs and System.Web.WebPages.Utils.UrlUtil.cs) that are in my stack trace:
System.Web.HttpException (0x80004005): Cannot use a leading .. to exit above the top directory.
at System.Web.Util.UrlPath.ReduceVirtualPath(String path)
at System.Web.Util.UrlPath.Reduce(String path)
at System.Web.VirtualPath.Combine(VirtualPath relativePath)
at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
at System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath)
at System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath)
at System.Web.WebPages.UrlUtil.GenerateClientUrl(HttpContextBase httpContext, String basePath, String path, Object[] pathParts)
There is code in System.Web.WebPages.Utils.UrlUtil.cs - GenerateClientUrlInternal method:
if (!wasRequestRewritten)
{
return contentPath;
}
// Since the rawUrl represents what the user sees in his browser, it is what we want to use as the base
// of our absolute paths. For example, consider mysite.example.com/foo, which is internally
// rewritten to content.example.com/mysite/foo. When we want to generate a link to ~/bar, we want to
// base it from / instead of /foo, otherwise the user ends up seeing mysite.example.com/foo/bar,
// which is incorrect.
string relativeUrlToDestination = MakeRelative(httpContext.Request.Path, contentPath);
string absoluteUrlToDestination = MakeAbsolute(httpContext.Request.RawUrl, relativeUrlToDestination);
return absoluteUrlToDestination;
You could see strange lines with author's comment for url rewritten paths. Also, original client path is in HttpContext.Request.RawUrl but in Url it is rewritten.
Look forward at System.Web.WebPages.Utils.UrlRewriterHelper.cs:
if (httpContext.Items.Contains(UrlWasRewrittenServerVar))
{
return Object.Equals(httpContext.Items[UrlWasRewrittenServerVar], UrlWasRequestRewrittenTrueValue);
}
else
{
HttpWorkerRequest httpWorkerRequest = (HttpWorkerRequest)httpContext.GetService(typeof(HttpWorkerRequest));
bool requestWasRewritten = (httpWorkerRequest != null && httpWorkerRequest.GetServerVariable(UrlWasRewrittenServerVar) != null);
if (requestWasRewritten)
{
httpContext.Items.Add(UrlWasRewrittenServerVar, UrlWasRequestRewrittenTrueValue);
}
else
{
httpContext.Items.Add(UrlWasRewrittenServerVar, UrlWasRequestRewrittenFalseValue);
}
return requestWasRewritten;
}
If we write dummy value to HttpContext.Items[UrlWasRewrittenServerVar] with "false" value we make skipped httpWorkerRequest.GetServerVariable(UrlWasRewrittenServerVar) != null check.
So Url.Content is working now.
Not sure if it helps but here is the code throwing the exception:
internal static string ReduceVirtualPath(string path)
{
int length = path.Length;
int startIndex = 0;
while (true)
{
startIndex = path.IndexOf('.', startIndex);
if (startIndex < 0)
{
return path;
}
if (((startIndex == 0) || (path[startIndex - 1] == '/')) && ((((startIndex + 1) == length) || (path[startIndex + 1] == '/')) || ((path[startIndex + 1] == '.') && (((startIndex + 2) == length) || (path[startIndex + 2] == '/')))))
{
break;
}
startIndex++;
}
ArrayList list = new ArrayList();
StringBuilder builder = new StringBuilder();
startIndex = 0;
do
{
int num3 = startIndex;
startIndex = path.IndexOf('/', num3 + 1);
if (startIndex < 0)
{
startIndex = length;
}
if ((((startIndex - num3) <= 3) && ((startIndex < 1) || (path[startIndex - 1] == '.'))) && (((num3 + 1) >= length) || (path[num3 + 1] == '.')))
{
if ((startIndex - num3) == 3)
{
if (list.Count == 0)
{
throw new HttpException(SR.GetString("Cannot_exit_up_top_directory"));
}
if ((list.Count == 1) && IsAppRelativePath(path))
{
return ReduceVirtualPath(MakeVirtualPathAppAbsolute(path));
}
builder.Length = (int) list[list.Count - 1];
list.RemoveRange(list.Count - 1, 1);
}
}
else
{
list.Add(builder.Length);
builder.Append(path, num3, startIndex - num3);
}
}
while (startIndex != length);
string str = builder.ToString();
if (str.Length != 0)
{
return str;
}
if ((length > 0) && (path[0] == '/'))
{
return "/";
}
return ".";
}

ASP.Net Webforms w/ AJAX Slow Rendering

I have a Webforms, AJAX-enabled web page which, when rendering large amounts of data, is extremely slow to load in IE (we're married to IE - no other browser options). In an attempt to determine the source of the slowness, I viewed the HTML source (about 2.5 MB) and copied all of it (except for the Ajax JavaScript calls) to a blank .html file. IE renders this file MUCH faster than when the rendering happens through .Net. This seems to indicate that the AJAX JavaScript is slowing down the display of the page. Does this sound plausible? Any recommendations on improving performance here?
I've already eliminated as many UpdatePanel controls as I can from the page, but it doesn't seem to help with render time.
Thanks for the help!
Update... In the HTML source, I noticed that at the bottom of the screen, a call to WebForm_InitCallback() appears. When I executed this call directly through javascript:alert(WebForm_InitCallback());, the CPU spikes for 12 seconds before it completes! This call is here because I implemented ICallbackEventHandler to try to accomplish some traditional-style AJAX handling. Looking at WebResource.axd, that WebForm_InitCallback() method iterates through the entire form and attaches some kind of events to EVERY SINGLE textbox, checkbox, radiobutton, etc. So I guess I really need to abandon ScriptManager and UpdatePanel altogether here. Poop.
Andy
I hate to say this, but can you take the Microsoft AJAX out of the equation? Try it with doing an XMLHTTP request and populate the data yourself. That way at least you could step through the js and figure out if it is time on the server, time turning the resulting XML or JSON into an object, or time spent populating your data on screen.
This is an old topic but I thought I should share what I recently did to fix long running script error in IE 7 caused by WebForm_InitCallback.
I had a page with over 2000 form elements and in IE 7 was causing a long running script warning / browser freeze for a client. We have other pages with many more form elements and paging or other options aren't options due to needing a quick turn around to improve performance.
I narrowed it down to WebForm_InitCallback, and even further to the following line:
element = theForm.elements[i];
By saving a reference to theForm.elements instead and using it to access the index, I found significant performance gains.
var elements = theForm.elements;
for (var i = 0; i < count; i++) {
element = elements[i];
....
}
I made a jsperf to test the difference since I didn't expect such impressive gains from not calling the refinement every time.
Beyond that, I found better performance by replacing the concatenation in WebForm_InitCallbackAddField to adding the strings to an array and joining it together after the for loop in WebForm_InitCallback completes and saving it back into __theFormPostData.
Here are the original two function that you'll see in the WebResource:
function WebForm_InitCallback() {
var count = theForm.elements.length;
var element;
for (var i = 0; i < count; i++) {
element = theForm.elements[i];
var tagName = element.tagName.toLowerCase();
if (tagName == "input") {
var type = element.type;
if ((__callbackTextTypes.test(type) || ((type == "checkbox" || type == "radio") && element.checked))
&& (element.id != "__EVENTVALIDATION")) {
WebForm_InitCallbackAddField(element.name, element.value);
}
}
else if (tagName == "select") {
var selectCount = element.options.length;
for (var j = 0; j < selectCount; j++) {
var selectChild = element.options[j];
if (selectChild.selected == true) {
WebForm_InitCallbackAddField(element.name, element.value);
}
}
}
else if (tagName == "textarea") {
WebForm_InitCallbackAddField(element.name, element.value);
}
}
}
function WebForm_InitCallbackAddField(name, value) {
var nameValue = new Object();
nameValue.name = name;
nameValue.value = value;
__theFormPostCollection[__theFormPostCollection.length] = nameValue;
__theFormPostData += WebForm_EncodeCallback(name) + "=" + WebForm_EncodeCallback(value) + "&";
}
And here is the javascript I added to my page to overwrite them. It's important that this code is inserted after the WebResource is added and before WebForm_InitCallback is called.
var __theFormPostDataArr = [];
if (typeof (WebForm_InitCallback) != "undefined") {
WebForm_InitCallback = function () {
var count = theForm.elements.length;
var element;
var elements = theForm.elements;
for (var i = 0; i < count; i++) {
element = elements[i];
var tagName = element.tagName.toLowerCase();
if (tagName == "input") {
var type = element.type;
if ((type == "text" || type == "hidden" || type == "password" ||
((type == "checkbox" || type == "radio") && element.checked)) &&
(element.id != "__EVENTVALIDATION")) {
WebForm_InitCallbackAddField(element.name, element.value);
}
}
else if (tagName == "select") {
var selectCount = element.options.length;
for (var j = 0; j < selectCount; j++) {
var selectChild = element.options[j];
if (selectChild.selected == true) {
WebForm_InitCallbackAddField(element.name, element.value);
}
}
}
else if (tagName == "textarea") {
WebForm_InitCallbackAddField(element.name, element.value);
}
}
__theFormPostData = __theFormPostDataArr.join('');
}
WebForm_InitCallbackAddField = function (name, value) {
__theFormPostDataArr = [];
var nameValue = new Object();
nameValue.name = name;
nameValue.value = value;
__theFormPostCollection[__theFormPostCollection.length] = nameValue;
__theFormPostDataArr[__theFormPostDataArr.length] = WebForm_EncodeCallback(name);
__theFormPostDataArr[__theFormPostDataArr.length] = "=";
__theFormPostDataArr[__theFormPostDataArr.length] = WebForm_EncodeCallback(value);
__theFormPostDataArr[__theFormPostDataArr.length] = "&";
}
}
Ultimately, it took the run time of WebForm_InitCallback from 27 seconds to 4 seconds on my IE 7 machine.

Where to find or duplicate code that produces HttpRequestValidationException

I have some PageMethods (static methods in a page marked with <WebMethod>) defined on some pages and call them using an ajax call. This POST to the server apparently doesn't trigger the ASP.NET code that would raise HttpRequestValidationException if the data sent is deemed possible XSS, so I'd like to duplicate that checking code to run it in my page methods.
Anyone know the details of that code or where I can find it? I looked in the MS AntiXss library, but it only does encoding, not actually checking input, AFAIK.
Edit: Or point me in the direction of code or a library that does some similar checking.
Analyzing the stack trace when a System.Web.HttpRequestValidationException is raised we can find out what code is throwing it.
System.Web.HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (IdentifierTextBox="
at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)
Using Reflector we find that ValidateString is calling: RequestValidator.Current.IsValidRequestString, which in turn calls CrossSiteScriptingValidation.IsDangerousString which is:
internal static bool IsDangerousString(string s, out int matchIndex)
{
matchIndex = 0;
int startIndex = 0;
while (true)
{
int num2 = s.IndexOfAny(startingChars, startIndex);
if (num2 < 0)
{
return false;
}
if (num2 == (s.Length - 1))
{
return false;
}
matchIndex = num2;
char ch = s[num2];
if (ch != '&')
{
if ((ch == '<') && ((IsAtoZ(s[num2 + 1]) || (s[num2 + 1] == '!')) || ((s[num2 + 1] == '/') || (s[num2 + 1] == '?'))))
{
return true;
}
}
else if (s[num2 + 1] == '#')
{
return true;
}
startIndex = num2 + 1;
}
}

Resources