Moving micasa 1.5 trunk to Novell forge.

This commit is contained in:
Cameron (Kamran) Mashayekhi
2005-10-11 19:51:00 +00:00
parent 082db33275
commit efe0a5e13c
691 changed files with 116628 additions and 0 deletions

View File

@@ -0,0 +1,286 @@
using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Threading;
using Gtk;
using GLib;
namespace Novell.CASA.DataEngines.GK
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class KeyringInfo
{
public int lockOnIdle;
public uint lockTimeout;
public uint mTime;
public uint cTime;
public int isLocked;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class NativeItemInfo
{
public int itemType;
public IntPtr displayName;
public IntPtr secret;
public int mTime;
public int cTime;
public NativeItemInfo()
{
displayName = Marshal.AllocHGlobal(128);
secret = Marshal.AllocHGlobal(128);
}
~NativeItemInfo()
{
Marshal.FreeHGlobal(displayName);
Marshal.FreeHGlobal(secret);
}
}
public class ItemInfo
{
public string itemType;
public string displayName;
public string secret;
public int mTime;
public int cTime;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class NativeAttribute
{
public uint type;
public IntPtr key;
public IntPtr value;
}
public class Attribute
{
public uint type;
public string key;
public string value;
}
public class GnomeKeyring
{
[DllImport("libad_gk.so")]
public static extern int GetKeyrings(out IntPtr list);
[DllImport("libad_gk.so")]
public static extern int GetKeyringInfo(string name,KeyringInfo info);
[DllImport("libad_gk.so")]
public static extern int GetItems(string keyring,out IntPtr list);
[DllImport("libad_gk.so")]
public static extern int GetItemInfo(string keyring,int itemId, NativeItemInfo info);
[DllImport("libad_gk.so")]
public static extern int GetAttributeList(string keyring,int itemId, out IntPtr attrList);
[DllImport("libad_gk.so")]
public static extern int FreeAttributeList(IntPtr attrList);
public static KeyringInfo GKGetKeyringInfo(string name)
{
KeyringInfo info = null;
try
{
info = new KeyringInfo();
int retVal = GetKeyringInfo(name,info);
if( 0 != retVal )
info = null;
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
info = null;
}
return info;
}
public static void PrintKeyringInfo(KeyringInfo info)
{
if( null == info )
return;
try
{
Console.WriteLine("lockOnIdle = " + info.lockOnIdle);
Console.WriteLine("lockTimeout = " + info.lockTimeout);
Console.WriteLine("mTime = " + info.mTime);
Console.WriteLine("cTime = " + info.cTime);
Console.WriteLine("isLocked = " + info.isLocked);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static ItemInfo GKGetItemInfo(string keyring, int itemId)
{
ItemInfo info = null;
try
{
NativeItemInfo nativeItemInfo = new NativeItemInfo();
int retVal = GetItemInfo(keyring, itemId, nativeItemInfo);
if( 0 != retVal )
info = null;
else
{
info = new ItemInfo();
if(nativeItemInfo.itemType == 0)
info.itemType = "Generic Secret";
else if(nativeItemInfo.itemType == 1)
info.itemType = "Network Password";
else if(nativeItemInfo.itemType == 2)
info.itemType = "Note";
else
info.itemType = "No Type"; // need to have a better name
info.displayName = Marshal.PtrToStringAnsi(nativeItemInfo.displayName);
info.secret = Marshal.PtrToStringAnsi(nativeItemInfo.secret);
info.mTime = nativeItemInfo.mTime;
info.cTime = nativeItemInfo.cTime;
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
info = null;
}
return info;
}
public static void PrintItemInfo(ItemInfo info)
{
if( null == info )
return;
try
{
Console.WriteLine("CS : itemType = " + info.itemType);
Console.WriteLine("CS : displayName = " + info.displayName);
Console.WriteLine("CS : secret = " + info.secret);
Console.WriteLine("CS : mTime = " + info.mTime);
Console.WriteLine("CS : cTime = " + info.cTime);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static ArrayList GKGetKeyrings()
{
ArrayList retList;
try
{
retList = new ArrayList();
IntPtr list = new IntPtr();
int retVal = GetKeyrings(out list);
if ( 0 != retVal )
retList = null;
GLib.List keyringList = new List(list,typeof(string));
IEnumerator etor = (IEnumerator)(keyringList.GetEnumerator());
string name;
while(etor.MoveNext())
{
name = (string)etor.Current;
retList.Add(name);
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
retList = null;
}
return retList;
}
public static ArrayList GKGetItems(string keyring)
{
ArrayList retList = null;
try
{
retList = new ArrayList();
IntPtr list = new IntPtr();
int retVal = GetItems(keyring,out list);
if( 0 != retVal )
retList = null;
GLib.List itemList = new List(list,typeof(int));
IEnumerator etor = (IEnumerator)(itemList.GetEnumerator());
int itemId;
while(etor.MoveNext())
{
itemId = (int)etor.Current;
retList.Add(itemId);
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
retList = null;
}
return retList;
}
public static ArrayList GKGetAttributeList(string keyring, int itemId)
{
ArrayList retList = null;
try
{
retList = new ArrayList();
IntPtr list = new IntPtr();
int retVal = GetAttributeList(keyring, itemId,out list);
if( 0 != retVal )
retList = null;
GLib.List attrList = new List(list,typeof(int));
IEnumerator etor = (IEnumerator)(attrList.GetEnumerator());
while(etor.MoveNext())
{
int test = (int)etor.Current;
IntPtr ptr = new IntPtr(test);
NativeAttribute attr = new NativeAttribute();
attr = (NativeAttribute)Marshal.PtrToStructure(ptr,typeof(NativeAttribute));
string key = Marshal.PtrToStringAnsi(attr.key);
string value = Marshal.PtrToStringAnsi(attr.value);
Attribute retAttr = new Attribute();
retAttr.type = attr.type;
retAttr.key = String.Copy(key);
retAttr.value = String.Copy(value);
retList.Add(retAttr);
}
if(retList.Count > 0)
FreeAttributeList(list);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
retList = null;
}
return retList;
}
public static void PrintAttrList(ArrayList attrList)
{
if( null == attrList )
return;
Attribute attr;
try
{
IEnumerator etor = (IEnumerator)(attrList.GetEnumerator());
while(etor.MoveNext())
{
attr = (Attribute)(etor.Current);
Console.WriteLine("CS : AttrType = " + attr.type);
Console.WriteLine("CS : AttrKey = " + attr.key);
Console.WriteLine("CS : AttrValue = " + attr.value);
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}

20
c_adlib/ad_gk/Makefile Normal file
View File

@@ -0,0 +1,20 @@
#
# configure environment
#
TARGET = Novell.CASA.DataEngines.GnomeKeyring
CS_NAME = $(TARGET)$(xtra).$(EXE)
include global.mak
include defaults.$(PLAT)
include rules.mak
#
# target object and source files
#
include src.$(PLAT)
include objs.$(PLAT)
#
# targets
#
include target.cs

View File

@@ -0,0 +1,20 @@
#
# configure environment
#
TARGET = ad_gk
include global.mak
include defaults.$(PLAT)
include rules.mak
BIN_NAME = $(TARGET)$(xtra).$(BIN)
LIB_NAME = $(TARGET)$(xtra).$(LIB)
#
# target object and source files
#
include objs.$(PLAT)
#
# targets
#
include target.cl

View File

@@ -0,0 +1,237 @@
#include "ad_gk.h"
void ListKeyringsCb (GnomeKeyringResult result,
GList *keyrings,
gpointer data)
{
GList *l = NULL;
char *name = NULL;
GList **retList = data;
GetKeyringsCbData *cbData = data;
GMainLoop *loop = cbData->loop;
retList = cbData->keyringList;
*retList = NULL;
if (result != GNOME_KEYRING_RESULT_OK)
{
g_print ("Unable to get keyring list - %d\n", result);
}
else
{
for (l = keyrings; l != NULL; l = l->next)
{
name = l->data;
*retList = g_list_append (*retList, g_strdup (name));
}
}
g_main_loop_quit (loop);
}
void KeyringGetInfoCb(GnomeKeyringResult result,
GnomeKeyringInfo *info,
gpointer data)
{
GetKeyringInfoCbData *cbData = data;
KeyringInfo *retInfo = cbData->info;
if (result != GNOME_KEYRING_RESULT_OK)
{
g_print ("Unable to get keyring info %d\n", result);
}
else
{
retInfo->lockOnIdle = gnome_keyring_info_get_lock_on_idle(info);
retInfo->lockTimeout = gnome_keyring_info_get_lock_timeout(info);
retInfo->mTime = gnome_keyring_info_get_mtime(info);
retInfo->cTime = gnome_keyring_info_get_ctime(info);
retInfo->isLocked = gnome_keyring_info_get_is_locked(info);
}
g_main_loop_quit (cbData->loop);
}
void ListItemCb( GnomeKeyringResult result,
GList *list,
gpointer data)
{
GList **retList;
GetItemsCbData *cbData = data;
retList = cbData->itemList;
*retList = NULL;
if (result != GNOME_KEYRING_RESULT_OK)
{
g_print ("Unable to get list of items : %d\n", result);
}
else
{
*retList = g_list_copy (list);
}
g_main_loop_quit (cbData->loop);
}
void ItemGetInfoCb( GnomeKeyringResult result,
GnomeKeyringItemInfo *info,
gpointer data)
{
GetItemInfoCbData *cbData = data;
ItemInfo *itemInfo = cbData->info;
if (result != GNOME_KEYRING_RESULT_OK)
{
g_print ("Unable to get Item info: %d\n", result);
}
else
{
itemInfo->itemType = gnome_keyring_item_info_get_type(info);
strcpy(itemInfo->displayName,gnome_keyring_item_info_get_display_name(info));
strcpy(itemInfo->secret,gnome_keyring_item_info_get_secret(info));
itemInfo->mTime = gnome_keyring_item_info_get_mtime(info);
itemInfo->cTime = gnome_keyring_item_info_get_ctime(info);
}
g_main_loop_quit (cbData->loop);
}
void ItemGetAttributesCb(GnomeKeyringResult result,
GnomeKeyringAttributeList *attributes,
gpointer data)
{
GnomeKeyringAttribute *attrList = NULL;
int i = 0;
GetAttributeListCbData *cbData = data;
Attribute *attr = NULL;
GList **retList;
retList = cbData->attrList;
*retList = NULL;
if( result != GNOME_KEYRING_RESULT_OK )
{
g_print("Unable to get the attributes of item\n");
}
else
{
attrList = (GnomeKeyringAttribute*)(attributes->data); //GArray has len and data
for(i = 0; i < attributes->len; i++ )
{
if(attrList[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING)
{
attr = (Attribute*)malloc(sizeof(Attribute));
if( NULL != attr )
{
memset(attr,0,sizeof(Attribute));
attr->type = 0;
attr->key = (char*)malloc(KEY_SIZE);
if(attr->key != NULL)
strcpy(attr->key,attrList[i].name);
attr->value = (char*)malloc(VAL_SIZE);
if(attr->value != NULL)
strcpy(attr->value,attrList[i].value.string);
}
}
else if(attrList[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32)
{
attr = (Attribute*)malloc(sizeof(Attribute));
if( NULL != attr )
{
memset(attr,0,sizeof(Attribute));
attr->type = 0;
attr->key = (char*)malloc(KEY_SIZE);
if(attr->key != NULL)
strcpy(attr->key,attrList[i].name);
attr->value = (char*)malloc(VAL_SIZE);
if(attr->value != NULL)
sprintf(attr->value,"%d",attrList[i].value.integer);
}
}
*retList = g_list_append (*retList, attr);
}
}
g_main_loop_quit (cbData->loop);
}
int GetKeyrings(GList **keyringList)
{
GList *l = NULL;
GetKeyringsCbData cbData;
cbData.loop = g_main_loop_new (NULL, FALSE);
cbData.keyringList = keyringList;
gnome_keyring_list_keyring_names(ListKeyringsCb,&cbData,NULL);
g_main_loop_run(cbData.loop);
return SUCCESS;
}
int GetKeyringInfo(char *keyring,KeyringInfo *info)
{
GetKeyringInfoCbData cbData;
cbData.loop = g_main_loop_new (NULL, FALSE);
cbData.info = info;
gnome_keyring_get_info(keyring, KeyringGetInfoCb,&cbData, NULL);
g_main_loop_run (cbData.loop);
return SUCCESS;
}
int GetItems(char *keyring, GList **itemList)
{
GList *l = NULL;
gint itemId;
GetItemsCbData cbData;
cbData.loop = g_main_loop_new (NULL, FALSE);
cbData.itemList = itemList;
gnome_keyring_list_item_ids(keyring, ListItemCb, &cbData, NULL);
g_main_loop_run (cbData.loop);
return SUCCESS;
}
int GetItemInfo(char *keyring, int itemId, ItemInfo *info)
{
GetItemInfoCbData cbData;
cbData.loop = g_main_loop_new (NULL, FALSE);
cbData.info = info;
gnome_keyring_item_get_info (keyring,itemId, ItemGetInfoCb,
&cbData, NULL);
g_main_loop_run (cbData.loop);
return SUCCESS;
}
int GetAttributeList(char *keyring, int itemId, GList **attrList)
{
int i = 0;
GetAttributeListCbData cbData;
cbData.loop = g_main_loop_new (NULL, FALSE);
cbData.attrList = attrList;
gnome_keyring_item_get_attributes (keyring, itemId,
ItemGetAttributesCb, &cbData,
NULL);
g_main_loop_run (cbData.loop);
return SUCCESS;
}
int FreeAttributeList(GList *attrList)
{
GList *l;
Attribute *attr = NULL;
for(l = attrList; l != NULL; l = l->next)
{
attr = (Attribute*)(l->data);
if(attr->key)
{
free(attr->key);
}
if(attr->value)
{
free(attr->value);
}
}
g_list_free(attrList);
return SUCCESS;
}

View File

@@ -0,0 +1,76 @@
#ifndef _AD_GK_H_
#define _AD_GK_H_
#include <stdio.h>
#include <stdint.h>
#include <glib.h>
#include <gnome-keyring.h>
#define SUCCESS 0
#define FAILURE -1
#define KEY_SIZE 128
#define VAL_SIZE 128
typedef struct _KeyringInfo
{
int32_t lockOnIdle;
uint32_t lockTimeout;
uint32_t mTime;
uint32_t cTime;
int32_t isLocked;
}KeyringInfo;
typedef struct _ItemInfo
{
int32_t itemType;
char *displayName;
char *secret;
uint32_t mTime;
uint32_t cTime;
}ItemInfo;
typedef struct _Attribute
{
uint32_t type;
char *key;
char *value;
}Attribute;
int GetKeyrings(GList **retList);
int GetKeyringInfo(char *keyring,KeyringInfo *info);
int GetItems(char *keyring, GList **itemList);
int GetItemInfo(char *keyring, int itemId, ItemInfo *info);
int GetAttributeList(char *keyring, int itemId, GList **);
int FreeAttributeList(GList *attrList);
typedef struct _GetKeyringsCbData
{
GList **keyringList;
GMainLoop *loop;
}GetKeyringsCbData;
typedef struct _GetKeyringInfoCbData
{
KeyringInfo *info;
GMainLoop *loop;
}GetKeyringInfoCbData;
typedef struct _GetItemsCbData
{
GList **itemList;
GMainLoop *loop;
}GetItemsCbData;
typedef struct _GetItemInfoCbData
{
ItemInfo *info;
GMainLoop *loop;
}GetItemInfoCbData;
typedef struct _GetAttributeListCbData
{
GList **attrList;
GMainLoop *loop;
}GetAttributeListCbData;
#endif

View File

@@ -0,0 +1,13 @@
LINK = $(CPP) \
-Wl,-Bsymbolic \
-shared \
-pthread\
-O2 -fno-exceptions -fno-check-new\
-Wl,-rpath -Wl,/usr/lib$(ARCH_LIB) \
-L/usr/lib$(ARCH_LIB) -lpthread -lc -ldl \
-Wl,-soname -Wl,lib$(TARGET).so.$(PROD_NUM) \
-o $(LIBDIR)$(XTRA)/lib$(TARGET).so.$(BLD_VER) \
-L$(LIBDIR)$(XTRA) \
$(OBJDIR)*.$(O) `pkg-config --libs gnome-keyring-1` -lgnome-keyring \
`pkg-config --libs glib-2.0` -lglib-2.0

View File

@@ -0,0 +1,2 @@
OBJS=\
ad_gk.$(O)

2
c_adlib/ad_gk/objs.lux Normal file
View File

@@ -0,0 +1,2 @@
OBJS=\
GnomeKeyring

2
c_adlib/ad_gk/src.lux Normal file
View File

@@ -0,0 +1,2 @@
SRC=\
GnomeKeyring.cs