<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">

<channel>
	<title>Blog</title>
	<link>http://www.objectpark.net/devblog.html</link>
	<description></description>
	<copyright>If you wanna copy anything, please ask first - thanks!</copyright>
	<pubDate>Thu, 29 Jul 2010 14:47:00 +0200</pubDate>
	<generator>http://www.awf-cms.org/</generator>
		<item>
		<title>Get the parent process id for a given pid</title>
		<link>http://www.objectpark.net/parentpid.html</link>
		<pubDate>Thu, 17 Aug 2006 00:00:00 +0200</pubDate>
		<category>General</category>
		<guid>http://www.objectpark.net/parentpid.html</guid>
		<description> I was really surprised that there seems to be no posix or Cocoa API to get the parent process id on OS X when you already know a process id. This is expecially useful if you have started a process in form of an NSTask, but that task forks and so you cannot identify the process by -[NSTask processIdentifier] any more. This is now possible with the following small function by comparing the parent process id: 


  
#include &amp;lt;sys/sysctl.h&amp;gt;

#define OPProcessValueUnknown UINT_MAX

int OPParentIDForProcessID(int pid)
/*&amp;quot; Returns the parent process id 
     for the given process id (pid). &amp;quot;*/
{
    struct kinfo_proc info;
    size_t length = sizeof(struct kinfo_proc);
    int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
    if (sysctl(mib, 4, &amp;amp;info, &amp;amp;length, NULL, 0) &amp;lt; 0)
        return OPProcessValueUnknown;
    if (length == 0)
        return OPProcessValueUnknown;
    return info.kp_eproc.e_ppid;
}  

 Have fun! 

 Dirk 

</description>
		<trackback:ping>http://www.objectpark.net/trackback/AWF_Document/38</trackback:ping>
	</item>
		<item>
		<title>Stripping HTML</title>
		<link>http://www.objectpark.net/StrippingHTML.html</link>
		<pubDate>Wed, 29 Nov 2006 00:00:00 +0100</pubDate>
		<category>General</category>
		<guid>http://www.objectpark.net/StrippingHTML.html</guid>
		<description> Ever wondered how to get just the text out of an html document, e.g. for indexing? NSAttributedString simply does not do it as you cannot stop it from loading external resources like images - resulting in timeouts and wasted network bandwidth. 

 Here is how we do it in our email client (&#039;Ginko&#039;). After a long research and asking around at WWDC, I was delighted that libxml2 can do everything needed and is very flexible, so the code is very short! Use it in your code as you like! 

 If someone improves it so that &#039;alt&#039; tags etc. are also indexed, we&#039;d like to update our code as well. 


  
//
//  NSString+OPHTMLTools.m
//  GinkoVoyager
//
//  Created by Dirk Theisen on 30.06.06.
//  Copyright 2006 Objectpark Group.
//

#import &amp;quot;NSString+OPHTMLTools.h&amp;quot;

#include &amp;lt;string.h&amp;gt;
#include &amp;lt;libxml/xmlmemory.h&amp;gt;
#include &amp;lt;libxml/HTMLparser.h&amp;gt;

@implementation NSString (OPHTMLTools)

static void charactersParsed(void* context, const xmlChar* ch, int len)
/*&amp;quot; Callback function for stringByStrippingHTML. &amp;quot;*/
{
  NSMutableString* result = context;
  NSString* parsedString;
  parsedString = [[NSString alloc] initWithBytesNoCopy: (xmlChar*) ch
    length: len encoding: NSUTF8StringEncoding freeWhenDone: NO];
  [result appendString: parsedString];
  [parsedString release];
}

- (NSString*) stringByStrippingHTML
/*&amp;quot; Interpretes the receiver als HTML, removes all tags 
    and returns the plain text. &amp;quot;*/
{
  int mem_base = xmlMemBlocks();    
  NSMutableString* result = [NSMutableString string];
  xmlSAXHandler handler; bzero(&amp;amp;handler, sizeof(xmlSAXHandler));
  handler.characters = &amp;amp;charactersParsed;
    
  htmlSAXParseDoc((xmlChar*)[self UTF8String], 
    &amp;quot;utf-8&amp;quot;, &amp;amp;handler, result);
    
  if (mem_base != xmlMemBlocks()) {
    printf(&amp;quot;Leak of %d blocks found in htmlSAXParseDoc&amp;quot;,
      xmlMemBlocks() - mem_base);
  }
  return result;
}  

 Have Fun! 

 Dirk 

</description>
		<trackback:ping>http://www.objectpark.net/trackback/AWF_Document/40</trackback:ping>
	</item>
		<item>
		<title>Default Download Directory</title>
		<link>http://www.objectpark.net/download-directory.html</link>
		<pubDate>Fri,  7 Jul 2006 00:00:00 +0200</pubDate>
		<category>General</category>
		<guid>http://www.objectpark.net/download-directory.html</guid>
		<description> Have you ever wondered how to access the user&#039;s default download directory/folder (as used by Safari for example) using Cocoa? You cannot directly. So we wrote a category for NSWorkspace calling into the legacy InternetConfig library which is now part of Carbon - so do not forget to link against Carbon when using this code. 

 Thanks to  Uli Kusterer  for the original! 


  
@implementation NSWorkspace (OPExtensions)

- (NSString*) downloadDirectory 
/*&amp;quot; Returns the user&#039;s std. download directory path 
    taken from Internet Config. &amp;quot;*/
{ 
    // Code modified from Uli Kusterer&#039;s UKPathUtilities:
    ICInstance     inst = NULL; 
    ICFileSpec     fSpec; 
    long length = kICFileSpecHeaderSize; 
    FSRef fref; 
    unsigned char fpath[PATH_MAX] = { 0 }; 
    if (ICStart(&amp;amp;inst, 0L ) != noErr) goto cleanup; 
    ICGetPref(inst, kICDownloadFolder, NULL, &amp;amp;fSpec, &amp;amp;length); 
    ICStop(inst); 
    if (FSpMakeFSRef( &amp;amp;fSpec.fss, &amp;amp;fref ) != noErr ) goto cleanup; 
    if (FSRefMakePath( &amp;amp;fref, fpath, 1024 ) != noErr ) goto cleanup; 
cleanup: ;
    if (fpath[0] == 0) return [NSHomeDirectory() 
        stringByAppendingPathComponent: @&amp;quot;Desktop&amp;quot;];
    return [NSString stringWithUTF8String: (char*)fpath]; 
}
@end  

 Have fun! 

 Dirk 

</description>
		<trackback:ping>http://www.objectpark.net/trackback/AWF_Document/36</trackback:ping>
	</item>
		<item>
		<title>Descriptive Error Messages for the Security Framework</title>
		<link>http://www.objectpark.net/SSLErrorMessages.html</link>
		<pubDate>Fri, 19 May 2006 00:00:00 +0200</pubDate>
		<category>General</category>
		<guid>http://www.objectpark.net/SSLErrorMessages.html</guid>
		<description> Have you ever wondered how to translate OSStatus codes like -9612 from e.g. SSLHandshake() to something user presentable using Cocoa? 

 Here is how! 


  
NSString* OPStringForSecErrorCode(OSStatus status)
/*&amp;quot; Returns the error string from the SecErrorMessages.strings 
    file found in the Security.framework bundle for the error (status) 
    code given. &amp;quot;*/
{    
    NSBundle* secBundle   = [NSBundle bundleWithIdentifier: @&amp;quot;com.apple.security&amp;quot;];
    // Convert status to Int32 string representation, e.g. &amp;quot;-25924&amp;quot;:
    NSString* keyString   = [NSString stringWithFormat: @&amp;quot;%d&amp;quot;, status];     
    NSString* errorString = [secBundle localizedStringForKey: keyString 
                                                       value: keyString 
                                                       table: @&amp;quot;SecErrorMessages&amp;quot;];
    return errorString;
}  

 This code is also part of the BSD-licensed  OPNetwork.framework  (OPSSLSocket class). 

 Have fun! 

 Dirk 

</description>
		<trackback:ping>http://www.objectpark.net/trackback/AWF_Document/28</trackback:ping>
	</item>
		<item>
		<title>Finally...</title>
		<link>http://www.objectpark.net/Finally.html</link>
		<pubDate>Tue,  2 May 2006 00:00:00 +0200</pubDate>
		<category>General</category>
		<guid>http://www.objectpark.net/Finally.html</guid>
		<description> We finally made it! Objectpark now has a weblog for all our development stuff. Look out for code snippets, categories and tricks at this place. 

 Dirk 

</description>
		<trackback:ping>http://www.objectpark.net/trackback/AWF_Document/24</trackback:ping>
	</item>
	</channel>
</rss>